argo-search 2.9.9 → 2.10.1

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.
Files changed (104) hide show
  1. package/README.en.md +39 -22
  2. package/README.es.md +39 -22
  3. package/README.ja.md +38 -21
  4. package/README.ko.md +38 -21
  5. package/README.md +41 -22
  6. package/SKILL.md +13 -12
  7. package/backends/domain_profiles.json +76 -0
  8. package/backends/engine_registry.yaml +163 -7
  9. package/backends/quota_profiles.json +122 -2
  10. package/backends/source_types_cn.json +9 -0
  11. package/bin/argo +22 -1
  12. package/bin/argo.js +3 -3
  13. package/config.yaml +150 -30
  14. package/docs/ARGO_INTRO.md +4 -4
  15. package/docs/ENGINE_CATALOG.md +68 -48
  16. package/docs/MCP_SETUP.md +1 -1
  17. package/docs/RELEASE_NOTES_v2.10.0.md +85 -0
  18. package/docs/RELEASE_NOTES_v2.10.1.md +57 -0
  19. package/docs/RELEASE_NOTES_v2.9.8.md +1 -1
  20. package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +9 -9
  21. package/engines/_template_http.yaml +2 -0
  22. package/engines/specs/clawhub.yaml +16 -15
  23. package/engines/specs/deepseek1024.yaml +46 -0
  24. package/engines/specs/dsh_hub.yaml +44 -0
  25. package/engines/specs/dshopen.yaml +32 -0
  26. package/engines/specs/explainx.yaml +32 -0
  27. package/engines/specs/gbfs_nyc.yaml +6 -1
  28. package/engines/specs/metaso_doc.yaml +49 -0
  29. package/engines/specs/metaso_image.yaml +65 -0
  30. package/engines/specs/metaso_podcast.yaml +60 -0
  31. package/engines/specs/metaso_scholar.yaml +57 -0
  32. package/engines/specs/metaso_video.yaml +62 -0
  33. package/engines/specs/ncpssd.yaml +44 -0
  34. package/engines/specs/sciverse.yaml +73 -0
  35. package/engines/specs/skills_sh.yaml +32 -0
  36. package/engines/specs/skillsmp.yaml +18 -16
  37. package/package.json +4 -2
  38. package/packages/dsh-plugin/README.md +3 -2
  39. package/packages/dsh-plugin/package.json +1 -1
  40. package/packages/dsh-plugin/test/size-gate.test.js +113 -0
  41. package/scripts/adaptive.py +41 -14
  42. package/scripts/article.py +6 -1
  43. package/scripts/article_meta.py +151 -2
  44. package/scripts/bench_general_pool.py +145 -0
  45. package/scripts/candidate_envelope.py +45 -4
  46. package/scripts/charset_decode.py +127 -0
  47. package/scripts/ci_drift_gate.py +47 -24
  48. package/scripts/crawl.py +240 -74
  49. package/scripts/crawl_frontier.py +217 -0
  50. package/scripts/crawl_policy.py +174 -0
  51. package/scripts/engine_dispatch.py +23 -18
  52. package/scripts/engine_failure.py +15 -0
  53. package/scripts/engine_status.py +12 -5
  54. package/scripts/engine_validate.py +8 -0
  55. package/scripts/engines.py +15 -0
  56. package/scripts/engines_base.py +43 -15
  57. package/scripts/engines_builders.py +14 -0
  58. package/scripts/engines_builders_data.py +10 -3
  59. package/scripts/engines_builders_dsh.py +330 -0
  60. package/scripts/engines_builders_skill.py +314 -0
  61. package/scripts/evidence.py +26 -5
  62. package/scripts/fetch_v3.py +37 -5
  63. package/scripts/gen_engine_catalog.py +218 -2
  64. package/scripts/general_pool.py +162 -0
  65. package/scripts/http_client.py +38 -42
  66. package/scripts/image_ops.py +4 -0
  67. package/scripts/install.ps1 +47 -19
  68. package/scripts/install.sh +45 -20
  69. package/scripts/local_seek.py +53 -11
  70. package/scripts/matrix_search_eval.py +17 -1
  71. package/scripts/mcp_transport.py +1 -1
  72. package/scripts/ncpssd_bridge.py +123 -0
  73. package/scripts/paid_policy.py +109 -13
  74. package/scripts/pre-commit +19 -4
  75. package/scripts/query_signals.py +156 -3
  76. package/scripts/redskill/redskill_engine.py +29 -2
  77. package/scripts/release.py +398 -0
  78. package/scripts/release_check.py +209 -0
  79. package/scripts/retry_policy.py +22 -1
  80. package/scripts/robots_guard.py +26 -0
  81. package/scripts/route.py +11 -8
  82. package/scripts/route_cache.py +6 -0
  83. package/scripts/route_combo.py +37 -59
  84. package/scripts/route_domains.py +22 -3
  85. package/scripts/route_policy.py +6 -0
  86. package/scripts/search.py +13 -3
  87. package/scripts/search_cli.py +49 -0
  88. package/scripts/search_entry.py +9 -0
  89. package/scripts/search_output.py +43 -0
  90. package/scripts/search_pipeline.py +43 -3
  91. package/scripts/search_rank.py +4 -1
  92. package/scripts/serp_guard.py +11 -0
  93. package/scripts/social_engines/bilibili_engine.py +163 -26
  94. package/scripts/social_engines/reddit_engine.py +52 -51
  95. package/scripts/source_selection.py +302 -0
  96. package/scripts/url_canon.py +2 -1
  97. package/scripts/video_fetch.py +303 -0
  98. package/scripts/video_meta.py +225 -0
  99. package/scripts/video_route.py +65 -0
  100. package/scripts/watch.py +123 -0
  101. package/sub-skills/local-seek/scripts/seek.py +19 -4
  102. package/engines/specs/_cisa_kev.yaml +0 -54
  103. package/engines/specs/_osv.yaml +0 -63
  104. package/scripts/local_engines.py +0 -321
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env python3
2
+ """video_meta.py — 视频来源识别与时长归一(零依赖纯函数)。
3
+
4
+ 搜索链路里「视频」此前只体现为平台名:B 站引擎抓到了时长/播放量,但
5
+ CLI 解析层不透传 social_meta,envelope 又把所有带 social_meta 的结果写成
6
+ social_post。本模块只做三件可单独测试的事:
7
+
8
+ - URL → 平台/是否视频页(区分 B 站 /video/ 与 /read/ 图文);
9
+ - 各种时长写法 → 秒(B 站 "8:27"、API 数字、文本 "5分钟");
10
+ - 结果集 → 视频过滤/时长过滤(供 --video 与 --min-duration 使用)。
11
+
12
+ 判据刻意按「页面是不是视频」而不是「域名是不是视频站」:B 站专栏与动态
13
+ (/read/、/opus/)不是视频,抖音用户主页也不是单条视频。按域名一刀切会
14
+ 把图文当视频放进来,--video 的结果就不再可信。
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import re
20
+ from typing import Any
21
+ from urllib.parse import urlparse
22
+
23
+
24
+ # 域名 → 平台名。匹配按后缀(www./m. 等子域自动命中),路径规则在
25
+ # video_platform 里逐平台收紧。
26
+ _VIDEO_HOSTS: dict[str, str] = {
27
+ "youtube.com": "youtube",
28
+ "youtu.be": "youtube",
29
+ "bilibili.com": "bilibili",
30
+ "b23.tv": "bilibili",
31
+ "douyin.com": "douyin",
32
+ "iesdouyin.com": "douyin",
33
+ "kuaishou.com": "kuaishou",
34
+ "vimeo.com": "vimeo",
35
+ "v.qq.com": "tencent_video",
36
+ "youku.com": "youku",
37
+ "iqiyi.com": "iqiyi",
38
+ "ixigua.com": "xigua",
39
+ "xigua.com": "xigua",
40
+ "ted.com": "ted",
41
+ }
42
+
43
+ # envelope 里算「视频」的平台名(与 _platform_of 的返回值对齐)。
44
+ VIDEO_PLATFORMS = frozenset({
45
+ "youtube", "bilibili", "douyin", "kuaishou", "vimeo",
46
+ "tencent_video", "youku", "iqiyi", "xigua", "ted",
47
+ })
48
+
49
+
50
+ def _host_of(url: str) -> str:
51
+ try:
52
+ host = (urlparse(url).netloc or "").lower().split("@")[-1]
53
+ except (ValueError, AttributeError):
54
+ return ""
55
+ # 去端口(IPv6 不在视频站范围,按常见 host:port 处理即可)
56
+ return host.split(":")[0]
57
+
58
+
59
+ def video_platform(url: str) -> str | None:
60
+ """URL → 视频平台名;不是单条视频页返回 None。
61
+
62
+ 路径判据比域名严格,原因见模块头:B 站 /read/ 与抖音用户主页不是视频。
63
+ """
64
+ if not url:
65
+ return None
66
+ host = _host_of(url)
67
+ if not host:
68
+ return None
69
+ platform = None
70
+ for domain, name in _VIDEO_HOSTS.items():
71
+ if host == domain or host.endswith("." + domain):
72
+ platform = name
73
+ break
74
+ if platform is None:
75
+ return None
76
+
77
+ try:
78
+ path = urlparse(url).path or ""
79
+ except (ValueError, AttributeError):
80
+ path = ""
81
+
82
+ if platform == "bilibili":
83
+ # 短链 b23.tv 任何路径都视为视频;主站只认 /video/ 与 /bangumi/
84
+ if host == "b23.tv" or host.endswith(".b23.tv"):
85
+ return platform
86
+ if path.startswith("/video/") or path.startswith("/bangumi/"):
87
+ return platform
88
+ return None
89
+ if platform == "youtube":
90
+ if host == "youtu.be" or host.endswith(".youtu.be"):
91
+ return platform
92
+ if any(path.startswith(p) for p in
93
+ ("/watch", "/shorts/", "/embed/", "/live/")):
94
+ return platform
95
+ return None
96
+ if platform == "douyin":
97
+ if host.startswith("v.") or host.startswith("v-"):
98
+ return platform
99
+ return platform if "/video/" in path else None
100
+ if platform == "kuaishou":
101
+ return platform if ("/short-video/" in path or "/fw/photo/" in path) else None
102
+ if platform == "vimeo":
103
+ return platform if re.search(r"/\d+", path) else None
104
+ if platform == "tencent_video":
105
+ return platform if ("/x/page/" in path or "/x/cover/" in path) else None
106
+ if platform == "youku":
107
+ return platform if "/v_show/" in path else None
108
+ if platform == "iqiyi":
109
+ return platform if "/v_" in path else None
110
+ if platform == "xigua":
111
+ return platform if "/video/" in path else None
112
+ if platform == "ted":
113
+ return platform if "/talks/" in path else None
114
+ return platform
115
+
116
+
117
+ def is_video_url(url: str) -> bool:
118
+ """是否单条视频页(视频平台 + 视频路径)。"""
119
+ return video_platform(url) is not None
120
+
121
+
122
+ def parse_duration_seconds(value: Any) -> int | None:
123
+ """把视频时长归一成秒。
124
+
125
+ 支持:整数/浮点秒、"8:27"、"1:02:03"、"5分钟"、"90秒"、"1小时2分"。
126
+ 解析不了返回 None(而不是 0):0 会被下游当成「零时长视频」误过滤。
127
+ """
128
+ if value is None or isinstance(value, bool):
129
+ return None
130
+ if isinstance(value, (int, float)):
131
+ return int(value) if value >= 0 else None
132
+ text = str(value).strip()
133
+ if not text:
134
+ return None
135
+
136
+ # 纯数字秒
137
+ if re.fullmatch(r"\d+(?:\.\d+)?", text):
138
+ return int(float(text))
139
+
140
+ # mm:ss / hh:mm:ss(B 站搜索结果里 "1:0" 表示 1 分 0 秒)
141
+ if re.fullmatch(r"\d+(?::\d+){1,2}", text):
142
+ total = 0
143
+ for part in text.split(":"):
144
+ total = total * 60 + int(part)
145
+ return total
146
+
147
+ # 中文时长("5分钟"、"1小时2分"、"90秒")
148
+ m = re.search(
149
+ r"(?:(\d+)\s*(?:小时|时))?\s*(?:(\d+)\s*(?:分钟|分))?\s*(?:(\d+)\s*秒)?",
150
+ text,
151
+ )
152
+ if m and any(m.groups()):
153
+ hours = int(m.group(1) or 0)
154
+ minutes = int(m.group(2) or 0)
155
+ seconds = int(m.group(3) or 0)
156
+ return hours * 3600 + minutes * 60 + seconds
157
+ return None
158
+
159
+
160
+ def result_duration_seconds(item: dict[str, Any]) -> int | None:
161
+ """从一条搜索结果里取时长(social_meta 优先,其次顶层与 metrics)。"""
162
+ if not isinstance(item, dict):
163
+ return None
164
+ for container in (item.get("social_meta"), item, item.get("metrics")):
165
+ if not isinstance(container, dict):
166
+ continue
167
+ for key in ("duration_seconds", "duration"):
168
+ seconds = parse_duration_seconds(container.get(key))
169
+ if seconds is not None:
170
+ return seconds
171
+ return None
172
+
173
+
174
+ def is_video_result(item: dict[str, Any]) -> bool:
175
+ """一条结果是否是视频(引擎声明的 content_type 优先,其次 URL 判据)。"""
176
+ if not isinstance(item, dict):
177
+ return False
178
+ social = item.get("social_meta")
179
+ if isinstance(social, dict) and social.get("content_type") == "video":
180
+ return True
181
+ return is_video_url(item.get("url") or "")
182
+
183
+
184
+ def filter_video_results(
185
+ results: list[dict[str, Any]],
186
+ ) -> tuple[list[dict[str, Any]], int]:
187
+ """只保留视频结果,返回 (保留, 剔除数)。"""
188
+ kept: list[dict[str, Any]] = []
189
+ dropped = 0
190
+ for item in results:
191
+ if is_video_result(item):
192
+ kept.append(item)
193
+ else:
194
+ dropped += 1
195
+ return kept, dropped
196
+
197
+
198
+ def filter_duration(
199
+ results: list[dict[str, Any]],
200
+ min_seconds: int | None = None,
201
+ max_seconds: int | None = None,
202
+ ) -> tuple[list[dict[str, Any]], int, int]:
203
+ """按时长过滤,返回 (保留, 剔除数, 时长未知且保留数)。
204
+
205
+ 时长未知的条目保留:除 B 站外的引擎大多没有时长字段,硬删会把
206
+ anysearch 的 YouTube 结果全部清空。调用方据第三个数判断这次过滤的
207
+ 实际覆盖率,不要把它当成「已严格过滤」。
208
+ """
209
+ kept: list[dict[str, Any]] = []
210
+ filtered = 0
211
+ unknown = 0
212
+ for item in results:
213
+ seconds = result_duration_seconds(item)
214
+ if seconds is None:
215
+ unknown += 1
216
+ kept.append(item)
217
+ continue
218
+ if min_seconds is not None and seconds < min_seconds:
219
+ filtered += 1
220
+ continue
221
+ if max_seconds is not None and seconds > max_seconds:
222
+ filtered += 1
223
+ continue
224
+ kept.append(item)
225
+ return kept, filtered, unknown
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python3
2
+ """video_route.py — `--video` 的强制路由决策。
3
+
4
+ 为什么单独成模块:route.py 已登记模块体积上限,而这段逻辑只服务一个显式
5
+ 开关,不需要挤进主路由。决策形状必须与 route_query 的返回一致(prepare
6
+ 直接读 engines_combo / parallel / engine_request),否则 --video 会在
7
+ 执行层退化成空 combo。
8
+
9
+ 与自然语言路由的分工:
10
+ - 查询里出现「视频教程 / B站 / 视频(结尾)」等显式意图 → config 的 video
11
+ 域自然命中,不需要本模块;
12
+ - 用户敲 `--video` → 不看查询词,直接锁定视频 combo,并由 pipeline 的
13
+ video_only 过滤器保证结果里没有网页。
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from typing import Any
19
+
20
+ # config 缺 video 域时的兜底:B 站负责中文视频,parallel_free 负责海外/YouTube
21
+ # 视频(免 Key 直连),anysearch 补充国内综合索引。
22
+ _FALLBACK = ("bilibili", "parallel_free", "anysearch")
23
+
24
+
25
+ def _video_domain() -> dict[str, Any]:
26
+ try:
27
+ from config import get_domains
28
+ for domain in get_domains() or []:
29
+ if isinstance(domain, dict) and domain.get("name") == "video":
30
+ return domain
31
+ except Exception:
32
+ pass
33
+ return {}
34
+
35
+
36
+ def video_decision(min_duration: int | None = None,
37
+ max_duration: int | None = None) -> dict[str, Any]:
38
+ """构造 `--video` 的路由决策(形状对齐 route_query 的返回值)。"""
39
+ domain = _video_domain()
40
+ combo = [str(e) for e in (domain.get("engines_combo") or _FALLBACK) if e]
41
+ try:
42
+ from config import get_engines
43
+ specs = get_engines() or {}
44
+ combo = [e for e in combo if (specs.get(e) or {}).get("enabled", True)]
45
+ except Exception:
46
+ pass
47
+ combo = combo or list(_FALLBACK)
48
+ primary = domain.get("primary")
49
+ if primary not in combo:
50
+ primary = combo[0]
51
+ return {
52
+ "engine": primary,
53
+ "engines": list(combo),
54
+ "engines_combo": list(combo),
55
+ "domain": "video",
56
+ "parallel": True,
57
+ "no_early_stop": True,
58
+ "reason": "用户指定 --video:视频源优先(B站 + anysearch),只保留视频结果",
59
+ "confidence": 1.0,
60
+ # 请求身份进缓存键:--video 的结果不能与同 query 的 auto 结果互串。
61
+ "engine_request": "--video",
62
+ "video_only": True,
63
+ "min_duration": min_duration,
64
+ "max_duration": max_duration,
65
+ }
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)
@@ -1172,15 +1172,30 @@ def git_blame(path, line, timeout=None):
1172
1172
 
1173
1173
  def _run_grep_fallback(args, patterns, fixed, path, excludes, exts, max_results,
1174
1174
  timeout=None, since_ts=None, until_ts=None):
1175
- """rg 缺失时的 grep 保底(目录内/全盘共用)。
1175
+ """rg 缺失时的 FTS5 / grep 保底(目录内/全盘共用)。
1176
1176
 
1177
- 返回 (results, err, mode);rg 与 grep 都不可用时 results=None 且 err
1178
- 说明缺什么——调用方必须把「工具缺失」与「未找到匹配」区分开。
1177
+ 返回 (results, err, mode);FTS5 索引命中时优先走标准库 sqlite3(免外部工具),
1178
+ rg 与 grep 都不可用且无 FTS5 索引时 results=None 且 err 说明缺什么——
1179
+ 调用方必须把「工具缺失」与「未找到匹配」区分开。
1179
1180
  """
1181
+ dots = getattr(args, "dot", False)
1182
+ if not exts and not getattr(args, "exclude", None) and not args.count and args.context == 0:
1183
+ try:
1184
+ import seek_fts
1185
+ except ImportError:
1186
+ seek_fts = None
1187
+ if seek_fts is not None and seek_fts.query_suitable(args.query):
1188
+ rows = seek_fts.content_candidates(
1189
+ args.query, path, dots=dots,
1190
+ since_ts=since_ts, until_ts=until_ts)
1191
+ if rows is not None:
1192
+ return _finish_content(
1193
+ iter(rows), args.query, args.context, args.count,
1194
+ fixed, path, max_results, not args.include_noise
1195
+ ), None, "fts"
1180
1196
  grep_exe = resolve_grep()
1181
1197
  if not grep_exe:
1182
1198
  return None, "本机无 rg 与 grep 可用,请安装 ripgrep", ""
1183
- dots = getattr(args, "dot", False)
1184
1199
  mode = "fast"
1185
1200
  if not args.exact and len(patterns) > 1:
1186
1201
  results, err = grep_search(grep_exe, [args.query], path, excludes, exts,
@@ -1,54 +0,0 @@
1
- # 【已停用·留档】本文件原为 engines/specs/cisa_kev.yaml。7ca2f22 移除
2
- # OSV/CISA KEV 引擎代码(规避启发式杀毒误报)后,声明文件成了孤儿:加载器照常
3
- # 读入,但 _BUILDERS 里没有对应 builder,每次启动固定刷一行「未知引擎类型」
4
- # warning(对把 stderr 当错误日志采集的调用方是误报级噪音)。故加 _ 前缀改名,
5
- # _load_external_engine_specs 跳过 _ 前缀文件,公开仓恢复干净启动。
6
- # 本机仍可用:builder 由 scripts/local_engines.py(gitignored,不随公开仓提交)
7
- # 注册,引擎元数据已完整并入该文件的 _LOCAL_ENGINE_SPECS。
8
- # 公开仓若重新接回:拷回 engines/specs/ 并去掉下划线,同时提供 builder。
9
- # ─── 以下为原始声明,未改动 ───
10
-
11
- # CISA KEV — 已知被在野利用漏洞目录(免 key、免注册)
12
- #
13
- # 补的盲区:**「这个漏洞是不是正在被真实攻击利用」**。这是修复优先级里权重最高
14
- # 的一档信息——NVD 给 CVSS 分数(理论严重度),OSV 给影响版本,而 KEV 给的是
15
- # 官方确认「已被实际利用」的名单。三者互补,构成安全域的完整判断链。
16
- #
17
- # 数据形态(实测 2026-09-16):**单个 JSON 全量文件**,约 1.35MB、1710 条。
18
- # https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json
19
- # {"catalogVersion":"2026.09.14","vulnerabilities":[{cveID, vendorProject,
20
- # product, vulnerabilityName, dateAdded, shortDescription, dueDate, ...}]}
21
- # 上游**不支持查询参数**(实测 ?q= 无效,仍返回全量),因此必须本地过滤:
22
- # 按查询词匹配 cveID / vendor / product / name / description。
23
- #
24
- # 约束与取舍:每次查询下载 1.35MB。为避免把带宽与延迟花在无关查询上,
25
- # 本引擎声明 explicit_only + 低 priority,只在用户明确要「在野利用/KEV」类
26
- # 信息时被选中,不参与通用路由。
27
- #
28
- # 验证:
29
- # python3 scripts/engine_validate.py --engine cisa_kev --stage health --admit
30
- # python3 scripts/search.py "chrome" --engine cisa_kev --json
31
-
32
- engine_id: cisa_kev
33
- type: cisa_kev
34
- enabled: true
35
- explicit_only: true
36
- cost_tier: free
37
- label: CISA KEV 在野利用漏洞
38
- family: security
39
- priority: 47
40
- qps: 1
41
- period: second
42
- cost_per_call: 0.0
43
- cost_unit: free
44
- timeout: 30
45
- canary_query: "chrome"
46
- coverage:
47
- - security
48
- desc: "CISA 已知被在野利用漏洞目录(官方确认已被实际攻击利用的 CVE;全量 1.35MB 本地过滤)"
49
- recommended: false
50
- latency_ms: 4000
51
-
52
- quality_queries:
53
- - query: "chrome"
54
- - query: "CVE-2021-44228"
@@ -1,63 +0,0 @@
1
- # 【已停用·留档】本文件原为 engines/specs/osv.yaml。7ca2f22 移除
2
- # OSV/CISA KEV 引擎代码(规避启发式杀毒误报)后,声明文件成了孤儿:加载器照常
3
- # 读入,但 _BUILDERS 里没有对应 builder,每次启动固定刷一行「未知引擎类型」
4
- # warning(对把 stderr 当错误日志采集的调用方是误报级噪音)。故加 _ 前缀改名,
5
- # _load_external_engine_specs 跳过 _ 前缀文件,公开仓恢复干净启动。
6
- # 本机仍可用:builder 由 scripts/local_engines.py(gitignored,不随公开仓提交)
7
- # 注册,引擎元数据已完整并入该文件的 _LOCAL_ENGINE_SPECS。
8
- # 公开仓若重新接回:拷回 engines/specs/ 并去掉下划线,同时提供 builder。
9
- # ─── 以下为原始声明,未改动 ───
10
-
11
- # OSV.dev — 开源软件漏洞库(免 key、免注册,跨生态聚合)
12
- #
13
- # 补的盲区:**「这个包有没有已知漏洞」**。这是结构化事实而非网页检索问题——
14
- # 搜「xxx package 有漏洞吗」只能得到博客与二手解读,而 OSV 直出
15
- # 包 → 漏洞 → 影响版本区间,标准化且可交叉验证。
16
- #
17
- # 与已有源的分工(互补而非重复):
18
- # nvd —— CVE 编号/CVSS 严重度(NIST 官方口径,按关键词查)
19
- # osv —— **按包与生态**查询,聚合 GHSA / PyPA / Go / RustSec 等上游
20
- # GitHub Advisory —— 是 OSV 的上游之一,且未认证实测 403 rate limit,
21
- # 故不单独接入(OSV 已聚合其数据)
22
- #
23
- # 端点语义(实测 2026-09-16):只能 POST,GET 返回 405。
24
- # POST /v1/query {"package":{"name":"requests","ecosystem":"PyPI"}}
25
- # → vulns[](实测 16 条)
26
- # 生态取值:PyPI / npm / Go / crates.io / Maven / NuGet / Packagist / RubyGems。
27
- # 查询词传裸包名;带生态前缀(如 pypi:requests)时由 osv 生态映射处理。
28
- #
29
- # 验证:
30
- # python3 scripts/engine_validate.py --engine osv --stage health --admit
31
- # python3 scripts/search.py "requests" --engine osv --json
32
-
33
- engine_id: osv
34
- type: osv
35
- enabled: true
36
- explicit_only: true
37
- cost_tier: free
38
- label: OSV 开源漏洞库
39
- family: security
40
- priority: 44
41
- qps: 2
42
- period: second
43
- cost_per_call: 0.0
44
- cost_unit: free
45
- method: POST
46
- url: https://api.osv.dev/v1/query
47
- timeout: 15
48
- canary_query: "requests"
49
- desc: "OSV.dev 开源漏洞库(按包查已知漏洞与影响版本区间,免 key;生态 PyPI/npm/Go/crates 等)"
50
- coverage: [security, package]
51
- recommended: false
52
- latency_ms: 1500
53
-
54
- headers:
55
- Content-Type: application/json
56
-
57
- # body 由 builder 填充:生态需按包名推断(PyPI vs npm 同名包不同),
58
- # 声明式 body 无法表达该推断,见 scripts/engines_builders_tech.py 的 osv builder。
59
-
60
- quality_queries:
61
- - query: "requests"
62
- - query: "lodash"
63
- - query: "log4j-core"