argo-search 2.15.0 → 2.17.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/AGENTS.md +3 -1
- package/README.es.md +32 -5
- package/README.ja.md +32 -5
- package/README.ko.md +32 -5
- package/README.md +73 -19
- package/README.zh.md +73 -19
- package/SKILL.md +7 -7
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +3 -3
- package/assets/readme/hero.template.svg +121 -0
- package/assets/readme/proof-routes.svg +17 -16
- package/backends/domain_profiles.json +222 -24
- package/backends/engine_registry.yaml +26 -2
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +23 -3
- package/bin/argo +3 -0
- package/config.yaml +16 -0
- package/docs/CHANGELOG.md +31 -0
- package/docs/COMMIT_STANDARD.md +10 -0
- package/docs/ENGINE_CATALOG.md +40 -37
- package/docs/MCP_SETUP.md +9 -0
- package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
- package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/archive_org.yaml +1 -1
- package/engines/specs/carbon_intensity.yaml +1 -1
- package/engines/specs/crates.yaml +1 -1
- package/engines/specs/crossref.yaml +6 -2
- package/engines/specs/crt_sh.yaml +1 -1
- package/engines/specs/dblp.yaml +1 -1
- package/engines/specs/devto.yaml +1 -1
- package/engines/specs/docker_hub.yaml +1 -1
- package/engines/specs/europepmc.yaml +1 -1
- package/engines/specs/fxtwitter.yaml +1 -1
- package/engines/specs/gbfs_nyc.yaml +1 -1
- package/engines/specs/gleif.yaml +1 -1
- package/engines/specs/gov_regulations.yaml +1 -1
- package/engines/specs/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_datasets.yaml +1 -1
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/huggingface.yaml +1 -1
- package/engines/specs/keenable.yaml +7 -1
- package/engines/specs/linux_do.yaml +63 -0
- package/engines/specs/local_crossref.yaml +3 -1
- package/engines/specs/local_github.yaml +1 -1
- package/engines/specs/local_npm.yaml +6 -0
- package/engines/specs/local_openstreetmap.yaml +1 -1
- package/engines/specs/maven.yaml +1 -1
- package/engines/specs/mdn.yaml +1 -1
- package/engines/specs/musicbrainz.yaml +1 -1
- package/engines/specs/nasa_images.yaml +1 -1
- package/engines/specs/nhtsa_vpic.yaml +6 -3
- package/engines/specs/npm.yaml +1 -1
- package/engines/specs/nuget.yaml +1 -1
- package/engines/specs/nvd.yaml +1 -1
- package/engines/specs/openalex.yaml +13 -4
- package/engines/specs/openreview.yaml +1 -1
- package/engines/specs/polymarket.yaml +1 -1
- package/engines/specs/sec_edgar.yaml +1 -1
- package/engines/specs/steam.yaml +1 -1
- package/engines/specs/vam.yaml +1 -1
- package/engines/specs/wikidata.yaml +1 -1
- package/engines/specs/wikipedia.yaml +1 -1
- package/engines/specs/zhihu_hot_app.yaml +1 -1
- package/package.json +3 -1
- package/packages/dsh-plugin/README.md +5 -2
- package/packages/dsh-plugin/cordis.patch.yml +4 -1
- package/packages/dsh-plugin/dsh/client.js +69 -74
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +115 -21
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +50 -7
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +895 -0
- package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
- package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +460 -0
- package/packages/dsh-plugin/dsh/workbench.js +703 -0
- package/packages/dsh-plugin/icon.svg +23 -0
- package/packages/dsh-plugin/package.json +6 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
- package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
- package/packages/dsh-plugin/test/client.test.js +26 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
- package/packages/dsh-plugin/test/index.test.js +150 -1
- package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
- package/packages/dsh-plugin/test/workbench.test.js +420 -0
- package/scripts/adaptive.py +13 -11
- package/scripts/argo_paths.py +2 -2
- package/scripts/badcase_ledger.py +9 -0
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +69 -70
- package/scripts/check_commit_report.py +46 -0
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +91 -13
- package/scripts/config_cache.py +23 -10
- package/scripts/daemon.py +14 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +32 -49
- package/scripts/engine_env.py +13 -4
- package/scripts/engine_failure.py +33 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +50 -0
- package/scripts/engines_base.py +31 -19
- package/scripts/engines_builders_archive.py +4 -3
- package/scripts/engines_builders_batch11.py +2 -1
- package/scripts/engines_builders_batch13.py +4 -3
- package/scripts/engines_builders_batch14.py +2 -1
- package/scripts/engines_builders_batch15.py +2 -1
- package/scripts/engines_builders_batch9.py +2 -2
- package/scripts/engines_builders_cn.py +7 -7
- package/scripts/engines_builders_data.py +12 -11
- package/scripts/engines_builders_data_macro.py +5 -4
- package/scripts/engines_builders_dsh.py +2 -1
- package/scripts/engines_builders_feeds.py +34 -19
- package/scripts/engines_builders_finance.py +2 -1
- package/scripts/engines_builders_intl.py +3 -2
- package/scripts/engines_builders_media.py +59 -12
- package/scripts/engines_builders_science.py +8 -7
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_skill.py +2 -1
- package/scripts/engines_builders_tech.py +19 -19
- package/scripts/engines_builders_weather.py +9 -4
- package/scripts/engines_fields.py +23 -0
- package/scripts/engines_http.py +50 -1
- package/scripts/engines_mcp.py +28 -6
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/evidence_loop.py +15 -1
- package/scripts/extend_route_labels.py +6 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/fetch_jina.py +98 -0
- package/scripts/fetch_v3.py +52 -93
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.sh +2 -0
- package/scripts/matrix_search_eval.py +8 -10
- package/scripts/mcp_transport.py +33 -9
- package/scripts/numeric_verify.py +12 -2
- package/scripts/output_transparency.py +3 -0
- package/scripts/pre-commit +57 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +46 -63
- package/scripts/recovery.py +19 -16
- package/scripts/recovery_runner.py +29 -10
- package/scripts/redskill/redskill_engine.py +2 -1
- package/scripts/release.py +16 -1
- package/scripts/research_gates.py +85 -1
- package/scripts/route.py +8 -0
- package/scripts/route_combo.py +24 -3
- package/scripts/route_policy.py +1 -1
- package/scripts/search_attribution.py +20 -0
- package/scripts/search_entry.py +27 -0
- package/scripts/search_output.py +18 -7
- package/scripts/search_pipeline.py +3 -3
- package/scripts/semantic_evidence.py +20 -11
- package/scripts/serp_guard.py +13 -1
- package/scripts/settings_page.py +1 -0
- package/scripts/single_flight.py +1 -1
- package/scripts/social_engines/hackernews_engine.py +2 -1
- package/scripts/social_engines/reddit_engine.py +2 -1
- package/scripts/social_engines/zhihu_engine.py +2 -1
- package/scripts/source_audit.py +42 -7
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/scripts/usage_log.py +24 -9
- package/scripts/watch.py +3 -3
- package/scripts/zhihu_quota.py +2 -1
- package/sub-skills/argo-wide-research/SKILL.md +7 -5
- package/sub-skills/ego-search/{SKILL.md → README.md} +24 -47
- package/sub-skills/ego-search/scripts/ego_search.py +195 -19
- package/sub-skills/ego-search/scripts/pacing.py +291 -0
- package/sub-skills/ego-search/scripts/quality.py +262 -6
- package/sub-skills/ego-search/scripts/runtime.py +7 -1
- package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
- package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
- package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
- package/sub-skills/local-search/engine_registry.py +32 -7
- package/sub-skills/local-seek/SKILL.md +20 -22
package/scripts/browser_auth.py
CHANGED
|
@@ -105,6 +105,7 @@ def _read_meta(d: Path) -> dict:
|
|
|
105
105
|
|
|
106
106
|
def _write_meta(d: Path, host: str, created: str | None = None) -> None:
|
|
107
107
|
"""原子写 meta.json:profile 的 argo 登记标记(Chrome 不认识也不在乎它)。"""
|
|
108
|
+
import argo_paths
|
|
108
109
|
prev = _read_meta(d)
|
|
109
110
|
meta = {
|
|
110
111
|
"site": host,
|
|
@@ -112,9 +113,7 @@ def _write_meta(d: Path, host: str, created: str | None = None) -> None:
|
|
|
112
113
|
"last_used": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
113
114
|
"argo": "browser-profiles/v1",
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
-
tmp.write_text(json.dumps(meta, ensure_ascii=False), encoding="utf-8")
|
|
117
|
-
os.replace(tmp, d / "meta.json")
|
|
116
|
+
argo_paths.atomic_write_json(d / "meta.json", meta)
|
|
118
117
|
|
|
119
118
|
|
|
120
119
|
def profile_for(url_or_host: str) -> str | None:
|
|
@@ -174,6 +173,7 @@ def login(url_or_host: str, chrome_path: str | None = None,
|
|
|
174
173
|
msg += "(该 profile 可能已有 Chrome 在跑:关掉它或先 argo auth logout)"
|
|
175
174
|
return {"ok": False, "site": host, "error": msg[:200]}
|
|
176
175
|
|
|
176
|
+
saved = False
|
|
177
177
|
try:
|
|
178
178
|
if confirm is None:
|
|
179
179
|
print(f"\n[{host}] 已在打开的 Chrome 窗口中登录/扫码。", file=sys.stderr)
|
|
@@ -186,12 +186,15 @@ def login(url_or_host: str, chrome_path: str | None = None,
|
|
|
186
186
|
else:
|
|
187
187
|
confirm()
|
|
188
188
|
_write_meta(d, host)
|
|
189
|
+
saved = True
|
|
189
190
|
return {"ok": True, "site": host, "profile": str(d)}
|
|
190
191
|
finally:
|
|
191
192
|
try:
|
|
192
193
|
proc.stop()
|
|
193
194
|
except Exception:
|
|
194
195
|
pass
|
|
196
|
+
if fresh and not saved:
|
|
197
|
+
shutil.rmtree(d, ignore_errors=True)
|
|
195
198
|
|
|
196
199
|
|
|
197
200
|
def status() -> list[dict]:
|
|
@@ -246,6 +249,162 @@ def touch(url_or_host: str) -> None:
|
|
|
246
249
|
pass
|
|
247
250
|
|
|
248
251
|
|
|
252
|
+
# ─── 四态防抖判别、活体会话校验与评论上下文封顶 ─────────────────────────────
|
|
253
|
+
|
|
254
|
+
_SEC_VERIFY_URL_RE = re.compile(r"captcha|security[._-]?verif|challenge|/account/access", re.I)
|
|
255
|
+
_SEC_VERIFY_TEXT_RE = re.compile(
|
|
256
|
+
r"安全验证|安全限制|IP存在风险|访问受限|异常访问|操作频繁|请完成验证|verify you are human",
|
|
257
|
+
re.I,
|
|
258
|
+
)
|
|
259
|
+
_SIGNED_OUT_URL_RE = re.compile(r"website-login|/i/flow/login|/login(?:/|\?|$)|/signin(?:/|\?|$)", re.I)
|
|
260
|
+
_LOGIN_WALL_TEXT_RE = re.compile(
|
|
261
|
+
r"登录后推荐更懂你的笔记|登录后查看|请先登录|立即登录以继续|log in to continue|sign in to view",
|
|
262
|
+
re.I,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def detect_page_auth_state(
|
|
267
|
+
url: str,
|
|
268
|
+
title: str = "",
|
|
269
|
+
body_text: str = "",
|
|
270
|
+
*,
|
|
271
|
+
has_security_modal: bool = False,
|
|
272
|
+
has_login_modal: bool = False,
|
|
273
|
+
after_search: bool = False,
|
|
274
|
+
) -> str:
|
|
275
|
+
"""四态(+搜索受限)判别纯函数:全部返回 engine_states.PAGE_AUTH_* 常量。"""
|
|
276
|
+
import engine_states as _es
|
|
277
|
+
|
|
278
|
+
# 入口统一收敛 str:调用方可能传非 str(测试桩的 MagicMock 等),
|
|
279
|
+
# regex 收到非 str 会 TypeError 顺异常链拖垮整条 fetch
|
|
280
|
+
# (tests/test_fetch_auth_lane.py::test_browser_fetch_marks_login_provenance 回归)。
|
|
281
|
+
href = str(url) if url else ""
|
|
282
|
+
combined = "{}\n{}".format(str(title or ""), str(body_text or "")[:4000])
|
|
283
|
+
if has_security_modal or _SEC_VERIFY_URL_RE.search(href) or _SEC_VERIFY_TEXT_RE.search(combined):
|
|
284
|
+
return _es.PAGE_AUTH_SECURITY_VERIFY
|
|
285
|
+
if _SIGNED_OUT_URL_RE.search(href):
|
|
286
|
+
return _es.PAGE_AUTH_SIGNED_OUT
|
|
287
|
+
if has_login_modal or _LOGIN_WALL_TEXT_RE.search(combined):
|
|
288
|
+
return _es.PAGE_AUTH_SEARCH_RESTRICTED if after_search else _es.PAGE_AUTH_LOGIN_WALL
|
|
289
|
+
return _es.PAGE_AUTH_READY
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def wait_for_stable_page_auth_state(
|
|
293
|
+
probe_fn,
|
|
294
|
+
*,
|
|
295
|
+
settle_s: float = 0.6,
|
|
296
|
+
interval_s: float = 0.25,
|
|
297
|
+
consecutive: int = 3,
|
|
298
|
+
max_samples: int = 7,
|
|
299
|
+
sleep_fn=time.sleep,
|
|
300
|
+
) -> str:
|
|
301
|
+
"""多帧防抖状态机:连续 consecutive 次观测一致才裁决,避免 SPA 水合瞬间误判。"""
|
|
302
|
+
import engine_states as _es
|
|
303
|
+
|
|
304
|
+
if settle_s > 0:
|
|
305
|
+
sleep_fn(settle_s)
|
|
306
|
+
last: str | None = None
|
|
307
|
+
repeated = 0
|
|
308
|
+
for idx in range(max(1, max_samples)):
|
|
309
|
+
current = probe_fn()
|
|
310
|
+
if current == last:
|
|
311
|
+
repeated += 1
|
|
312
|
+
else:
|
|
313
|
+
last = current
|
|
314
|
+
repeated = 1
|
|
315
|
+
if repeated >= max(1, consecutive):
|
|
316
|
+
return current
|
|
317
|
+
if interval_s > 0 and idx + 1 < max_samples:
|
|
318
|
+
sleep_fn(interval_s)
|
|
319
|
+
return last or _es.PAGE_AUTH_SIGNED_OUT
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def verify_live_session(
|
|
323
|
+
url_or_host: str,
|
|
324
|
+
*,
|
|
325
|
+
cdp_factory=None,
|
|
326
|
+
timeout: float = 10.0,
|
|
327
|
+
settle_s: float = 0.6,
|
|
328
|
+
interval_s: float = 0.25,
|
|
329
|
+
) -> dict:
|
|
330
|
+
"""活体会话校验:确认持久 profile 存在且打开页面后经多帧防抖处于 PAGE_AUTH_READY。"""
|
|
331
|
+
import engine_states as _es
|
|
332
|
+
|
|
333
|
+
host = site_host(url_or_host)
|
|
334
|
+
prof = profile_for(host)
|
|
335
|
+
if not prof:
|
|
336
|
+
return {
|
|
337
|
+
"ok": False, "site": host, "state": _es.PAGE_AUTH_SIGNED_OUT,
|
|
338
|
+
"retryable": False, "handoff_required": True,
|
|
339
|
+
"error": f"未找到 {host} 的登录态 profile(请先 argo auth login {host})",
|
|
340
|
+
}
|
|
341
|
+
target = url_or_host.strip()
|
|
342
|
+
if "://" not in target:
|
|
343
|
+
target = "https://" + target
|
|
344
|
+
|
|
345
|
+
if cdp_factory is None:
|
|
346
|
+
from chrome_cdp import ChromeCDP
|
|
347
|
+
cdp_factory = lambda: ChromeCDP(auto_start=True, user_data_dir=prof)
|
|
348
|
+
|
|
349
|
+
cdp = None
|
|
350
|
+
try:
|
|
351
|
+
cdp = cdp_factory()
|
|
352
|
+
cdp.navigate(target, wait_until="networkidle", timeout=timeout)
|
|
353
|
+
|
|
354
|
+
def _probe() -> str:
|
|
355
|
+
return detect_page_auth_state(
|
|
356
|
+
cdp.get_url() or target,
|
|
357
|
+
cdp.get_title() or "",
|
|
358
|
+
cdp.get_text() or "",
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
state = wait_for_stable_page_auth_state(
|
|
362
|
+
_probe, settle_s=settle_s, interval_s=interval_s,
|
|
363
|
+
)
|
|
364
|
+
usable = _es.is_page_auth_usable(state)
|
|
365
|
+
non_retry = _es.is_page_auth_non_retryable(state)
|
|
366
|
+
return {
|
|
367
|
+
"ok": usable, "site": host, "state": state,
|
|
368
|
+
"retryable": not non_retry, "handoff_required": non_retry,
|
|
369
|
+
"error": None if usable else f"{host} 会话不可用(state={state}),请人工重新登录或通过验证",
|
|
370
|
+
}
|
|
371
|
+
except (OSError, RuntimeError, ValueError) as e:
|
|
372
|
+
return {
|
|
373
|
+
"ok": False, "site": host, "state": _es.PAGE_AUTH_SIGNED_OUT,
|
|
374
|
+
"retryable": True, "handoff_required": False,
|
|
375
|
+
"error": f"活体探测失败: {str(e)[:120]}",
|
|
376
|
+
}
|
|
377
|
+
finally:
|
|
378
|
+
if cdp is not None:
|
|
379
|
+
try:
|
|
380
|
+
cdp.stop()
|
|
381
|
+
except (OSError, RuntimeError):
|
|
382
|
+
pass
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def bound_comments(
|
|
386
|
+
comments: list[dict],
|
|
387
|
+
*,
|
|
388
|
+
max_items: int = 30,
|
|
389
|
+
max_chars: int = 800,
|
|
390
|
+
) -> dict:
|
|
391
|
+
"""评论/回复上下文封顶器:最多保留 max_items 条,单条正文截断至 max_chars,显式标 truncated。"""
|
|
392
|
+
total = len(comments or [])
|
|
393
|
+
kept: list[dict] = []
|
|
394
|
+
truncated = total > max_items
|
|
395
|
+
for raw in (comments or [])[:max_items]:
|
|
396
|
+
if not isinstance(raw, dict):
|
|
397
|
+
continue
|
|
398
|
+
item = dict(raw)
|
|
399
|
+
for text_key in ("text", "content", "body"):
|
|
400
|
+
val = item.get(text_key)
|
|
401
|
+
if isinstance(val, str) and len(val) > max_chars:
|
|
402
|
+
item[text_key] = val[:max_chars] + "…"
|
|
403
|
+
truncated = True
|
|
404
|
+
kept.append(item)
|
|
405
|
+
return {"items": kept, "total": total, "truncated": truncated}
|
|
406
|
+
|
|
407
|
+
|
|
249
408
|
# ─── CLI(bin/argo 的 auth 子命令入口)──────────────────────────────────────
|
|
250
409
|
|
|
251
410
|
def main(argv: list[str] | None = None) -> None:
|
|
@@ -314,7 +473,22 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
314
473
|
print(f"删除失败:{out.get('error')}", file=sys.stderr)
|
|
315
474
|
sys.exit(0 if out.get("ok") else 1)
|
|
316
475
|
|
|
317
|
-
|
|
476
|
+
if cmd == "verify":
|
|
477
|
+
if not rest:
|
|
478
|
+
print("用法:argo auth verify <url_or_host>(活体验证已保存会话)",
|
|
479
|
+
file=sys.stderr)
|
|
480
|
+
sys.exit(1)
|
|
481
|
+
out = verify_live_session(rest[0])
|
|
482
|
+
if use_json:
|
|
483
|
+
_emit_json(out)
|
|
484
|
+
elif out.get("ok"):
|
|
485
|
+
print(f"{out['site']} 登录态活体校验通过(state={out['state']})。")
|
|
486
|
+
else:
|
|
487
|
+
print(f"{out['site']} 校验未通过(state={out.get('state')}):{out.get('error')}",
|
|
488
|
+
file=sys.stderr)
|
|
489
|
+
sys.exit(0 if out.get("ok") else 1)
|
|
490
|
+
|
|
491
|
+
print(f"Unknown auth subcommand: {cmd}(可用:login / status / verify / logout)",
|
|
318
492
|
file=sys.stderr)
|
|
319
493
|
sys.exit(1)
|
|
320
494
|
|
package/scripts/cache.py
CHANGED
|
@@ -250,7 +250,7 @@ class LRUCache:
|
|
|
250
250
|
class SQLiteCache:
|
|
251
251
|
"""SQLite 持久化缓存,支持 TTL 过期、大小限制、gzip 压缩。"""
|
|
252
252
|
|
|
253
|
-
SCHEMA_VERSION =
|
|
253
|
+
SCHEMA_VERSION = 3 # 2026-11-17 bump:加列/改表必须与 bump 同提交(加列不 bump+版本早退曾让旧库升级即炸,test_cache_schema_migration 锁)
|
|
254
254
|
|
|
255
255
|
def __init__(self, db_path: str = DEFAULT_DB_PATH, ttl: int = DEFAULT_TTL,
|
|
256
256
|
max_size_mb: float | None = None):
|
|
@@ -324,22 +324,7 @@ class SQLiteCache:
|
|
|
324
324
|
|
|
325
325
|
@contextlib.contextmanager
|
|
326
326
|
def _conn(self):
|
|
327
|
-
"""
|
|
328
|
-
|
|
329
|
-
为什么不是 `with self._connect() as conn:`:sqlite3 的连接上下文管理器
|
|
330
|
-
管的是**事务**(正常退出 commit、异常 rollback),它**不关连接**。于是
|
|
331
|
-
此前 9 处调用点每跑一次就新建并遗弃一条文件连接——进程内跑几千次缓存
|
|
332
|
-
操作就攒下几千个 fd,长驻 MCP 进程迟早撞上 ulimit(EMFILE),而报错点
|
|
333
|
-
会落在完全无关的 socket/文件调用上,极难归因。
|
|
334
|
-
|
|
335
|
-
这里把「作用域」补成真正的作用域语义:commit → close。异常时先
|
|
336
|
-
rollback 再关,事务状态不留半截。
|
|
337
|
-
|
|
338
|
-
`:memory:` 是**共享**连接(每次 connect(":memory:") 都是独立空库),
|
|
339
|
-
不能关——关掉等于把整层内存缓存作废。锁不在这里取:调用点有的持锁
|
|
340
|
-
(读改写路径)、有的不持(_evict_if_needed / size_mb 只读统计),
|
|
341
|
-
保持各自原语义。
|
|
342
|
-
"""
|
|
327
|
+
"""借一个连接:出作用域提交/回滚,并把自建文件连接关闭以防 fd 泄漏。"""
|
|
343
328
|
conn = self._connect()
|
|
344
329
|
shared = conn is self._mem_conn
|
|
345
330
|
try:
|
|
@@ -452,44 +437,54 @@ class SQLiteCache:
|
|
|
452
437
|
).fetchone()
|
|
453
438
|
return row is not None and not self._is_expired(row[0], row[1])
|
|
454
439
|
|
|
440
|
+
_ACCESS_TOUCH_INTERVAL_S = 60.0 # 60s 内只读命中不回写 accessed_at,避 WAL 写锁争用
|
|
455
441
|
def get(self, key: str) -> Optional[dict]:
|
|
456
442
|
if self._degraded_reason is not None:
|
|
457
443
|
# 降级:一律视作未命中。缓存是加速层,缺它只该变慢,不该变错。
|
|
458
444
|
self._misses += 1
|
|
459
445
|
return None
|
|
460
|
-
|
|
461
|
-
with self.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
446
|
+
try:
|
|
447
|
+
with self._lock:
|
|
448
|
+
with self._conn() as conn:
|
|
449
|
+
row = conn.execute(
|
|
450
|
+
"SELECT value_blob, compressed, created_at, ttl, accessed_at FROM search_cache WHERE key = ?",
|
|
451
|
+
(key,),
|
|
452
|
+
).fetchone()
|
|
453
|
+
if row is None:
|
|
454
|
+
self._misses += 1
|
|
455
|
+
return None
|
|
456
|
+
value_blob, compressed, created_at, ttl, accessed_at = row
|
|
457
|
+
if self._is_expired(created_at, ttl):
|
|
458
|
+
conn.execute("DELETE FROM search_cache WHERE key = ?", (key,))
|
|
459
|
+
conn.commit()
|
|
460
|
+
self._misses += 1
|
|
461
|
+
return None
|
|
462
|
+
now = time.time()
|
|
463
|
+
if (now - float(accessed_at or 0)) >= self._ACCESS_TOUCH_INTERVAL_S:
|
|
464
|
+
conn.execute("UPDATE search_cache SET accessed_at = ? WHERE key = ?",
|
|
465
|
+
(now, key))
|
|
466
|
+
conn.commit()
|
|
467
|
+
self._hits += 1
|
|
468
|
+
return self._deserialize(value_blob, compressed)
|
|
469
|
+
except _get_sqlite3().Error:
|
|
470
|
+
self._misses += 1
|
|
471
|
+
return None
|
|
480
472
|
|
|
481
473
|
def get_many(self, keys: list[str]) -> dict[str, dict]:
|
|
482
474
|
if not keys or self._degraded_reason is not None:
|
|
483
475
|
return {}
|
|
484
476
|
out: dict[str, dict] = {}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
477
|
+
try:
|
|
478
|
+
with self._lock, self._conn() as conn:
|
|
479
|
+
ph = ",".join("?" for _ in keys)
|
|
480
|
+
for k, blob, comp, ts, ttl in conn.execute(
|
|
481
|
+
f"SELECT key, value_blob, compressed, created_at, ttl "
|
|
482
|
+
f"FROM search_cache WHERE key IN ({ph})", tuple(keys)
|
|
483
|
+
):
|
|
484
|
+
if not self._is_expired(ts, ttl):
|
|
485
|
+
out[k] = self._deserialize(blob, comp)
|
|
486
|
+
except _get_sqlite3().Error:
|
|
487
|
+
return {}
|
|
493
488
|
return out
|
|
494
489
|
|
|
495
490
|
def set(self, key: str, query: str, engine: str, max_results: int,
|
|
@@ -501,23 +496,24 @@ class SQLiteCache:
|
|
|
501
496
|
blob, compressed = self._serialize(value)
|
|
502
497
|
now = time.time()
|
|
503
498
|
effective_ttl = ttl if ttl is not None else self._ttl
|
|
504
|
-
with self._conn() as conn:
|
|
505
|
-
conn.execute(
|
|
506
|
-
"""INSERT OR REPLACE INTO search_cache
|
|
507
|
-
(key, query, engine, max_results, domain, mode, depth,
|
|
508
|
-
value_blob, compressed, ttl, created_at, accessed_at)
|
|
509
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|
510
|
-
(key, query, engine, max_results, domain, mode, depth,
|
|
511
|
-
blob, compressed, effective_ttl, now, now),
|
|
512
|
-
)
|
|
513
|
-
conn.commit()
|
|
514
|
-
# 驱逐失败不阻断写入方:缓存是加速层,缺它只该变慢不该变错。
|
|
515
|
-
# 与 self._degraded_reason 的 fail-open 语义同构——DB 损坏/磁盘满/WAL
|
|
516
|
-
# 异常时,宁可让下次搜索多写一条也不让 execute_search 在最后一步 traceback。
|
|
517
499
|
try:
|
|
518
|
-
self.
|
|
500
|
+
with self._conn() as conn:
|
|
501
|
+
conn.execute(
|
|
502
|
+
"""INSERT OR REPLACE INTO search_cache
|
|
503
|
+
(key, query, engine, max_results, domain, mode, depth,
|
|
504
|
+
value_blob, compressed, ttl, created_at, accessed_at)
|
|
505
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|
506
|
+
(key, query, engine, max_results, domain, mode, depth,
|
|
507
|
+
blob, compressed, effective_ttl, now, now),
|
|
508
|
+
)
|
|
509
|
+
conn.commit()
|
|
510
|
+
# 复用同一连接做空间回收(2 次开闭 → 1 次),失败不阻断写入方
|
|
511
|
+
try:
|
|
512
|
+
self._evict_if_needed(conn=conn)
|
|
513
|
+
except _get_sqlite3().Error:
|
|
514
|
+
pass
|
|
519
515
|
except _get_sqlite3().Error:
|
|
520
|
-
|
|
516
|
+
return
|
|
521
517
|
|
|
522
518
|
# 过期行回收的节流间隔。扫描是 O(rows) 全表(`created_at + ttl < ?` 不可
|
|
523
519
|
# 走索引),放进每次 set() 的热路径会白付约 6ms/次;稳态下每小时一次足够
|
|
@@ -544,9 +540,10 @@ class SQLiteCache:
|
|
|
544
540
|
except _get_sqlite3().Error:
|
|
545
541
|
pass
|
|
546
542
|
|
|
547
|
-
def _evict_if_needed(self):
|
|
543
|
+
def _evict_if_needed(self, conn=None):
|
|
548
544
|
"""空间回收三步:过期行清扫(每小时节流)→ LRU 淘汰(按 payload 口径)→ VACUUM。"""
|
|
549
|
-
|
|
545
|
+
ctx_mgr = contextlib.nullcontext(conn) if conn is not None else self._conn()
|
|
546
|
+
with ctx_mgr as conn:
|
|
550
547
|
limit_bytes = self._max_size_mb * 1024 * 1024
|
|
551
548
|
if self._expiry_sweep_due(conn):
|
|
552
549
|
conn.execute(
|
|
@@ -893,9 +890,7 @@ class SearchCache:
|
|
|
893
890
|
if hit is not None:
|
|
894
891
|
ttl = hit.get("_ttl", 0)
|
|
895
892
|
if ttl > 0 and time.time() - hit.get("_ts", 0) < ttl:
|
|
896
|
-
out =
|
|
897
|
-
out["results"] = [dict(r) if isinstance(r, dict) else r
|
|
898
|
-
for r in (hit.get("results") or [])]
|
|
893
|
+
out = self._copy_hit(hit)
|
|
899
894
|
out["_cache_level"] = engine_states.CACHE_LEVEL_L1
|
|
900
895
|
return out
|
|
901
896
|
self._l1.remove(key)
|
|
@@ -905,13 +900,17 @@ class SearchCache:
|
|
|
905
900
|
hit = self._l2.get(key)
|
|
906
901
|
if hit is not None:
|
|
907
902
|
self._l1.set(key, hit)
|
|
908
|
-
out =
|
|
909
|
-
out["results"] = [dict(r) if isinstance(r, dict) else r
|
|
910
|
-
for r in (hit.get("results") or [])]
|
|
903
|
+
out = self._copy_hit(hit)
|
|
911
904
|
out["_cache_level"] = engine_states.CACHE_LEVEL_L2
|
|
912
905
|
return out
|
|
913
906
|
return None
|
|
914
907
|
|
|
908
|
+
@staticmethod
|
|
909
|
+
def _copy_hit(hit: dict) -> dict:
|
|
910
|
+
out = dict(hit)
|
|
911
|
+
out["results"] = [dict(r) if isinstance(r, dict) else r for r in (hit.get("results") or [])]
|
|
912
|
+
return out
|
|
913
|
+
|
|
915
914
|
def _read_many(self, keys: list[str]) -> dict[str, dict]:
|
|
916
915
|
if not keys or self._disabled():
|
|
917
916
|
return {}
|
|
@@ -919,7 +918,7 @@ class SearchCache:
|
|
|
919
918
|
for k in dict.fromkeys(keys):
|
|
920
919
|
hit = self._l1.get(k)
|
|
921
920
|
if hit is not None and hit.get("_ttl", 0) > 0 and now - hit.get("_ts", 0) < hit.get("_ttl", 0):
|
|
922
|
-
out[k] = hit
|
|
921
|
+
out[k] = self._copy_hit(hit)
|
|
923
922
|
else:
|
|
924
923
|
if hit is not None:
|
|
925
924
|
self._l1.remove(k)
|
|
@@ -928,7 +927,7 @@ class SearchCache:
|
|
|
928
927
|
l2_hits = self._l2.get_many(miss)
|
|
929
928
|
for k, hit in l2_hits.items():
|
|
930
929
|
self._l1.set(k, hit)
|
|
931
|
-
out[k] = hit
|
|
930
|
+
out[k] = self._copy_hit(hit)
|
|
932
931
|
self._miss_memo = (time.monotonic(), frozenset(k for k in miss if k not in l2_hits))
|
|
933
932
|
return out
|
|
934
933
|
|
|
@@ -18,6 +18,10 @@ argo 的 pre-commit 注释自己记着两起真实事故:`f702ee2` 把 SKILL.m
|
|
|
18
18
|
用 `跑了` / `在 commit` / `未跑` 三个名字;`未跑: 无` 是合法写法(确实没漏),
|
|
19
19
|
但整段省略不合法。
|
|
20
20
|
|
|
21
|
+
另附 `docs(release*)` 纯净性判定(`is_release_docs_title` / `code_diff_violations`
|
|
22
|
+
/ `commit_code_diff_paths`):发布说明提交不得夹带代码 diff,由
|
|
23
|
+
`tests/test_check_commit_report.py` 的未推窗口门禁消费(2026-11-20 落地)。
|
|
24
|
+
|
|
21
25
|
用法:
|
|
22
26
|
python3 scripts/check_commit_report.py --message-file .git/COMMIT_EDITMSG
|
|
23
27
|
python3 scripts/check_commit_report.py --message "feat(engines): 接入 X 源"
|
|
@@ -89,6 +93,48 @@ def missing_segments(body: str) -> list[str]:
|
|
|
89
93
|
return [name for name, pat in _SEGMENTS.items() if not pat.search(body)]
|
|
90
94
|
|
|
91
95
|
|
|
96
|
+
# ── docs(release*) 纯净性:发布说明提交不得夹带代码 diff ─────────────────────
|
|
97
|
+
# 2026-11-20 实锤:0647a33 在 v2.16.0 发布说明提交里夹带 route_policy.py 的
|
|
98
|
+
# 路由行为变更,四语发布说明只字未提,次日 e0b3539 自查才补救。本判定不拦
|
|
99
|
+
# 历史(已推的拦不动),只供未推窗口门禁消费——见
|
|
100
|
+
# tests/test_check_commit_report.py::test_unpushed_release_docs_commits_are_pure。
|
|
101
|
+
_RELEASE_DOCS_TITLE_RE = re.compile(r"^docs\((release[-_a-z]*)\)")
|
|
102
|
+
|
|
103
|
+
# 代码后缀;bin/ 下无后缀的可执行脚本(bin/argo)也按代码算。
|
|
104
|
+
_CODE_DIFF_SUFFIXES = frozenset({".py", ".js", ".mjs", ".cjs", ".ts", ".jsx", ".tsx", ".sh"})
|
|
105
|
+
|
|
106
|
+
# 版本声明豁免:这两处 .py 是版本单源契约的机器声明文件(release_check 机械
|
|
107
|
+
# 对账成员),bump 版本号本来就发生在发布提交里——豁免它们,其余 .py/.js
|
|
108
|
+
# 一律不许。行为变更想借道这两处躲门禁,会被版本对账门禁照出形状不符。
|
|
109
|
+
_VERSION_DECLARATION_PATHS = frozenset({"argo_search/__init__.py", "scripts/mcp_transport.py"})
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def is_release_docs_title(title: str) -> bool:
|
|
113
|
+
"""标题是否为 docs(release*) 发布说明提交。"""
|
|
114
|
+
return bool(_RELEASE_DOCS_TITLE_RE.match(title.strip()))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def code_diff_violations(changed_paths) -> list[str]:
|
|
118
|
+
"""docs(release*) 提交里不许出现的代码路径(版本声明两处豁免)。"""
|
|
119
|
+
out = []
|
|
120
|
+
for p in changed_paths:
|
|
121
|
+
if p in _VERSION_DECLARATION_PATHS:
|
|
122
|
+
continue
|
|
123
|
+
if p.startswith("bin/") or Path(p).suffix.lower() in _CODE_DIFF_SUFFIXES:
|
|
124
|
+
out.append(p)
|
|
125
|
+
return out
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def commit_code_diff_paths(rev: str) -> list[str]:
|
|
129
|
+
"""列出某提交改动的文件路径(读不到该提交时返回空,调用方自行定夺)。"""
|
|
130
|
+
r = subprocess.run(
|
|
131
|
+
["git", "-C", str(ROOT), "show", "--name-only", "--pretty=format:", rev],
|
|
132
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace")
|
|
133
|
+
if r.returncode != 0:
|
|
134
|
+
return []
|
|
135
|
+
return [ln for ln in r.stdout.splitlines() if ln.strip()]
|
|
136
|
+
|
|
137
|
+
|
|
92
138
|
def parse_message(text: str) -> tuple[str, str]:
|
|
93
139
|
"""拆成 (标题, 正文)。注释行(# 开头)剔除。"""
|
|
94
140
|
lines = [ln for ln in text.splitlines()
|
package/scripts/chrome_cdp.py
CHANGED
|
@@ -498,6 +498,36 @@ class NetworkIdleTracker:
|
|
|
498
498
|
|
|
499
499
|
# ─── 主 API ──────────────────────────────────────────────────────────────────
|
|
500
500
|
|
|
501
|
+
class NetworkCapture:
|
|
502
|
+
"""轻量 CDP 网络流捕获器:按 URL 模式记录目标 XHR/GraphQL 响应 requestId。"""
|
|
503
|
+
|
|
504
|
+
def __init__(self, url_patterns: list[str] | tuple[str, ...]):
|
|
505
|
+
self._patterns = [p for p in url_patterns if p]
|
|
506
|
+
self._matched: dict[str, dict[str, Any]] = {}
|
|
507
|
+
self.finished_ids: list[str] = []
|
|
508
|
+
|
|
509
|
+
def feed(self, method: str | None, params: dict) -> None:
|
|
510
|
+
if method == "Network.responseReceived":
|
|
511
|
+
req_id = params.get("requestId")
|
|
512
|
+
resp = params.get("response") or {}
|
|
513
|
+
url = str(resp.get("url") or "")
|
|
514
|
+
if req_id and url and any(p in url for p in self._patterns):
|
|
515
|
+
self._matched[str(req_id)] = {
|
|
516
|
+
"request_id": str(req_id),
|
|
517
|
+
"url": url,
|
|
518
|
+
"status": int(resp.get("status") or 0),
|
|
519
|
+
"mime_type": str(resp.get("mimeType") or ""),
|
|
520
|
+
}
|
|
521
|
+
elif method == "Network.loadingFinished":
|
|
522
|
+
req_id = str(params.get("requestId") or "")
|
|
523
|
+
if req_id in self._matched and req_id not in self.finished_ids:
|
|
524
|
+
self.finished_ids.append(req_id)
|
|
525
|
+
|
|
526
|
+
def pending_entries(self, max_items: int = 20) -> list[dict[str, Any]]:
|
|
527
|
+
ids = self.finished_ids[:max_items] if self.finished_ids else list(self._matched.keys())[:max_items]
|
|
528
|
+
return [self._matched[rid] for rid in ids if rid in self._matched]
|
|
529
|
+
|
|
530
|
+
|
|
501
531
|
class ChromeCDP:
|
|
502
532
|
"""高级 CDP 封装:页面交互 + 内容提取。
|
|
503
533
|
|
|
@@ -524,6 +554,7 @@ class ChromeCDP:
|
|
|
524
554
|
self._session: _CDPSession | None = None
|
|
525
555
|
self._target_id: str | None = None
|
|
526
556
|
self._net: NetworkIdleTracker | None = None
|
|
557
|
+
self._capture: NetworkCapture | None = None
|
|
527
558
|
if auto_start:
|
|
528
559
|
try:
|
|
529
560
|
self.start()
|
|
@@ -566,6 +597,46 @@ class ChromeCDP:
|
|
|
566
597
|
def _on_event(self, method, params) -> None:
|
|
567
598
|
if self._net is not None:
|
|
568
599
|
self._net.feed(method, params)
|
|
600
|
+
if self._capture is not None:
|
|
601
|
+
self._capture.feed(method, params)
|
|
602
|
+
|
|
603
|
+
def start_network_capture(self, url_patterns: list[str] | tuple[str, ...]) -> NetworkCapture:
|
|
604
|
+
"""开启指定 URL 子串的网络流捕获(适用于 GraphQL/XHR 数据直取)。"""
|
|
605
|
+
self._capture = NetworkCapture(url_patterns)
|
|
606
|
+
return self._capture
|
|
607
|
+
|
|
608
|
+
def stop_network_capture(self) -> None:
|
|
609
|
+
self._capture = None
|
|
610
|
+
|
|
611
|
+
def collect_captured_json(self, max_items: int = 20) -> list[dict[str, Any]]:
|
|
612
|
+
"""拉取已捕获请求的响应体并解析 JSON(单条解析失败跳过,不中断整批)。"""
|
|
613
|
+
if self._capture is None or self._session is None:
|
|
614
|
+
return []
|
|
615
|
+
import base64
|
|
616
|
+
out: list[dict[str, Any]] = []
|
|
617
|
+
for meta in self._capture.pending_entries(max_items=max_items):
|
|
618
|
+
try:
|
|
619
|
+
res = self._session.send("Network.getResponseBody", {"requestId": meta["request_id"]})
|
|
620
|
+
except OSError:
|
|
621
|
+
continue
|
|
622
|
+
if not isinstance(res, dict) or "body" not in res:
|
|
623
|
+
continue
|
|
624
|
+
raw = res.get("body") or ""
|
|
625
|
+
if res.get("base64Encoded"):
|
|
626
|
+
try:
|
|
627
|
+
raw = base64.b64decode(raw).decode("utf-8", errors="replace")
|
|
628
|
+
except (ValueError, UnicodeDecodeError):
|
|
629
|
+
continue
|
|
630
|
+
try:
|
|
631
|
+
data = json.loads(raw)
|
|
632
|
+
except json.JSONDecodeError:
|
|
633
|
+
continue
|
|
634
|
+
out.append({
|
|
635
|
+
"url": meta["url"],
|
|
636
|
+
"status": meta["status"],
|
|
637
|
+
"data": data,
|
|
638
|
+
})
|
|
639
|
+
return out
|
|
569
640
|
|
|
570
641
|
def stop(self) -> None:
|
|
571
642
|
if self._session:
|