argo-search 2.9.9 → 2.10.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/README.en.md +24 -21
- package/README.es.md +24 -21
- package/README.ja.md +23 -20
- package/README.ko.md +23 -20
- package/README.md +26 -21
- package/SKILL.md +5 -5
- package/backends/domain_profiles.json +76 -0
- package/backends/engine_registry.yaml +161 -5
- package/backends/quota_profiles.json +122 -2
- package/bin/argo +22 -1
- package/bin/argo.js +3 -3
- package/config.yaml +128 -21
- package/docs/ARGO_INTRO.md +4 -4
- package/docs/ENGINE_CATALOG.md +64 -44
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.10.0.md +85 -0
- package/docs/RELEASE_NOTES_v2.9.8.md +1 -1
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +9 -9
- package/engines/specs/clawhub.yaml +16 -15
- package/engines/specs/deepseek1024.yaml +46 -0
- package/engines/specs/dsh_hub.yaml +44 -0
- package/engines/specs/dshopen.yaml +32 -0
- package/engines/specs/explainx.yaml +32 -0
- package/engines/specs/gbfs_nyc.yaml +6 -1
- package/engines/specs/metaso_doc.yaml +49 -0
- package/engines/specs/metaso_image.yaml +65 -0
- package/engines/specs/metaso_podcast.yaml +60 -0
- package/engines/specs/metaso_scholar.yaml +57 -0
- package/engines/specs/metaso_video.yaml +62 -0
- package/engines/specs/ncpssd.yaml +41 -0
- package/engines/specs/sciverse.yaml +72 -0
- package/engines/specs/skills_sh.yaml +32 -0
- package/engines/specs/skillsmp.yaml +18 -16
- package/package.json +3 -2
- package/packages/dsh-plugin/README.md +3 -2
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/size-gate.test.js +113 -0
- package/scripts/adaptive.py +41 -14
- package/scripts/article.py +6 -1
- package/scripts/article_meta.py +151 -2
- package/scripts/bench_general_pool.py +145 -0
- package/scripts/candidate_envelope.py +45 -4
- package/scripts/charset_decode.py +127 -0
- package/scripts/crawl.py +240 -74
- package/scripts/crawl_frontier.py +217 -0
- package/scripts/crawl_policy.py +174 -0
- package/scripts/engine_dispatch.py +22 -15
- package/scripts/engine_failure.py +15 -0
- package/scripts/engine_validate.py +8 -0
- package/scripts/engines.py +10 -0
- package/scripts/engines_base.py +12 -0
- package/scripts/engines_builders.py +14 -0
- package/scripts/engines_builders_dsh.py +330 -0
- package/scripts/engines_builders_skill.py +314 -0
- package/scripts/fetch_v3.py +37 -5
- package/scripts/gen_engine_catalog.py +218 -2
- package/scripts/general_pool.py +162 -0
- package/scripts/http_client.py +38 -42
- package/scripts/image_ops.py +4 -0
- package/scripts/install.ps1 +47 -19
- package/scripts/install.sh +45 -20
- package/scripts/matrix_search_eval.py +17 -1
- package/scripts/mcp_transport.py +1 -1
- package/scripts/ncpssd_bridge.py +123 -0
- package/scripts/paid_policy.py +109 -13
- package/scripts/pre-commit +19 -4
- package/scripts/query_signals.py +156 -3
- package/scripts/redskill/redskill_engine.py +29 -2
- package/scripts/release_check.py +209 -0
- package/scripts/retry_policy.py +22 -1
- package/scripts/robots_guard.py +26 -0
- package/scripts/route.py +11 -8
- package/scripts/route_cache.py +6 -0
- package/scripts/route_combo.py +37 -59
- package/scripts/route_domains.py +4 -1
- package/scripts/route_policy.py +6 -0
- package/scripts/search.py +9 -1
- package/scripts/search_cli.py +27 -0
- package/scripts/search_entry.py +9 -0
- package/scripts/search_output.py +29 -0
- package/scripts/search_pipeline.py +39 -1
- package/scripts/search_rank.py +1 -0
- package/scripts/social_engines/bilibili_engine.py +163 -26
- package/scripts/social_engines/reddit_engine.py +52 -51
- package/scripts/source_selection.py +302 -0
- package/scripts/video_fetch.py +303 -0
- package/scripts/video_meta.py +225 -0
- package/scripts/video_route.py +65 -0
- package/scripts/watch.py +123 -0
- package/scripts/local_engines.py +0 -321
package/scripts/watch.py
CHANGED
|
@@ -23,6 +23,7 @@ import re
|
|
|
23
23
|
import sys
|
|
24
24
|
import time
|
|
25
25
|
from typing import Any
|
|
26
|
+
|
|
26
27
|
from cli_io import dumps, dumps_pretty
|
|
27
28
|
|
|
28
29
|
_SNAP_CAP = 10 # 每个 URL 保留的快照历史上限(旧的丢弃)
|
|
@@ -64,6 +65,107 @@ def _content_hash(text: str) -> str:
|
|
|
64
65
|
return hashlib.sha256(_norm(text).encode("utf-8")).hexdigest()[:16]
|
|
65
66
|
|
|
66
67
|
|
|
68
|
+
# ── 噪声感知 diff ────────────────────────────────────────────────────────────
|
|
69
|
+
#
|
|
70
|
+
# 只比哈希会把「价格变了 1 元」「阅读数从 100 涨到 101」都报成变化,观察列表
|
|
71
|
+
# 很快被噪音淹没。这里先把日期、相对时间、价格、计数替换成占位符再比:
|
|
72
|
+
# 占位符之外完全一致 → noise;任何文字差异 → substantive。
|
|
73
|
+
#
|
|
74
|
+
# 纯数字(bare number)故意不算噪声:把「支持 3 种模式」改成「5 种」当成噪声
|
|
75
|
+
# 会漏掉真实内容变化。宁可多报一次,不可漏报。
|
|
76
|
+
|
|
77
|
+
_NOISE_PATTERNS: list[tuple[str, re.Pattern[str]]] = [
|
|
78
|
+
("date", re.compile(
|
|
79
|
+
r"(?:\d{4}[-/.]\d{1,2}[-/.]\d{1,2}(?:[T ]\d{1,2}:\d{2}(?::\d{2})?)?"
|
|
80
|
+
r"|\d{4}年\d{1,2}月(?:\d{1,2}[日号])?"
|
|
81
|
+
r"|\d{1,2}月\d{1,2}[日号]"
|
|
82
|
+
r"|\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.? \d{1,2}(?:, \d{4})?\b)",
|
|
83
|
+
re.IGNORECASE)),
|
|
84
|
+
("relative_time", re.compile(
|
|
85
|
+
r"(?:\b(?:\d+|an?|one)\s?(?:seconds?|secs?|minutes?|mins?|hours?|hrs?|days?"
|
|
86
|
+
r"|weeks?|months?|years?|yrs?)\s+ago\b|\bjust now\b|\byesterday\b"
|
|
87
|
+
r"|\d+\s?(?:个)?(?:秒钟?|分钟|小时|天|周|星期|个月|年)[前后]|刚刚|昨天|前天)",
|
|
88
|
+
re.IGNORECASE)),
|
|
89
|
+
("price", re.compile(
|
|
90
|
+
r"(?:(?:US\$|[$€£¥¥₹₩])\s?\d[\d,]*(?:\.\d+)?"
|
|
91
|
+
r"|\b(?:USD|EUR|GBP|CNY|RMB|JPY)\s?\d[\d,]*(?:\.\d+)?"
|
|
92
|
+
r"|\d[\d,]*(?:\.\d+)?\s?(?:USD|EUR|GBP|CNY|RMB|JPY|元|块钱|美元|欧元|日元|港元))",
|
|
93
|
+
re.IGNORECASE)),
|
|
94
|
+
("count", re.compile(
|
|
95
|
+
r"(?:\d[\d,]*(?:\.\d+)?[kKmM万]?\s?(?:次阅读|次浏览|次播放|次下载|条评论|条回复"
|
|
96
|
+
r"|个赞|人关注|人在看|阅读|浏览|评论|点赞|收藏|播放|转发|分享|下载|回复|关注|赞"
|
|
97
|
+
r"|views?|comments?|likes?|reads?|shares?|replies|retweets?|stars?|downloads?"
|
|
98
|
+
r"|followers?|subscribers?|votes?|points?|visits?|viewers?|reviews?|ratings?)\b"
|
|
99
|
+
r"|(?:次阅读|次浏览|次播放|次下载|条评论|条回复|个赞|人关注|人在看|阅读|浏览|评论"
|
|
100
|
+
r"|点赞|收藏|播放|转发|分享|下载|回复|关注|赞)[::]?\s?\d[\d,]*)",
|
|
101
|
+
re.IGNORECASE)),
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _mask_noise(text: str) -> str:
|
|
106
|
+
for name, pattern in _NOISE_PATTERNS:
|
|
107
|
+
text = pattern.sub(f"<{name.upper()}>", text)
|
|
108
|
+
return text
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _noise_categories(old: str, new: str) -> list[str]:
|
|
112
|
+
"""找出「把该类替换成占位符后两版就一致」的类别——即这次差异由谁解释。"""
|
|
113
|
+
changed = []
|
|
114
|
+
for name, pattern in _NOISE_PATTERNS:
|
|
115
|
+
if not (pattern.search(old) or pattern.search(new)):
|
|
116
|
+
continue
|
|
117
|
+
if _norm(pattern.sub("<X>", old)) == _norm(pattern.sub("<X>", new)):
|
|
118
|
+
changed.append(name)
|
|
119
|
+
return changed
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _blocks(text: str) -> list[str]:
|
|
123
|
+
"""按空行切块;围栏代码块内部的空行不切(否则 diff 会把代码拆散)。"""
|
|
124
|
+
blocks: list[str] = []
|
|
125
|
+
current: list[str] = []
|
|
126
|
+
fence = False
|
|
127
|
+
for line in (text or "").splitlines():
|
|
128
|
+
stripped = line.strip()
|
|
129
|
+
if stripped.startswith(("```", "~~~")):
|
|
130
|
+
fence = not fence
|
|
131
|
+
if not stripped and not fence:
|
|
132
|
+
if current:
|
|
133
|
+
blocks.append("\n".join(current).strip())
|
|
134
|
+
current = []
|
|
135
|
+
continue
|
|
136
|
+
current.append(line)
|
|
137
|
+
if current:
|
|
138
|
+
blocks.append("\n".join(current).strip())
|
|
139
|
+
return [b for b in blocks if b]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _block_key(block: str) -> str:
|
|
143
|
+
return _norm(block)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def diff_text(old: str, new: str) -> dict:
|
|
147
|
+
"""比较两版正文。返回 change_type(none/noise/substantive)与变化块样本。"""
|
|
148
|
+
if _norm(old) == _norm(new):
|
|
149
|
+
return {"change_type": "none", "noise_categories": [],
|
|
150
|
+
"added_blocks": [], "removed_blocks": []}
|
|
151
|
+
old_blocks = _blocks(old)
|
|
152
|
+
new_blocks = _blocks(new)
|
|
153
|
+
old_keys = {_block_key(b) for b in old_blocks}
|
|
154
|
+
new_keys = {_block_key(b) for b in new_blocks}
|
|
155
|
+
added = [b for b in new_blocks if _block_key(b) not in old_keys][:3]
|
|
156
|
+
removed = [b for b in old_blocks if _block_key(b) not in new_keys][:3]
|
|
157
|
+
if _norm(_mask_noise(old)) == _norm(_mask_noise(new)):
|
|
158
|
+
change_type = "noise"
|
|
159
|
+
else:
|
|
160
|
+
change_type = "substantive"
|
|
161
|
+
return {
|
|
162
|
+
"change_type": change_type,
|
|
163
|
+
"noise_categories": _noise_categories(old, new) if change_type == "noise" else [],
|
|
164
|
+
"added_blocks": [b[:200] for b in added],
|
|
165
|
+
"removed_blocks": [b[:200] for b in removed],
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
67
169
|
def _snapshot(url: str, skip_cache: bool = True) -> dict:
|
|
68
170
|
"""抓一帧快照;skip_cache=True 观察必须拿新鲜内容(fetch 缓存会掩盖变化)。"""
|
|
69
171
|
from fetch_v3 import fetch_v3
|
|
@@ -76,11 +178,21 @@ def _snapshot(url: str, skip_cache: bool = True) -> dict:
|
|
|
76
178
|
"title": str(r.get("title") or "")[:200],
|
|
77
179
|
"method": str(r.get("fetch_method") or ""),
|
|
78
180
|
"head": _norm(content)[:200],
|
|
181
|
+
# 只留最近一帧的正文:diff 需要上一版内容,历史帧只留指纹就够。
|
|
182
|
+
# 全部保留会让 watch.json 随观察数线性膨胀(每帧 20k 字符)。
|
|
183
|
+
"content": content[:20000],
|
|
79
184
|
"success": bool(r.get("success")) and bool(content),
|
|
80
185
|
"error": str(r.get("error") or "")[:200],
|
|
81
186
|
}
|
|
82
187
|
|
|
83
188
|
|
|
189
|
+
def _trim_contents(entry: dict) -> None:
|
|
190
|
+
"""只保留最新一帧正文,历史帧删掉内容字段(旧数据本来就没有)。"""
|
|
191
|
+
snaps = entry.get("snapshots") or []
|
|
192
|
+
for snap in snaps[:-1]:
|
|
193
|
+
snap.pop("content", None)
|
|
194
|
+
|
|
195
|
+
|
|
84
196
|
def _latest(url: str, data: dict) -> dict | None:
|
|
85
197
|
snaps = (data["urls"].get(url) or {}).get("snapshots") or []
|
|
86
198
|
return snaps[-1] if snaps else None
|
|
@@ -96,6 +208,7 @@ def cmd_add(url: str, note: str) -> dict:
|
|
|
96
208
|
entry["note"] = note or entry.get("note", "")
|
|
97
209
|
snap = _snapshot(url)
|
|
98
210
|
entry["snapshots"] = (entry["snapshots"] + [snap])[-_SNAP_CAP:]
|
|
211
|
+
_trim_contents(entry)
|
|
99
212
|
data["urls"][url] = entry
|
|
100
213
|
_save(data)
|
|
101
214
|
return {"url": url, "snapshot": snap}
|
|
@@ -127,8 +240,18 @@ def cmd_check(only_url: str | None) -> list[dict]:
|
|
|
127
240
|
"length_delta": snap["length"] - prev.get("length", 0),
|
|
128
241
|
"previous_fetched_at": prev.get("fetched_at"),
|
|
129
242
|
})
|
|
243
|
+
# 有上一帧正文才做噪声判定;旧快照只有指纹,如实标 unknown,
|
|
244
|
+
# 不能拿哈希不同就断言「实质变化」。
|
|
245
|
+
if prev.get("content") and snap.get("content"):
|
|
246
|
+
diff = diff_text(prev["content"], snap["content"])
|
|
247
|
+
report.update(diff)
|
|
248
|
+
# 以正文 diff 为准:哈希只做快速路径,diff 说没变就是没变。
|
|
249
|
+
report["changed"] = diff["change_type"] != "none"
|
|
250
|
+
elif report["changed"]:
|
|
251
|
+
report["change_type"] = "unknown"
|
|
130
252
|
entry = data["urls"][url]
|
|
131
253
|
entry["snapshots"] = (entry["snapshots"] + [snap])[-_SNAP_CAP:]
|
|
254
|
+
_trim_contents(entry)
|
|
132
255
|
entry["last_checked"] = snap["fetched_at"]
|
|
133
256
|
reports.append(report)
|
|
134
257
|
_save(data)
|
package/scripts/local_engines.py
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""本地个性化引擎插件 — 不随公开仓库提交。
|
|
3
|
-
|
|
4
|
-
包含漏洞查询类引擎(OSV.dev + CISA KEV),因启发式杀毒检测
|
|
5
|
-
(HEUR:HackTool/VulnScan)从公开构建器中移出。
|
|
6
|
-
本地文件,不提交 git;删除后对应引擎自动消失,不影响其他功能。
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
import json
|
|
12
|
-
import re
|
|
13
|
-
import time
|
|
14
|
-
import urllib.request
|
|
15
|
-
from typing import Any
|
|
16
|
-
|
|
17
|
-
from engines_base import safe_search, rank_score, http_open, note_failure
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# ── OSV.dev 开源漏洞库(免 key,必须 POST)─────────────────────────────────
|
|
21
|
-
|
|
22
|
-
_OSV_ECOSYSTEM_PREFIX: dict[str, str] = {
|
|
23
|
-
"pypi": "PyPI", "npm": "npm", "go": "Go", "crates": "crates.io",
|
|
24
|
-
"cargo": "crates.io", "maven": "Maven", "nuget": "NuGet",
|
|
25
|
-
"packagist": "Packagist", "composer": "Packagist",
|
|
26
|
-
"rubygems": "RubyGems", "gem": "RubyGems", "hex": "Hex",
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
_OSV_NPM_HINTS: frozenset[str] = frozenset({
|
|
30
|
-
"lodash", "react", "vue", "express", "axios", "next", "webpack",
|
|
31
|
-
"typescript", "eslint", "vite", "jest", "moment", "jquery", "angular",
|
|
32
|
-
"svelte", "nuxt", "rollup", "babel", "prettier", "cheerio", "socket.io",
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
_OSV_GO_HINTS: frozenset[str] = frozenset({
|
|
36
|
-
"golang.org/x/net", "golang.org/x/crypto", "golang.org/x/text",
|
|
37
|
-
"github.com/gin-gonic/gin", "github.com/gorilla/websocket",
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def _osv_resolve_ecosystem(query: str) -> tuple[str, str]:
|
|
42
|
-
q = (query or "").strip()
|
|
43
|
-
if ":" in q:
|
|
44
|
-
head, _, tail = q.partition(":")
|
|
45
|
-
eco = _OSV_ECOSYSTEM_PREFIX.get(head.strip().lower())
|
|
46
|
-
if eco and tail.strip():
|
|
47
|
-
return tail.strip(), eco
|
|
48
|
-
name = q
|
|
49
|
-
if name.startswith("@") or "/" in name:
|
|
50
|
-
if name.startswith("@"):
|
|
51
|
-
return name, "npm"
|
|
52
|
-
if name.startswith(("github.com/", "gitlab.com/", "golang.org/")):
|
|
53
|
-
return name, "Go"
|
|
54
|
-
return name, "npm"
|
|
55
|
-
if name.lower() in _OSV_NPM_HINTS:
|
|
56
|
-
return name, "npm"
|
|
57
|
-
if name.lower() in _OSV_GO_HINTS:
|
|
58
|
-
return name, "Go"
|
|
59
|
-
return name, "PyPI"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _build_osv_engine(spec: dict[str, Any]) -> Any:
|
|
63
|
-
"""OSV.dev 漏洞查询(按包名,POST /v1/query;免 key、免限次)。"""
|
|
64
|
-
timeout = spec.get("timeout", 15)
|
|
65
|
-
|
|
66
|
-
@safe_search
|
|
67
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None,
|
|
68
|
-
**kwargs) -> list[dict[str, Any]]:
|
|
69
|
-
to = _timeout or timeout
|
|
70
|
-
q = (query or "").strip()
|
|
71
|
-
if not q:
|
|
72
|
-
return []
|
|
73
|
-
if re.match(r"^CVE-\d{4}-\d{4,}$", q, re.I):
|
|
74
|
-
return []
|
|
75
|
-
pkg, eco = _osv_resolve_ecosystem(q)
|
|
76
|
-
body = json.dumps({"package": {"name": pkg, "ecosystem": eco}}).encode("utf-8")
|
|
77
|
-
req = urllib.request.Request(
|
|
78
|
-
"https://api.osv.dev/v1/query", data=body,
|
|
79
|
-
headers={"Content-Type": "application/json"})
|
|
80
|
-
eng_name = spec.get("_name") or "osv"
|
|
81
|
-
try:
|
|
82
|
-
with http_open(req, timeout=to, engine=eng_name) as resp:
|
|
83
|
-
data = json.loads(resp.read().decode("utf-8"))
|
|
84
|
-
except Exception as e:
|
|
85
|
-
if isinstance(e, (json.JSONDecodeError, UnicodeDecodeError)):
|
|
86
|
-
note_failure(eng_name, "parse", "json_decode", str(e))
|
|
87
|
-
import logging
|
|
88
|
-
logging.getLogger("unified_search.engines").warning(f"OSV 失败: {e}")
|
|
89
|
-
return []
|
|
90
|
-
results = []
|
|
91
|
-
for i, v in enumerate((data.get("vulns") or [])[:n]):
|
|
92
|
-
vid = str(v.get("id") or "").strip()
|
|
93
|
-
if not vid:
|
|
94
|
-
continue
|
|
95
|
-
summary = str(v.get("summary") or "").strip()
|
|
96
|
-
affected_bits = []
|
|
97
|
-
for aff in (v.get("affected") or [])[:2]:
|
|
98
|
-
if not isinstance(aff, dict):
|
|
99
|
-
continue
|
|
100
|
-
for rng in (aff.get("ranges") or [])[:2]:
|
|
101
|
-
if not isinstance(rng, dict):
|
|
102
|
-
continue
|
|
103
|
-
events = rng.get("events") or []
|
|
104
|
-
introduced = next((e.get("introduced") for e in events
|
|
105
|
-
if isinstance(e, dict) and e.get("introduced")), "")
|
|
106
|
-
fixed = next((e.get("fixed") for e in events
|
|
107
|
-
if isinstance(e, dict) and e.get("fixed")), "")
|
|
108
|
-
if introduced or fixed:
|
|
109
|
-
affected_bits.append(
|
|
110
|
-
f"{introduced or '?'} ≤ 受影响 < {fixed or '未修复'}")
|
|
111
|
-
aliases = [a for a in (v.get("aliases") or []) if a][:3]
|
|
112
|
-
snippet = " · ".join(p for p in (
|
|
113
|
-
summary, f"生态 {eco}",
|
|
114
|
-
affected_bits[0] if affected_bits else "",
|
|
115
|
-
" ".join(aliases),
|
|
116
|
-
) if p)[:300]
|
|
117
|
-
results.append({
|
|
118
|
-
"title": f"{vid} [{eco}] {summary}"[:500] or vid,
|
|
119
|
-
"url": f"https://osv.dev/vulnerability/{vid}",
|
|
120
|
-
"snippet": snippet,
|
|
121
|
-
"source": "osv",
|
|
122
|
-
"published_at": str(v.get("published") or "")[:10],
|
|
123
|
-
"score": rank_score(0.85, i),
|
|
124
|
-
})
|
|
125
|
-
return results
|
|
126
|
-
return _engine
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# ── CISA KEV 已知在野利用漏洞(免 key,全量文件 + 本地过滤)──────────────
|
|
130
|
-
|
|
131
|
-
_KEV_CACHE: dict[str, Any] = {"at": 0.0, "items": None}
|
|
132
|
-
_KEV_TTL_S = 6 * 3600
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def _kev_disk_path():
|
|
136
|
-
try:
|
|
137
|
-
from argo_paths import state_path
|
|
138
|
-
return state_path("cisa_kev_cache.json")
|
|
139
|
-
except Exception:
|
|
140
|
-
return None
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def _kev_load(timeout: float) -> list[dict[str, Any]]:
|
|
144
|
-
now = time.time()
|
|
145
|
-
cached = _KEV_CACHE.get("items")
|
|
146
|
-
if cached and (now - float(_KEV_CACHE.get("at") or 0)) < _KEV_TTL_S:
|
|
147
|
-
return cached
|
|
148
|
-
disk_p = _kev_disk_path()
|
|
149
|
-
if disk_p is not None and disk_p.exists():
|
|
150
|
-
try:
|
|
151
|
-
st = disk_p.stat()
|
|
152
|
-
if (now - st.st_mtime) < _KEV_TTL_S:
|
|
153
|
-
disk_items = json.loads(disk_p.read_text(encoding="utf-8"))
|
|
154
|
-
if isinstance(disk_items, list) and disk_items:
|
|
155
|
-
_KEV_CACHE["items"] = disk_items
|
|
156
|
-
_KEV_CACHE["at"] = st.st_mtime
|
|
157
|
-
return disk_items
|
|
158
|
-
except Exception:
|
|
159
|
-
pass
|
|
160
|
-
req = urllib.request.Request(
|
|
161
|
-
"https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json",
|
|
162
|
-
headers={"User-Agent": "argo-search/1.0 (+cisa-kev)", "Accept": "application/json"})
|
|
163
|
-
try:
|
|
164
|
-
with http_open(req, timeout=timeout, engine="cisa_kev") as resp:
|
|
165
|
-
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
166
|
-
except Exception as e:
|
|
167
|
-
if isinstance(e, (json.JSONDecodeError, UnicodeDecodeError)):
|
|
168
|
-
note_failure("cisa_kev", "parse", "json_decode", str(e))
|
|
169
|
-
import logging
|
|
170
|
-
logging.getLogger("unified_search.engines").warning(f"CISA KEV 失败: {e}")
|
|
171
|
-
return cached or []
|
|
172
|
-
items = data.get("vulnerabilities") or []
|
|
173
|
-
if not isinstance(items, list):
|
|
174
|
-
return cached or []
|
|
175
|
-
_KEV_CACHE["items"] = items
|
|
176
|
-
_KEV_CACHE["at"] = now
|
|
177
|
-
if disk_p is not None and items:
|
|
178
|
-
try:
|
|
179
|
-
from argo_paths import atomic_write_json
|
|
180
|
-
atomic_write_json(disk_p, items)
|
|
181
|
-
except Exception:
|
|
182
|
-
pass
|
|
183
|
-
return items
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
def _build_cisa_kev_engine(spec: dict[str, Any]) -> Any:
|
|
187
|
-
"""CISA KEV 在野利用漏洞目录(本地过滤全量目录)。"""
|
|
188
|
-
timeout = spec.get("timeout", 30)
|
|
189
|
-
|
|
190
|
-
@safe_search
|
|
191
|
-
def _engine(query: str, n: int = 5, _timeout: float | None = None,
|
|
192
|
-
**kwargs) -> list[dict[str, Any]]:
|
|
193
|
-
to = _timeout or timeout
|
|
194
|
-
q = (query or "").strip()
|
|
195
|
-
if not q:
|
|
196
|
-
return []
|
|
197
|
-
items = _kev_load(to)
|
|
198
|
-
if not items:
|
|
199
|
-
return []
|
|
200
|
-
cve_q = q.upper() if re.match(r"^CVE-\d{4}-\d{4,}$", q.strip(), re.I) else ""
|
|
201
|
-
matched = []
|
|
202
|
-
for v in items:
|
|
203
|
-
if not isinstance(v, dict):
|
|
204
|
-
continue
|
|
205
|
-
if cve_q:
|
|
206
|
-
if str(v.get("cveID") or "").strip().upper() == cve_q:
|
|
207
|
-
matched.append(v)
|
|
208
|
-
continue
|
|
209
|
-
terms = [t for t in re.split(r"[\s,]+", q.lower()) if t]
|
|
210
|
-
hay = " ".join(str(v.get(k) or "") for k in (
|
|
211
|
-
"cveID", "vendorProject", "product", "vulnerabilityName",
|
|
212
|
-
"shortDescription", "requiredAction", "cwes")).lower()
|
|
213
|
-
if all(t in hay for t in terms):
|
|
214
|
-
matched.append(v)
|
|
215
|
-
matched.sort(key=lambda x: str(x.get("dateAdded") or ""), reverse=True)
|
|
216
|
-
results = []
|
|
217
|
-
for i, v in enumerate(matched[:n]):
|
|
218
|
-
cve = str(v.get("cveID") or "").strip()
|
|
219
|
-
if not cve:
|
|
220
|
-
continue
|
|
221
|
-
vendor = str(v.get("vendorProject") or "").strip()
|
|
222
|
-
product = str(v.get("product") or "").strip()
|
|
223
|
-
name = str(v.get("vulnerabilityName") or "").strip()
|
|
224
|
-
desc = str(v.get("shortDescription") or "").strip()
|
|
225
|
-
due = str(v.get("dueDate") or "").strip()
|
|
226
|
-
ransom = str(v.get("knownRansomwareCampaignUse") or "").strip()
|
|
227
|
-
bits = [b for b in (
|
|
228
|
-
f"{vendor} {product}".strip(),
|
|
229
|
-
f"修复期限 {due}" if due else "",
|
|
230
|
-
"已知勒索软件利用" if ransom.lower() == "known" else "",
|
|
231
|
-
desc,
|
|
232
|
-
) if b]
|
|
233
|
-
results.append({
|
|
234
|
-
"title": f"{cve} — {name or product or vendor}"[:500],
|
|
235
|
-
"url": "https://www.cisa.gov/known-exploited-vulnerabilities-catalog",
|
|
236
|
-
"snippet": " · ".join(bits)[:300],
|
|
237
|
-
"source": "cisa_kev",
|
|
238
|
-
"published_at": str(v.get("dateAdded") or "")[:10],
|
|
239
|
-
"score": rank_score(0.9, i),
|
|
240
|
-
})
|
|
241
|
-
return results
|
|
242
|
-
return _engine
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
# ── 引擎声明(本地个性化配置,不提交公开仓库)────────────────────────────────
|
|
246
|
-
#
|
|
247
|
-
# 字段与原 engines/specs/osv.yaml、engines/specs/cisa_kev.yaml 逐项对齐——
|
|
248
|
-
# 那两个声明已加 _ 前缀改名停用(公开仓每次启动刷两行「未知引擎类型」warning),
|
|
249
|
-
# 元数据随之并入本文件,本机路由行为(explicit_only / family / priority / qps
|
|
250
|
-
# 等)与改名前完全一致。
|
|
251
|
-
|
|
252
|
-
_LOCAL_ENGINE_SPECS: dict[str, dict[str, Any]] = {
|
|
253
|
-
"osv": {
|
|
254
|
-
"type": "osv",
|
|
255
|
-
"enabled": True,
|
|
256
|
-
"explicit_only": True,
|
|
257
|
-
"cost_tier": "free",
|
|
258
|
-
"label": "OSV 开源漏洞库",
|
|
259
|
-
"family": "security",
|
|
260
|
-
"priority": 44,
|
|
261
|
-
"qps": 2,
|
|
262
|
-
"period": "second",
|
|
263
|
-
"cost_per_call": 0.0,
|
|
264
|
-
"cost_unit": "free",
|
|
265
|
-
"method": "POST",
|
|
266
|
-
"url": "https://api.osv.dev/v1/query",
|
|
267
|
-
"timeout": 15,
|
|
268
|
-
"canary_query": "requests",
|
|
269
|
-
"desc": "OSV.dev 开源软件漏洞库(按包查已知漏洞与影响版本区间,免 key;生态 PyPI/npm/Go/crates 等)",
|
|
270
|
-
"description": "OSV.dev 开源漏洞查询(按包名)",
|
|
271
|
-
"coverage": ["security", "package"],
|
|
272
|
-
"recommended": False,
|
|
273
|
-
"latency_ms": 1500,
|
|
274
|
-
"headers": {"Content-Type": "application/json"},
|
|
275
|
-
"quality_queries": [
|
|
276
|
-
{"query": "requests"},
|
|
277
|
-
{"query": "lodash"},
|
|
278
|
-
{"query": "log4j-core"},
|
|
279
|
-
],
|
|
280
|
-
},
|
|
281
|
-
"cisa_kev": {
|
|
282
|
-
"type": "cisa_kev",
|
|
283
|
-
"enabled": True,
|
|
284
|
-
"explicit_only": True,
|
|
285
|
-
"cost_tier": "free",
|
|
286
|
-
"label": "CISA KEV 在野利用漏洞",
|
|
287
|
-
"family": "security",
|
|
288
|
-
"priority": 47,
|
|
289
|
-
"qps": 1,
|
|
290
|
-
"period": "second",
|
|
291
|
-
"cost_per_call": 0.0,
|
|
292
|
-
"cost_unit": "free",
|
|
293
|
-
"timeout": 30,
|
|
294
|
-
"canary_query": "chrome",
|
|
295
|
-
"desc": "CISA 已知被在野利用漏洞目录(官方确认已被实际攻击利用的 CVE;全量 1.35MB 本地过滤)",
|
|
296
|
-
"description": "CISA KEV 在野利用漏洞目录",
|
|
297
|
-
"coverage": ["security"],
|
|
298
|
-
"recommended": False,
|
|
299
|
-
"latency_ms": 4000,
|
|
300
|
-
"quality_queries": [
|
|
301
|
-
{"query": "chrome"},
|
|
302
|
-
{"query": "CVE-2021-44228"},
|
|
303
|
-
],
|
|
304
|
-
},
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
def register(builders: dict[str, Any], engine_specs: dict[str, Any]) -> None:
|
|
309
|
-
"""将本地引擎注册到全局 builders 和 engine_specs 中。
|
|
310
|
-
|
|
311
|
-
在 engines.py 的 _load_registry() 中、构建 registry 之前调用。
|
|
312
|
-
文件不存在时 engines.py 跳过 import,不影响公开仓库。
|
|
313
|
-
外置 spec(engines/specs/*.yaml)已有的字段保留,不抹除 explicit_only/family 等元数据。
|
|
314
|
-
"""
|
|
315
|
-
builders["osv"] = _build_osv_engine
|
|
316
|
-
builders["cisa_kev"] = _build_cisa_kev_engine
|
|
317
|
-
for name, spec in _LOCAL_ENGINE_SPECS.items():
|
|
318
|
-
base = dict(engine_specs.get(name) or {})
|
|
319
|
-
for k, v in spec.items():
|
|
320
|
-
base.setdefault(k, v)
|
|
321
|
-
engine_specs[name] = base
|