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
|
@@ -81,14 +81,28 @@ def _route_one(query: str) -> dict:
|
|
|
81
81
|
from route import route_query
|
|
82
82
|
d = route_query(query, mode="auto", depth="fast")
|
|
83
83
|
reason = d.get("reason") or ""
|
|
84
|
-
kind
|
|
84
|
+
# kind 判定口径:**按路由分支**判,不按 reason 文案判。
|
|
85
|
+
#
|
|
86
|
+
# 2026-11-02 修:此前判据是「reason 里有没有 TF-IDF 字样」。概念路由默认关
|
|
87
|
+
# 之后,域命中分支的 reason 不再写 [TF-IDF→x](那一行只在推荐真进 combo 时
|
|
88
|
+
# 才写),于是 87 条域命中查询的 kind 从 tfidf 误翻成 regex——快照失去
|
|
89
|
+
# 「这条路由走的是硬域正则还是语义选源」这个信息。
|
|
90
|
+
#
|
|
91
|
+
# 正确判据:reason 以「TF-IDF」开头的是语义选源分支;domain 非空且 reason
|
|
92
|
+
# 含「命中域」的是域分支;domain 为 general_search 且无命中域的是回退。
|
|
93
|
+
if reason.startswith("TF-IDF") or "回退通用" in reason:
|
|
94
|
+
kind = "tfidf"
|
|
95
|
+
else:
|
|
96
|
+
kind = "regex"
|
|
85
97
|
return {
|
|
86
98
|
"domain": d.get("domain"),
|
|
87
99
|
"kind": kind,
|
|
88
100
|
"engines": (d.get("engines_combo") or [])[:2],
|
|
101
|
+
"reason": reason,
|
|
89
102
|
}
|
|
90
103
|
|
|
91
104
|
|
|
105
|
+
|
|
92
106
|
def _build() -> list[dict]:
|
|
93
107
|
out = []
|
|
94
108
|
for e in _collect_corpus():
|
|
@@ -113,9 +127,10 @@ def _diff(current: list[dict], recorded: list[dict]) -> list[str]:
|
|
|
113
127
|
continue
|
|
114
128
|
for key in ("domain", "kind"):
|
|
115
129
|
if prev.get(key) != e.get(key):
|
|
130
|
+
reason_hint = f"\n (当前 reason: {e.get('reason')!r})" if e.get("reason") else ""
|
|
116
131
|
problems.append(
|
|
117
132
|
f" {e['query']!r}: {key} {prev.get(key)!r} -> {e.get(key)!r}"
|
|
118
|
-
f"(期望域 {e.get('expect')!r},来源 {e.get('src')})")
|
|
133
|
+
f"(期望域 {e.get('expect')!r},来源 {e.get('src')}){reason_hint}")
|
|
119
134
|
for q in sorted(set(old) - {e["query"] for e in current}):
|
|
120
135
|
problems.append(f" 快照有而语料没有: {q!r}(语料被删?若是故意,重新生成)")
|
|
121
136
|
# 期望域失配(标注集自己抓的那层,快照顺带报告)
|
|
@@ -176,13 +191,17 @@ def main() -> int:
|
|
|
176
191
|
print(f"路由快照对账通过({len(current)} 条查询,domain+kind 零漂移)")
|
|
177
192
|
return 0
|
|
178
193
|
|
|
194
|
+
clean_entries = [
|
|
195
|
+
{k: v for k, v in e.items() if k != "reason"}
|
|
196
|
+
for e in current
|
|
197
|
+
]
|
|
179
198
|
payload = {
|
|
180
199
|
"version": 1,
|
|
181
200
|
"generated_by": "scripts/gen_routing_snapshot.py",
|
|
182
201
|
"compare_keys": ["domain", "kind"],
|
|
183
202
|
"note": "engines 仅存档不比对(随熔断/配额波动);expect/forbid 是语料"
|
|
184
203
|
"自带的标注,失配由 precision/negative 测试与 --check 双报",
|
|
185
|
-
"entries":
|
|
204
|
+
"entries": clean_entries,
|
|
186
205
|
}
|
|
187
206
|
SNAPSHOT.parent.mkdir(parents=True, exist_ok=True)
|
|
188
207
|
SNAPSHOT.write_text(json.dumps(payload, ensure_ascii=False, indent=1) + "\n",
|
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
|
|
package/scripts/lang_detect.py
CHANGED
|
@@ -214,15 +214,24 @@ def detect_language(query: str) -> str:
|
|
|
214
214
|
# 汉字为主判 zh
|
|
215
215
|
if han / total_chars >= 0.3:
|
|
216
216
|
return "zh"
|
|
217
|
+
# 汉字与拉丁并存的中文技术查询(「Transformer 模型 原理」「OpenAI o3 评测」
|
|
218
|
+
# 「Python asyncio 教程」)判 mixed 而不是 en。
|
|
219
|
+
#
|
|
220
|
+
# 为什么这条放在拉丁判定**之前**:这些查询里拉丁词是技术专名(模型名、
|
|
221
|
+
# 库名、产品名),汉字才是用户真正在问的内容。判 en 会让
|
|
222
|
+
# route_domains 的中文域语言门把所有中文域整片跳过——实测「Transformer
|
|
223
|
+
# 模型 原理」命中 chinese_tech_deep/chinese_general 后又被门清空,
|
|
224
|
+
# 掉进 TF-IDF 分支落到 arxiv(返回 NLP 综述,而用户要的是原理)。
|
|
225
|
+
# 判 mixed 与 en 都不在 _ZH_LANG_GATED_DOMAINS 的跳过条件里
|
|
226
|
+
# (`primary_lang not in ("zh","mixed","other")`),中文域正常参与。
|
|
227
|
+
if han and latin:
|
|
228
|
+
return "mixed"
|
|
217
229
|
# 拉丁字母(含扩展字符 é/ü/ñ 等)为主 → 拉丁语系
|
|
218
230
|
# 扩展字符占比 ≥ 0.08 时判 latin(café / español / français 等)
|
|
219
231
|
if (latin + latin_ext) / total_chars >= 0.5:
|
|
220
232
|
if latin_ext / total_chars >= 0.08:
|
|
221
233
|
return "latin"
|
|
222
234
|
return "en" if latin else "latin"
|
|
223
|
-
# 有汉字也有大量拉丁 → 中英混合;其余情况判混合
|
|
224
|
-
if han and latin:
|
|
225
|
-
return "mixed"
|
|
226
235
|
return "other"
|
|
227
236
|
|
|
228
237
|
|
|
@@ -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/local_seek.py
CHANGED
|
@@ -335,13 +335,23 @@ def _run_local_seek(query: str, max_n: int = 5,
|
|
|
335
335
|
|
|
336
336
|
|
|
337
337
|
def _load_seek_module(seek_py: str):
|
|
338
|
-
"""按解析后真实路径加载 seek 模块(importlib
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
"""按解析后真实路径加载 seek 模块(importlib 显式文件定位,不占通用
|
|
339
|
+
模块名),按路径缓存——ARGO_LOCAL_SEEK_PATH 指向不同文件时各自独立
|
|
340
|
+
加载。失败返回 None。
|
|
341
|
+
|
|
342
|
+
seek.py 模块级有 sibling 导入(from seek_rank import ...),而
|
|
343
|
+
spec_from_file_location 不像脚本运行那样把文件所在目录放进 sys.path
|
|
344
|
+
——干净进程里 exec_module 必 ModuleNotFoundError,进程内路径名存实亡
|
|
345
|
+
(2026-10-31 实测:CI 与本机 sys.path 污染顺序不同,同一条测试一边绿
|
|
346
|
+
一边红)。加载前把 seek.py 所在目录补进 sys.path(去重),进程内加载
|
|
347
|
+
从此确定性可用;模块名仍走 argo_seek_impl,不占通用名。"""
|
|
341
348
|
mod = _SEEK_MODULE_CACHE.get(seek_py)
|
|
342
349
|
if mod is not None:
|
|
343
350
|
return mod
|
|
344
351
|
import importlib.util
|
|
352
|
+
seek_dir = os.path.dirname(os.path.abspath(seek_py))
|
|
353
|
+
if seek_dir and seek_dir not in sys.path:
|
|
354
|
+
sys.path.insert(0, seek_dir)
|
|
345
355
|
spec = importlib.util.spec_from_file_location("argo_seek_impl", seek_py)
|
|
346
356
|
if spec is None or spec.loader is None:
|
|
347
357
|
return None
|
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"]
|
package/scripts/mcp_transport.py
CHANGED
package/scripts/net_proxy.py
CHANGED
|
@@ -178,6 +178,48 @@ def resolve_proxy(url: str, override: str | None = None,
|
|
|
178
178
|
return None
|
|
179
179
|
|
|
180
180
|
|
|
181
|
+
def _matched_rule_value(url: str) -> str | None:
|
|
182
|
+
"""命中的域规则的**原始值**(未插值);未命中返回 None。
|
|
183
|
+
|
|
184
|
+
与 resolve_proxy 的分工:那里把 `${VAR}` 未设置也压成 None(=不设代理),
|
|
185
|
+
无法区分「没配规则」与「规则要求直连」。open_url 需要这个区分——前者
|
|
186
|
+
维持 urlopen 的原生行为,后者要绕开标准环境变量代理。
|
|
187
|
+
"""
|
|
188
|
+
try:
|
|
189
|
+
import urllib.parse
|
|
190
|
+
host = (urllib.parse.urlparse(url if "//" in url else "https://" + url)
|
|
191
|
+
.hostname or "").lower()
|
|
192
|
+
for domain, val in (_network_cfg().get("rules") or {}).items():
|
|
193
|
+
d = str(domain).lower().strip()
|
|
194
|
+
if d and (host == d or host.endswith("." + d)):
|
|
195
|
+
return str(val)
|
|
196
|
+
except Exception:
|
|
197
|
+
return None
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def explicit_direct(url: str) -> bool:
|
|
202
|
+
"""argo 级配置是否**显式**要求该 URL 直连(而不是「恰好没配代理」)。
|
|
203
|
+
|
|
204
|
+
为什么需要:urlopen 原生认标准 `HTTP(S)_PROXY`。rules 写 "direct"、或
|
|
205
|
+
`${VAR}` 的 VAR 未设置时,本意都是「真直连」,但 resolve_proxy 只回 None,
|
|
206
|
+
open_url 落回 urlopen 后又被环境变量代理兜走——「强制直连」在设了
|
|
207
|
+
HTTPS_PROXY 的机器上名不副实。例:animetrace.com 这类源按出口 IP 限频,
|
|
208
|
+
配置写明 direct 却仍走 Clash 出口时稳定 429——是否该直连取决于本机出口,
|
|
209
|
+
但 explicit_direct 至少要保证调用方真的拿到配置要求的出口。
|
|
210
|
+
"""
|
|
211
|
+
val = _matched_rule_value(url)
|
|
212
|
+
if val is not None:
|
|
213
|
+
return _interp_env(val) is None
|
|
214
|
+
argo = _argo_env("ARGO_PROXY")
|
|
215
|
+
if argo:
|
|
216
|
+
return argo.lower() == "direct"
|
|
217
|
+
cu = str(_network_cfg().get("url") or "").strip()
|
|
218
|
+
if cu:
|
|
219
|
+
return _interp_env(cu) is None
|
|
220
|
+
return False
|
|
221
|
+
|
|
222
|
+
|
|
181
223
|
def open_url(req: Any, timeout: float = 10.0):
|
|
182
224
|
"""代理感知的 `urllib.request.urlopen` 替身——urllib 类出口的唯一入口。
|
|
183
225
|
|
|
@@ -210,6 +252,11 @@ def open_url(req: Any, timeout: float = 10.0):
|
|
|
210
252
|
logger.debug("代理解析失败(%s),本次按直连处理:%r", url, e)
|
|
211
253
|
px = None
|
|
212
254
|
if not px:
|
|
255
|
+
# 显式直连要自己装空 ProxyHandler:urlopen 会把标准环境变量里的代理
|
|
256
|
+
# 再兜一层,那样 rules="direct" 等于没写。未配置时仍走 urlopen 原生。
|
|
257
|
+
if explicit_direct(url):
|
|
258
|
+
return urllib.request.build_opener(
|
|
259
|
+
urllib.request.ProxyHandler({})).open(req, timeout=timeout)
|
|
213
260
|
return urllib.request.urlopen(req, timeout=timeout)
|
|
214
261
|
scheme = urllib.parse.urlparse(url).scheme or "https"
|
|
215
262
|
opener = urllib.request.build_opener(
|