argo-search 2.10.2 → 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 +22 -11
- package/README.es.md +22 -11
- package/README.ja.md +22 -11
- package/README.ko.md +21 -10
- package/README.md +22 -11
- package/SKILL.md +16 -15
- package/backends/domain_profiles.json +18 -6
- package/backends/engine_registry.yaml +38 -13
- package/backends/quota_profiles.json +30 -10
- package/bin/argo +6 -0
- package/config.yaml +16 -17
- package/docs/ENGINE_CATALOG.md +11 -8
- 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 +3 -2
- package/packages/dsh-plugin/dsh/index.js +5 -0
- package/packages/dsh-plugin/dsh/runner.js +7 -1
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/index.test.js +21 -0
- package/scripts/budget.py +13 -3
- package/scripts/engine_dispatch.py +2 -1
- package/scripts/engine_families.py +7 -3
- package/scripts/engines.py +10 -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_tech.py +0 -78
- package/scripts/extend_route_labels_by_language.py +306 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/job.py +2 -1
- 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/mcp_compact.py +5 -0
- package/scripts/mcp_transport.py +1 -1
- package/scripts/net_proxy.py +47 -0
- package/scripts/plan.py +11 -0
- package/scripts/pre-commit +21 -13
- package/scripts/quota.py +109 -10
- package/scripts/search.py +13 -12
- package/scripts/search_pipeline.py +15 -15
- package/scripts/social_engines/twitter_engine.py +35 -2
- package/scripts/social_engines/xiaohongshu_engine.py +25 -0
|
@@ -1231,84 +1231,6 @@ def _build_endoflife_engine(spec: dict[str, Any]) -> Any:
|
|
|
1231
1231
|
return _engine
|
|
1232
1232
|
|
|
1233
1233
|
|
|
1234
|
-
# ── TinEye 反向图片搜索(以图搜图,免 key)────────────────────────────────
|
|
1235
|
-
|
|
1236
|
-
def _build_tineye_engine(spec: dict[str, Any]) -> Any:
|
|
1237
|
-
"""TinEye 反向图片搜索(公开 JSON 端点,免 key)。"""
|
|
1238
|
-
timeout = spec.get("timeout", 15)
|
|
1239
|
-
|
|
1240
|
-
@safe_search
|
|
1241
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
1242
|
-
to = _timeout or timeout
|
|
1243
|
-
q = (query or "").strip()
|
|
1244
|
-
if not re.match(r"(?i)^https?://", q):
|
|
1245
|
-
return [{"error": "tineye: 反搜图引擎要喂图片 URL(http(s):// 开头)"
|
|
1246
|
-
f"作为查询,收到的是关键词「{q[:50]}」",
|
|
1247
|
-
"source": "tineye"}]
|
|
1248
|
-
u = ("https://tineye.com/api/v1/result_json/?url="
|
|
1249
|
-
+ urllib.parse.quote(q, safe=""))
|
|
1250
|
-
raw = _http_get_raw(u, {"Accept": "application/json"}, to,
|
|
1251
|
-
engine=spec.get("_name", ""))
|
|
1252
|
-
if not raw:
|
|
1253
|
-
return []
|
|
1254
|
-
try:
|
|
1255
|
-
data = json.loads(raw)
|
|
1256
|
-
except (json.JSONDecodeError, ValueError):
|
|
1257
|
-
return []
|
|
1258
|
-
matches = data.get("matches") if isinstance(data, dict) else None
|
|
1259
|
-
if not isinstance(matches, list):
|
|
1260
|
-
return []
|
|
1261
|
-
results: list[dict[str, Any]] = []
|
|
1262
|
-
seen_pages: set[str] = set()
|
|
1263
|
-
for m in matches:
|
|
1264
|
-
if len(results) >= max(1, n):
|
|
1265
|
-
break
|
|
1266
|
-
if not isinstance(m, dict):
|
|
1267
|
-
continue
|
|
1268
|
-
bl = next((b for b in (m.get("backlinks") or [])
|
|
1269
|
-
if isinstance(b, dict) and (b.get("backlink") or b.get("url"))), None)
|
|
1270
|
-
if not bl:
|
|
1271
|
-
continue
|
|
1272
|
-
page_url = str(bl.get("backlink") or bl.get("url") or "")
|
|
1273
|
-
if not page_url or page_url in seen_pages:
|
|
1274
|
-
continue
|
|
1275
|
-
seen_pages.add(page_url)
|
|
1276
|
-
try:
|
|
1277
|
-
sim = float(m.get("score"))
|
|
1278
|
-
except (TypeError, ValueError):
|
|
1279
|
-
sim = 0.0
|
|
1280
|
-
domain = str(m.get("domain") or "").strip()
|
|
1281
|
-
try:
|
|
1282
|
-
w, h = int(m.get("width") or 0), int(m.get("height") or 0)
|
|
1283
|
-
except (TypeError, ValueError):
|
|
1284
|
-
w = h = 0
|
|
1285
|
-
crawl = str(bl.get("crawl_date") or "").strip()
|
|
1286
|
-
bits = [b for b in (
|
|
1287
|
-
f"相似度 {sim:g}%" if sim > 0 else "",
|
|
1288
|
-
f"来源 {domain}" if domain else "",
|
|
1289
|
-
f"{w}x{h}" if w and h else "",
|
|
1290
|
-
f"收录 {crawl[:10]}" if crawl else "",
|
|
1291
|
-
) if b]
|
|
1292
|
-
base = min(sim / 100.0, 1.0) if sim > 0 else 0.7
|
|
1293
|
-
results.append({
|
|
1294
|
-
"title": (domain or "TinEye 图片匹配")[:120],
|
|
1295
|
-
"url": page_url,
|
|
1296
|
-
"snippet": " · ".join(bits),
|
|
1297
|
-
"source": "tineye",
|
|
1298
|
-
"score": rank_score(base, len(results)),
|
|
1299
|
-
"metadata": {
|
|
1300
|
-
"image_url": str(m.get("image_url") or ""),
|
|
1301
|
-
"similarity": sim,
|
|
1302
|
-
"domain": domain,
|
|
1303
|
-
"width": w,
|
|
1304
|
-
"height": h,
|
|
1305
|
-
"crawl_date": crawl,
|
|
1306
|
-
},
|
|
1307
|
-
})
|
|
1308
|
-
return results
|
|
1309
|
-
return _engine
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
1234
|
# ── Bing RSS 通用网页搜索(免 key,稳定备胎)─────────────────────────────
|
|
1313
1235
|
|
|
1314
1236
|
def _build_bing_rss_engine(spec: dict[str, Any]) -> Any:
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""extend_route_labels_by_language.py — 按语言能力扩展路由标注集。
|
|
3
|
+
|
|
4
|
+
## 为什么需要它
|
|
5
|
+
|
|
6
|
+
既有语料 745 条里中文 504(67.7%)、英文 239(32.1%)、韩文 2(0.3%),
|
|
7
|
+
**其余 13 种语言 0 条**。而 config 里 273 个引擎声明了 16 种语言能力
|
|
8
|
+
(ja 4 个、ko 2 个、ar/id/cs/es/de/pt/tr/fr/th/ru/vi/he 各 1 个),
|
|
9
|
+
`world_news` 域的 patterns 更是直接写了 11 种语言的「新闻」。
|
|
10
|
+
|
|
11
|
+
语言覆盖的缺失意味着:**非中英查询的路由对不对,没有任何门在守**。
|
|
12
|
+
|
|
13
|
+
## MECE 拆解:按字符系统分组
|
|
14
|
+
|
|
15
|
+
语言按「字符系统 + 有无专属引擎」正交拆分,七组互不重叠:
|
|
16
|
+
|
|
17
|
+
| 组 | 语言 | 字符系统 | 专属引擎 |
|
|
18
|
+
|---|---|---|---|
|
|
19
|
+
| CJK 扩展 | ja / ko | 假名 / 谚文 | qiita/hatena/cinii/nhk、kor_law/yna |
|
|
20
|
+
| 西里尔 | ru | 西里尔 | tass |
|
|
21
|
+
| 阿拉伯 | ar | 阿拉伯 | aljazeera |
|
|
22
|
+
| 东南亚 | th / vi | 泰文 / 拉丁+变音 | matichon、vnpress |
|
|
23
|
+
| 欧洲 | de / fr / es / pt / cs / tr | 拉丁 | faz/lefigaro/elpais/folha/ct24/hurriyet |
|
|
24
|
+
| 希伯来 | he | 希伯来 | ynet |
|
|
25
|
+
| 拉丁通用 | id | 拉丁 | antara |
|
|
26
|
+
|
|
27
|
+
**穷尽性**:16 种语言里 en/zh 已在语料里,其余 14 种按上表七组覆盖。
|
|
28
|
+
`id`(印尼)虽用拉丁字母,但有专属引擎(antara),单独成组避免被
|
|
29
|
+
「拉丁=英文」的直觉漏掉。
|
|
30
|
+
|
|
31
|
+
## 第一性原理:判据是「该语言有专属能力」
|
|
32
|
+
|
|
33
|
+
不是「随便抽几条非中英查询」——而是**每种语言都要测它的专属引擎/域能不能
|
|
34
|
+
被路由命中**。例:日语测 `world_news` 的 `ニュース` pattern 与 qiita 的
|
|
35
|
+
技术查询;俄语测 `world_news` 的 `новости` 与 tass。
|
|
36
|
+
|
|
37
|
+
## 用法
|
|
38
|
+
|
|
39
|
+
python3 scripts/extend_route_labels_by_language.py # 扩展并写回
|
|
40
|
+
python3 scripts/extend_route_labels_by_language.py --dry-run # 只统计
|
|
41
|
+
python3 scripts/extend_route_labels_by_language.py --report # 打印命中/失配
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
from __future__ import annotations
|
|
45
|
+
|
|
46
|
+
import argparse
|
|
47
|
+
import json
|
|
48
|
+
import re
|
|
49
|
+
import sys
|
|
50
|
+
from collections import Counter
|
|
51
|
+
from pathlib import Path
|
|
52
|
+
from typing import Any
|
|
53
|
+
|
|
54
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
55
|
+
SCRIPTS = ROOT / "scripts"
|
|
56
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
57
|
+
|
|
58
|
+
LABELS = ROOT / "tests" / "golden" / "route_labeled.jsonl"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _lang_of(query: str) -> str:
|
|
62
|
+
"""判定查询的**文字系统**(复用系统 lang_detect,不自造判据)。
|
|
63
|
+
|
|
64
|
+
系统 `detect_language` 返回的是文字系统而非具体语言:ja/ko/zh 各自可辨,
|
|
65
|
+
但拉丁语系(越/德/法/西/葡/捷/土/印尼)统一返回 `latin`。这是**正确的
|
|
66
|
+
抽象**——路由层按文字系统选源(`engine_families.ENGINE_LANGS` 的
|
|
67
|
+
`lang_allows`),不区分具体拉丁语言。
|
|
68
|
+
|
|
69
|
+
具体语言由 `_LANGUAGE_GROUPS` 的组声明给出(`langs` 字段),不靠字符判定
|
|
70
|
+
——靠字符判定会把越南语误判成英文(都是拉丁字母)。
|
|
71
|
+
"""
|
|
72
|
+
try:
|
|
73
|
+
from lang_detect import detect_language
|
|
74
|
+
return detect_language(query)
|
|
75
|
+
except Exception:
|
|
76
|
+
return "unknown"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# ── 语言能力组(MECE)────────────────────────────────────────────────────────
|
|
80
|
+
# 每组:(组名, [语言...], [(查询, 期望域, 说明), ...])
|
|
81
|
+
# 查询构造自该语言**真实会被问到的形式**,且尽量命中该语言的专属 pattern。
|
|
82
|
+
|
|
83
|
+
_LANGUAGE_GROUPS: list[tuple[str, list[str], list[tuple[str, str, str]]]] = [
|
|
84
|
+
# ── CJK 扩展:日语 ──
|
|
85
|
+
("ja", ["ja"], [
|
|
86
|
+
# world_news 的 patterns 直接写了 ニュース
|
|
87
|
+
("ニュース 今日 速報", "world_news", "日语新闻"),
|
|
88
|
+
("天気 東京 予報", "weather_query", "日语天气(域 patterns 含 天気/予報)"),
|
|
89
|
+
("Qiita python 記事", "cn_tech_community", "日语技术社区(qiita 引擎)"),
|
|
90
|
+
("学术论文 博士論文 探す", "scholar_search", "日语学术(cinii 引擎)"),
|
|
91
|
+
]),
|
|
92
|
+
# ── CJK 扩展:韩语 ──
|
|
93
|
+
("ko", ["ko"], [
|
|
94
|
+
("세계 뉴스 today", "world_news", "韩语新闻(域 patterns 含 뉴스)"),
|
|
95
|
+
("서울 날씨 예보", "weather_query", "韩语天气"),
|
|
96
|
+
("대한민국 형법 조문", "kor_law", "韩语法律(kor_law 引擎)"),
|
|
97
|
+
]),
|
|
98
|
+
# ── 西里尔:俄语 ──
|
|
99
|
+
("ru", ["ru"], [
|
|
100
|
+
("мировые новости сегодня", "world_news", "俄语新闻(域 patterns 含 новости)"),
|
|
101
|
+
("погода Москва прогноз", "weather_query", "俄语天气"),
|
|
102
|
+
("геополитика конфликт санкции", "global_event", "俄语地缘政治"),
|
|
103
|
+
]),
|
|
104
|
+
# ── 阿拉伯:阿拉伯语 ──
|
|
105
|
+
("ar", ["ar"], [
|
|
106
|
+
("أخبار العالم اليوم", "world_news", "阿拉伯语新闻(域 patterns 含 أخبار)"),
|
|
107
|
+
("الطقس الرياض توقعات", "weather_query", "阿拉伯语天气"),
|
|
108
|
+
]),
|
|
109
|
+
# ── 东南亚:泰语 / 越南语 ──
|
|
110
|
+
("sea", ["th", "vi"], [
|
|
111
|
+
("ข่าวโลก วันนี้", "world_news", "泰语新闻(域 patterns 含 ข่าว)"),
|
|
112
|
+
("อากาศ กรุงเทพ พยากรณ์", "weather_query", "泰语天气"),
|
|
113
|
+
("tin thế giới hôm nay", "world_news", "越南语新闻"),
|
|
114
|
+
("thời tiết Hà Nội dự báo", "weather_query", "越南语天气"),
|
|
115
|
+
]),
|
|
116
|
+
# ── 欧洲:德/法/西/葡/捷/土 ──
|
|
117
|
+
("eu", ["de", "fr", "es", "pt", "cs", "tr"], [
|
|
118
|
+
("Weltnachrichten heute", "world_news", "德语新闻(域 patterns 含 Nachrichten)"),
|
|
119
|
+
("Wetter Berlin Vorhersage", "weather_query", "德语天气"),
|
|
120
|
+
("nouvelles du monde aujourd'hui", "world_news", "法语新闻(含 nouvelles/actualités)"),
|
|
121
|
+
("météo Paris prévisions", "weather_query", "法语天气"),
|
|
122
|
+
("noticias del mundo hoy", "world_news", "西班牙语新闻(含 noticias)"),
|
|
123
|
+
("tiempo Madrid pronóstico", "weather_query", "西班牙语天气"),
|
|
124
|
+
("notícias do mundo hoje", "world_news", "葡萄牙语新闻(含 notícias)"),
|
|
125
|
+
("previsão do tempo São Paulo", "weather_query", "葡萄牙语天气"),
|
|
126
|
+
("světové zprávy dnes", "world_news", "捷克语新闻"),
|
|
127
|
+
("počasí Praha předpověď", "weather_query", "捷克语天气"),
|
|
128
|
+
("dünya haberleri bugün", "world_news", "土耳其语新闻"),
|
|
129
|
+
("hava durumu İstanbul tahmin", "weather_query", "土耳其语天气"),
|
|
130
|
+
]),
|
|
131
|
+
# ── 希伯来:以色列 ──
|
|
132
|
+
("he", ["he"], [
|
|
133
|
+
("חדשות העולם היום", "world_news", "希伯来语新闻"),
|
|
134
|
+
("מזג אוויר תל אביב תחזית", "weather_query", "希伯来语天气"),
|
|
135
|
+
]),
|
|
136
|
+
# ── 拉丁通用:印尼 ──
|
|
137
|
+
("id", ["id"], [
|
|
138
|
+
("berita dunia hari ini", "world_news", "印尼语新闻"),
|
|
139
|
+
("prakiraan cuaca Jakarta", "weather_query", "印尼语天气"),
|
|
140
|
+
]),
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _guess_latin_lang(query: str, candidates: list[str]) -> str:
|
|
145
|
+
"""拉丁语系内的具体语言猜测(只在组内候选里选)。
|
|
146
|
+
|
|
147
|
+
判据是各语言的**特征词/特征字符**,不是通用字符集——系统
|
|
148
|
+
`detect_language` 对拉丁语系只返回 `latin`,区分具体语言需要词级判据。
|
|
149
|
+
命中不了时返回 `latin`(诚实标注「未区分」,不硬猜)。
|
|
150
|
+
"""
|
|
151
|
+
q = query.lower()
|
|
152
|
+
# 特征词/字符 → 语言(按候选集裁剪,避免把「德」的特征词用在中式英文上)
|
|
153
|
+
markers: list[tuple[str, list[str]]] = [
|
|
154
|
+
("vi", ["thời tiết", "dự báo", "tin thế giới", "việt"]),
|
|
155
|
+
("de", ["wetter", "vorhersage", "nachrichten", "weltnachrichten", "temperatur"]),
|
|
156
|
+
("fr", ["météo", "prévision", "nouvelles", "aujourd'hui", "prévisions"]),
|
|
157
|
+
("es", ["tiempo", "pronóstico", "noticias", "del mundo", "previsión"]),
|
|
158
|
+
("pt", ["previsão", "notícias", "do tempo", "do mundo", "são paulo"]),
|
|
159
|
+
("cs", ["počasí", "předpověď", "světové", "zprávy", "teplota"]),
|
|
160
|
+
("tr", ["hava durumu", "tahmin", "dünya haberleri", "yağış", "sıcaklık"]),
|
|
161
|
+
("id", ["prakiraan cuaca", "berita dunia", "hari ini", "jakarta"]),
|
|
162
|
+
]
|
|
163
|
+
for lang, words in markers:
|
|
164
|
+
if lang in candidates and any(w in q for w in words):
|
|
165
|
+
return lang
|
|
166
|
+
return "latin"
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# 组名 → 该组声明的语言清单(供修正既有条目时确定具体语言)
|
|
170
|
+
_GROUP_LANGS: dict[str, list[str]] = {
|
|
171
|
+
g: list(langs) for g, langs, _ in _LANGUAGE_GROUPS
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def build(entries: list[dict[str, Any]]) -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
|
176
|
+
"""为每种语言生成用例,实测路由后写入(命中的才写)。"""
|
|
177
|
+
from config import get_domains
|
|
178
|
+
from route import route_query
|
|
179
|
+
from route_domains import match_domains
|
|
180
|
+
|
|
181
|
+
doms = get_domains()
|
|
182
|
+
dmap = {d["name"]: d for d in doms}
|
|
183
|
+
existing = {e["query"] for e in entries}
|
|
184
|
+
|
|
185
|
+
out = list(entries)
|
|
186
|
+
added = 0
|
|
187
|
+
hit_count = 0
|
|
188
|
+
miss_count = 0
|
|
189
|
+
misses: list[str] = []
|
|
190
|
+
langs_covered: set[str] = set()
|
|
191
|
+
|
|
192
|
+
for group, langs, cases in _LANGUAGE_GROUPS:
|
|
193
|
+
for query, want_domain, why in cases:
|
|
194
|
+
if query in existing:
|
|
195
|
+
continue
|
|
196
|
+
if want_domain not in dmap:
|
|
197
|
+
continue
|
|
198
|
+
try:
|
|
199
|
+
r = route_query(query, mode="auto", depth="fast")
|
|
200
|
+
except Exception:
|
|
201
|
+
continue
|
|
202
|
+
hit_names = {h.get("name") for h in match_domains(query, doms, max_n=5)}
|
|
203
|
+
if want_domain in hit_names:
|
|
204
|
+
hit_count += 1
|
|
205
|
+
# 具体语言由**组声明**给出,不由字符判定——拉丁语系都是
|
|
206
|
+
# latin,字符判定会把越南语误判成英文。组内有多语言时取
|
|
207
|
+
# 第一个(一条用例只测一种语言)。
|
|
208
|
+
specific_lang = langs[0] if len(langs) == 1 else _guess_latin_lang(query, langs)
|
|
209
|
+
langs_covered.add(specific_lang)
|
|
210
|
+
out.append({
|
|
211
|
+
"query": query,
|
|
212
|
+
"expect_domain": want_domain,
|
|
213
|
+
"expect_family": None,
|
|
214
|
+
"evidence": "language",
|
|
215
|
+
"quality": {"errors": False, "recovered": False,
|
|
216
|
+
"count": 0, "occurrences": 1},
|
|
217
|
+
"source": f"language:{group}",
|
|
218
|
+
"lang": specific_lang,
|
|
219
|
+
"script": _lang_of(query),
|
|
220
|
+
"intent": None,
|
|
221
|
+
})
|
|
222
|
+
added += 1
|
|
223
|
+
else:
|
|
224
|
+
miss_count += 1
|
|
225
|
+
if len(misses) < 40:
|
|
226
|
+
misses.append(
|
|
227
|
+
f" {query[:34]!r:38} want={want_domain:20} "
|
|
228
|
+
f"got={r.get('domain'):20} [{why}]")
|
|
229
|
+
|
|
230
|
+
# 修正既有 language 条目的 lang/script 字段——它们是上一版用字符判定
|
|
231
|
+
# 写入的(把越南语判成 en、日语判成 zh),必须重算,否则错标签会留在
|
|
232
|
+
# 语料里被当成事实。
|
|
233
|
+
fixed = 0
|
|
234
|
+
for e in out:
|
|
235
|
+
if e.get("evidence") != "language":
|
|
236
|
+
continue
|
|
237
|
+
script = _lang_of(e["query"])
|
|
238
|
+
# 具体语言:优先用组声明的候选集做词级猜测
|
|
239
|
+
group_langs = _GROUP_LANGS.get(
|
|
240
|
+
str(e.get("source", "")).replace("language:", ""), [])
|
|
241
|
+
if len(group_langs) == 1:
|
|
242
|
+
lang = group_langs[0]
|
|
243
|
+
elif script == "latin":
|
|
244
|
+
lang = _guess_latin_lang(e["query"], group_langs) if group_langs else "latin"
|
|
245
|
+
else:
|
|
246
|
+
lang = script
|
|
247
|
+
if e.get("lang") != lang or e.get("script") != script:
|
|
248
|
+
fixed += 1
|
|
249
|
+
e["lang"] = lang
|
|
250
|
+
e["script"] = script
|
|
251
|
+
|
|
252
|
+
# 补 intent 标签
|
|
253
|
+
try:
|
|
254
|
+
from extend_route_labels import classify_intent
|
|
255
|
+
for e in out:
|
|
256
|
+
if not e.get("intent"):
|
|
257
|
+
e["intent"] = classify_intent(e["query"], e.get("expect_domain"))
|
|
258
|
+
except Exception:
|
|
259
|
+
pass
|
|
260
|
+
|
|
261
|
+
stats = {
|
|
262
|
+
"total": len(out),
|
|
263
|
+
"added": added,
|
|
264
|
+
"hit": hit_count,
|
|
265
|
+
"miss": miss_count,
|
|
266
|
+
"langs_covered": sorted(langs_covered),
|
|
267
|
+
"lang_fields_fixed": fixed,
|
|
268
|
+
"misses": misses,
|
|
269
|
+
}
|
|
270
|
+
return out, stats
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def main() -> int:
|
|
274
|
+
ap = argparse.ArgumentParser(description="按语言能力扩展路由标注集")
|
|
275
|
+
ap.add_argument("--dry-run", action="store_true")
|
|
276
|
+
ap.add_argument("--report", action="store_true")
|
|
277
|
+
args = ap.parse_args()
|
|
278
|
+
|
|
279
|
+
if not LABELS.is_file():
|
|
280
|
+
print(f"[lang-extend] 语料不存在:{LABELS}", file=sys.stderr)
|
|
281
|
+
return 1
|
|
282
|
+
entries = [json.loads(l) for l in
|
|
283
|
+
LABELS.read_text(encoding="utf-8").splitlines() if l.strip()]
|
|
284
|
+
|
|
285
|
+
extended, stats = build(entries)
|
|
286
|
+
print(f"[lang-extend] 语料 {len(entries)} -> {stats['total']} 条"
|
|
287
|
+
f"(新增 {stats['added']},命中 {stats['hit']},失配 {stats['miss']})")
|
|
288
|
+
print(f"[lang-extend] 覆盖语言: {stats['langs_covered']}")
|
|
289
|
+
|
|
290
|
+
if args.report and stats["misses"]:
|
|
291
|
+
print("失配样例:")
|
|
292
|
+
for m in stats["misses"]:
|
|
293
|
+
print(m)
|
|
294
|
+
|
|
295
|
+
if args.dry_run:
|
|
296
|
+
return 0
|
|
297
|
+
|
|
298
|
+
with LABELS.open("w", encoding="utf-8") as f:
|
|
299
|
+
for e in extended:
|
|
300
|
+
f.write(json.dumps(e, ensure_ascii=False) + "\n")
|
|
301
|
+
print(f"[lang-extend] 已写回 {LABELS}")
|
|
302
|
+
return 0
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
if __name__ == "__main__":
|
|
306
|
+
raise SystemExit(main())
|
|
Binary file
|
package/scripts/job.py
CHANGED
|
@@ -919,7 +919,8 @@ def _mark_source_down(name: str, detail: str) -> None:
|
|
|
919
919
|
"""
|
|
920
920
|
try:
|
|
921
921
|
from quota import get_quota_manager
|
|
922
|
-
get_quota_manager().mark_remote_exhausted(
|
|
922
|
+
get_quota_manager().mark_remote_exhausted(
|
|
923
|
+
name, reason=detail[:160], category="quota_exhausted")
|
|
923
924
|
except Exception:
|
|
924
925
|
pass
|
|
925
926
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""lint_spec_contracts.py — 引擎规格契约 lint(声明层复发护栏)。
|
|
3
|
+
|
|
4
|
+
背景:声明式引擎规格与消费层之间隔了四层契约(spec.search_args → CLI 实参
|
|
5
|
+
→ 解析格式 → output_map/envelope 键),历史上反复出的事故都卡在「层与层
|
|
6
|
+
之间没有机器校验」:
|
|
7
|
+
- 2026-10-27 bilibili.search_args 少传 --json,social_meta 在 JSON 解析前
|
|
8
|
+
就不存在,三层各错一点(video P0)
|
|
9
|
+
- 2026-11-03 xhs CLI 未下发 --json,_parse_xhs_output 的 json.loads 失败
|
|
10
|
+
静默返回空列表(issue #36)
|
|
11
|
+
本 lint 不做运行时校验(那是引擎与用例的职责),只在声明层钉不变式,让同
|
|
12
|
+
类规格在提交前被拦下。只读 YAML、零运行时导入,供门禁与
|
|
13
|
+
tests/test_spec_contracts.py 调用。
|
|
14
|
+
|
|
15
|
+
不变式:
|
|
16
|
+
C1 type: cli 且声明了 output_map ⇒ search_args 必须显式请求机器可读输
|
|
17
|
+
出(含 "json" 的旗标)或声明 output_format。output_map 是结构化输出
|
|
18
|
+
的字段映射,人读文本流上它整体是死代码——spec 必须表态。
|
|
19
|
+
C2 结构完整性:type: cli 必须带 cmd;engine_id 必填且不得为空。
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import sys
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
from typing import Any
|
|
27
|
+
|
|
28
|
+
SKILL_DIR = Path(__file__).resolve().parent.parent
|
|
29
|
+
SPECS_DIR = SKILL_DIR / "engines" / "specs"
|
|
30
|
+
CONFIG_PATH = SKILL_DIR / "config.yaml"
|
|
31
|
+
|
|
32
|
+
# C1 的显式豁免名单(engine_id):规格声明的 CLI 默认输出就是机器可读、
|
|
33
|
+
# 且无 --json 类旗标可传时,在此登记并注明依据。当前为空——出现新豁免
|
|
34
|
+
# 必须在行内写清实测依据,否则优先改 spec。
|
|
35
|
+
JSON_FLAG_EXEMPT: set[str] = set()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def load_specs() -> list[tuple[str, str, dict[str, Any]]]:
|
|
39
|
+
"""收集声明式规格:(来源标签, engine_id, spec)。含 engines/specs/*.yaml
|
|
40
|
+
与 config.yaml engines 段里的 dict 条目。读不了的文件计为一条结构违例。"""
|
|
41
|
+
out: list[tuple[str, str, dict[str, Any]]] = []
|
|
42
|
+
for p in sorted(SPECS_DIR.glob("*.yaml")):
|
|
43
|
+
try:
|
|
44
|
+
from yaml_load import loads
|
|
45
|
+
|
|
46
|
+
data = loads(p.read_text(encoding="utf-8"))
|
|
47
|
+
except Exception as e: # 坏 YAML 本身就是结构违例
|
|
48
|
+
out.append((f"specs/{p.name}", "", {"_load_error": str(e)}))
|
|
49
|
+
continue
|
|
50
|
+
if isinstance(data, dict):
|
|
51
|
+
out.append((f"specs/{p.name}", str(data.get("engine_id", "")), data))
|
|
52
|
+
try:
|
|
53
|
+
from yaml_load import loads
|
|
54
|
+
|
|
55
|
+
cfg = loads(CONFIG_PATH.read_text(encoding="utf-8")) or {}
|
|
56
|
+
except Exception:
|
|
57
|
+
cfg = {}
|
|
58
|
+
for name, spec in (cfg.get("engines") or {}).items():
|
|
59
|
+
if isinstance(spec, dict) and spec.get("type") == "cli":
|
|
60
|
+
out.append(("config.yaml", str(name), spec))
|
|
61
|
+
return out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def lint_specs(specs: list[tuple[str, str, dict[str, Any]]]) -> list[str]:
|
|
65
|
+
"""返回违例列表(空 = 通过)。每条带不变式编号与文件出处。"""
|
|
66
|
+
violations: list[str] = []
|
|
67
|
+
for origin, engine_id, spec in specs:
|
|
68
|
+
where = f"{origin}:{engine_id or '?'}"
|
|
69
|
+
if spec.get("_load_error"):
|
|
70
|
+
violations.append(f"C2 {where}: YAML 解析失败 {spec['_load_error']}")
|
|
71
|
+
continue
|
|
72
|
+
etype = spec.get("type")
|
|
73
|
+
# C2 结构完整性
|
|
74
|
+
if etype == "cli":
|
|
75
|
+
cmd = spec.get("cmd")
|
|
76
|
+
if not cmd or (isinstance(cmd, list) and not cmd):
|
|
77
|
+
violations.append(f"C2 {where}: type: cli 缺 cmd,规格永远发不出请求")
|
|
78
|
+
if not str(engine_id or "").strip() and origin.startswith("specs/"):
|
|
79
|
+
violations.append(f"C2 {origin}: 缺 engine_id")
|
|
80
|
+
# C1 机器可读输出契约
|
|
81
|
+
if etype == "cli":
|
|
82
|
+
omap = spec.get("output_map")
|
|
83
|
+
if isinstance(omap, dict) and omap and engine_id not in JSON_FLAG_EXEMPT:
|
|
84
|
+
args = [str(a) for a in (spec.get("search_args") or [])]
|
|
85
|
+
fmt = str(spec.get("output_format", "")).strip().lower()
|
|
86
|
+
asks_machine_readable = fmt in ("json", "yaml") or any(
|
|
87
|
+
"json" in a.lower() for a in args
|
|
88
|
+
)
|
|
89
|
+
if not asks_machine_readable:
|
|
90
|
+
violations.append(
|
|
91
|
+
f"C1 {where}: 声明了 output_map 但 search_args 未请求 "
|
|
92
|
+
f"JSON 且未声明 output_format——人读文本流上 output_map "
|
|
93
|
+
f"整体是死代码(bilibili/xhs 同类根因)"
|
|
94
|
+
)
|
|
95
|
+
return violations
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def main(argv: list[str] | None = None) -> int:
|
|
99
|
+
violations = lint_specs(load_specs())
|
|
100
|
+
if violations:
|
|
101
|
+
for v in violations:
|
|
102
|
+
print(f"❌ {v}", file=sys.stderr)
|
|
103
|
+
print(f"spec 契约 lint:{len(violations)} 条违例", file=sys.stderr)
|
|
104
|
+
return 1
|
|
105
|
+
print(f"✅ spec 契约一致({len(load_specs())} 份规格)")
|
|
106
|
+
return 0
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if __name__ == "__main__":
|
|
110
|
+
sys.exit(main())
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""lint_stub_targets.py — 测试打桩目标存在性 lint(复发护栏)。
|
|
3
|
+
|
|
4
|
+
背景:重构搬函数后,测试里的 monkeypatch.setattr / mock.patch 若仍指向旧
|
|
5
|
+
模块名,打桩会落在转出副本上成为**空操作**——测试照绿、真行为已变。历史
|
|
6
|
+
上至少两例(2026-10-22 `_RETRY_FAST_S` 与 `_seek_py` 打桩旧模块,2026-10-23
|
|
7
|
+
CI 假绿第三例),都是全量才红或人工撞见。
|
|
8
|
+
|
|
9
|
+
本 lint 用 AST 找出 tests/ 里以**字符串字面量**为目标的打桩点,逐个验证
|
|
10
|
+
「模块可导入 → 属性链存在」。两条边界如实说明:
|
|
11
|
+
- 打桩目标在「转出副本」上但属性仍在(打桩空转的最隐蔽形态)静态不可
|
|
12
|
+
判定,不在本 lint 范围;那类靠「拆完必须扫 tests 旧模块名打桩点」的
|
|
13
|
+
流程纪律兜底。
|
|
14
|
+
- 模块导入失败按「可选依赖缺失」跳过不计违例——环境缺件是另一类问题;
|
|
15
|
+
只报「模块在、属性不在」这一种确定性错误。
|
|
16
|
+
`raising=False` / `create=True` 的创建式打桩是合法用法,显式豁免。
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import ast
|
|
22
|
+
import importlib
|
|
23
|
+
import sys
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any
|
|
26
|
+
|
|
27
|
+
SKILL_DIR = Path(__file__).resolve().parent.parent
|
|
28
|
+
TESTS_DIR = SKILL_DIR / "tests"
|
|
29
|
+
|
|
30
|
+
# 打桩入口:(*, 目标在第一个位置参数的字符串字面量里)
|
|
31
|
+
STUB_CALL_NAMES = {"setattr", "patch", "patch_object"} # patch.object 归一后
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _call_name(node: ast.AST) -> str | None:
|
|
35
|
+
"""归一调用名:monkeypatch.setattr → setattr;mock.patch → patch;
|
|
36
|
+
patch.object → patch_object。"""
|
|
37
|
+
if not isinstance(node, ast.Call):
|
|
38
|
+
return None
|
|
39
|
+
f = node.func
|
|
40
|
+
if isinstance(f, ast.Attribute):
|
|
41
|
+
if f.attr in ("setattr", "patch"):
|
|
42
|
+
return f.attr
|
|
43
|
+
if f.attr == "object" and isinstance(f.value, ast.Attribute) and f.value.attr == "patch":
|
|
44
|
+
return "patch_object"
|
|
45
|
+
if isinstance(f, ast.Name) and f.id == "patch":
|
|
46
|
+
return "patch"
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _is_creating_stub(call: ast.Call) -> bool:
|
|
51
|
+
"""raising=False / create=True 的创建式打桩:允许造新属性,豁免。"""
|
|
52
|
+
for kw in call.keywords:
|
|
53
|
+
if kw.arg in ("raising", "create") and isinstance(kw.value, ast.Constant):
|
|
54
|
+
if kw.value.value is False and kw.arg == "raising":
|
|
55
|
+
return True
|
|
56
|
+
if kw.value.value is True and kw.arg == "create":
|
|
57
|
+
return True
|
|
58
|
+
return False
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def lint_file(path: Path, _resolver=None) -> list[str]:
|
|
62
|
+
"""扫描单文件,返回违例(file:line 目标 原因)。"""
|
|
63
|
+
try:
|
|
64
|
+
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
|
|
65
|
+
except SyntaxError:
|
|
66
|
+
return [] # 语法错误由 static_lint 门负责,这里不重复报
|
|
67
|
+
violations: list[str] = []
|
|
68
|
+
for node in ast.walk(tree):
|
|
69
|
+
name = _call_name(node)
|
|
70
|
+
if not name or not node.args:
|
|
71
|
+
continue
|
|
72
|
+
first = node.args[0]
|
|
73
|
+
if not (isinstance(first, ast.Constant) and isinstance(first.value, str)):
|
|
74
|
+
continue # 对象形态打桩(setattr(obj, "name", …))是安全形态
|
|
75
|
+
target = first.value
|
|
76
|
+
if "." not in target or not target.strip():
|
|
77
|
+
continue
|
|
78
|
+
if name in ("setattr", "patch") and _is_creating_stub(node):
|
|
79
|
+
continue
|
|
80
|
+
reason = (_resolver or resolve_target)(target)
|
|
81
|
+
if reason:
|
|
82
|
+
try:
|
|
83
|
+
rel = path.relative_to(SKILL_DIR)
|
|
84
|
+
except ValueError: # 仓外文件(测试正向控制用 tmp_path):原样呈现
|
|
85
|
+
rel = path
|
|
86
|
+
violations.append(f"{rel}:{node.lineno} {target} {reason}")
|
|
87
|
+
return violations
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def resolve_target(target: str) -> str | None:
|
|
91
|
+
"""返回违例原因;None = 可验证且通过;模块不可导入返回 None(可选依赖
|
|
92
|
+
缺失按跳过处理,见模块 docstring 的边界说明)。"""
|
|
93
|
+
parts = target.split(".")
|
|
94
|
+
for i in range(len(parts) - 1, 0, -1):
|
|
95
|
+
modname = ".".join(parts[:i])
|
|
96
|
+
try:
|
|
97
|
+
mod = importlib.import_module(modname)
|
|
98
|
+
except Exception:
|
|
99
|
+
continue # 可选依赖缺失/重副作用模块:跳过,不当违例
|
|
100
|
+
cur: Any = mod
|
|
101
|
+
for attr in parts[i:]:
|
|
102
|
+
try:
|
|
103
|
+
cur = getattr(cur, attr)
|
|
104
|
+
except AttributeError:
|
|
105
|
+
return f"模块 {modname} 可导入但属性缺失"
|
|
106
|
+
return None
|
|
107
|
+
return None # 顶层模块就不可导入:按可选依赖缺失跳过
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def lint_tests_dir(tests_dir: Path | None = None) -> list[str]:
|
|
111
|
+
root = tests_dir or TESTS_DIR
|
|
112
|
+
violations: list[str] = []
|
|
113
|
+
for p in sorted(root.glob("test_*.py")):
|
|
114
|
+
violations.extend(lint_file(p))
|
|
115
|
+
return violations
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def main() -> int:
|
|
119
|
+
violations = lint_tests_dir()
|
|
120
|
+
if violations:
|
|
121
|
+
for v in violations:
|
|
122
|
+
print(f"❌ {v}", file=sys.stderr)
|
|
123
|
+
print(f"打桩目标 lint:{len(violations)} 条违例", file=sys.stderr)
|
|
124
|
+
return 1
|
|
125
|
+
print("✅ 打桩目标全部可解析")
|
|
126
|
+
return 0
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == "__main__":
|
|
130
|
+
sys.exit(main())
|
package/scripts/local_image.py
CHANGED
|
@@ -635,9 +635,9 @@ def search_local(
|
|
|
635
635
|
) -> list[dict[str, Any]]:
|
|
636
636
|
"""按文本查本地图片;给 similar_to(图片路径)时按指纹找相似图。
|
|
637
637
|
|
|
638
|
-
`similar_to`
|
|
639
|
-
|
|
640
|
-
|
|
638
|
+
`similar_to` 走的是「以图找相似」:不回答「这张图从哪来」(那是反搜图
|
|
639
|
+
引擎的事,且都要外网与凭据),而是在本机素材里回答「有没有和它像的」,
|
|
640
|
+
离线、不产生调用成本。
|
|
641
641
|
"""
|
|
642
642
|
if similar_to:
|
|
643
643
|
return _search_by_fingerprint(conn, similar_to, limit=limit)
|
package/scripts/mcp_compact.py
CHANGED
|
@@ -49,6 +49,11 @@ def _compact_search_result(result: dict[str, Any], summary: bool = False) -> dic
|
|
|
49
49
|
# 保留发布时间维度(仅引擎输出该字段时,避免空字段噪音)
|
|
50
50
|
if r.get("published_at"):
|
|
51
51
|
item["published_at"] = r["published_at"]
|
|
52
|
+
# 图链与许可:图搜/反搜图结果靠这两条「看图」,缺了 Agent 只剩出处页链接。
|
|
53
|
+
# 缩略图只作展示(出处与引用仍以 url 为准),所以不进 snippet、也不当证据。
|
|
54
|
+
for k in ("image_url", "image_license"):
|
|
55
|
+
if r.get(k):
|
|
56
|
+
item[k] = r[k]
|
|
52
57
|
# 顶包标记:recovery 替换了引擎原结果时透传,供上层识别结果已被代答
|
|
53
58
|
if r.get("_recovered"):
|
|
54
59
|
item["recovered"] = r["_recovered"]
|