argo-search 2.13.0 → 2.14.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.
Files changed (89) hide show
  1. package/AGENTS.md +93 -0
  2. package/README.en.md +16 -4
  3. package/README.es.md +16 -4
  4. package/README.ja.md +16 -4
  5. package/README.ko.md +16 -4
  6. package/README.md +16 -4
  7. package/SKILL.md +1 -1
  8. package/assets/readme/counts.json +1 -1
  9. package/backends/domain_profiles.json +66 -6
  10. package/backends/engine_registry.yaml +154 -15
  11. package/backends/env_passthrough.txt +2 -0
  12. package/backends/quota_profiles.json +111 -11
  13. package/bin/argo +3 -0
  14. package/config.yaml +27 -1
  15. package/docs/CHANGELOG.md +23 -0
  16. package/docs/COMMIT_STANDARD.md +98 -0
  17. package/docs/ENGINE_CATALOG.md +94 -79
  18. package/docs/RELEASE_NOTES_v2.14.0.md +77 -0
  19. package/engines/specs/clinicaltrials.yaml +8 -0
  20. package/engines/specs/cnii.yaml +5 -0
  21. package/engines/specs/coingecko.yaml +10 -2
  22. package/engines/specs/dbpedia.yaml +32 -0
  23. package/engines/specs/fourget.yaml +23 -0
  24. package/engines/specs/grep_app.yaml +19 -0
  25. package/engines/specs/hackernews.yaml +1 -0
  26. package/engines/specs/hf_papers.yaml +26 -0
  27. package/engines/specs/kaggle.yaml +44 -0
  28. package/engines/specs/local_baidu.yaml +5 -0
  29. package/engines/specs/local_seek.yaml +34 -0
  30. package/engines/specs/local_yandex.yaml +37 -0
  31. package/engines/specs/mojeek.yaml +31 -0
  32. package/engines/specs/mwmbl.yaml +39 -0
  33. package/engines/specs/openaire.yaml +34 -0
  34. package/engines/specs/repology.yaml +18 -0
  35. package/package.json +13 -10
  36. package/packages/dsh-plugin/dsh/client.js +1 -0
  37. package/packages/dsh-plugin/dsh/native-tools.mjs +24 -3
  38. package/packages/dsh-plugin/dsh/runner.js +35 -1
  39. package/packages/dsh-plugin/dsh/specs.js +3 -1
  40. package/packages/dsh-plugin/dsh/wide-research.js +4 -2
  41. package/packages/dsh-plugin/package.json +1 -1
  42. package/packages/dsh-plugin/test/client.test.js +6 -0
  43. package/packages/dsh-plugin/test/config.test.js +5 -1
  44. package/packages/dsh-plugin/test/index.test.js +3 -1
  45. package/packages/dsh-plugin/test/size-gate.test.js +2 -2
  46. package/scripts/badcase_causes.py +81 -0
  47. package/scripts/badcase_ledger.py +287 -14
  48. package/scripts/cache.py +3 -3
  49. package/scripts/check_commit_report.py +168 -0
  50. package/scripts/engine_admission.py +9 -5
  51. package/scripts/engine_families.py +13 -2
  52. package/scripts/engine_policy.py +1 -1
  53. package/scripts/engine_states.py +393 -8
  54. package/scripts/engine_status.py +31 -0
  55. package/scripts/engine_validate.py +47 -39
  56. package/scripts/engines.py +6 -0
  57. package/scripts/engines_base.py +26 -80
  58. package/scripts/engines_builders.py +5 -0
  59. package/scripts/engines_builders_batch12.py +168 -0
  60. package/scripts/engines_builders_batch16.py +186 -0
  61. package/scripts/engines_parsers.py +399 -0
  62. package/scripts/fetch_browser.py +4 -2
  63. package/scripts/fetch_jsrun.py +2 -1
  64. package/scripts/fetch_v3.py +22 -22
  65. package/scripts/gen_native_tools.py +44 -17
  66. package/scripts/local_intent.py +139 -0
  67. package/scripts/local_seek.py +223 -91
  68. package/scripts/local_seek_adapter.py +87 -0
  69. package/scripts/mcp_transport.py +1 -1
  70. package/scripts/pre-commit +44 -1
  71. package/scripts/recovery.py +14 -5
  72. package/scripts/recovery_l0.py +5 -3
  73. package/scripts/research.py +1 -1
  74. package/scripts/research_gates.py +3 -3
  75. package/scripts/route_lang.py +6 -1
  76. package/scripts/route_policy.py +21 -14
  77. package/scripts/search.py +33 -25
  78. package/scripts/search_cli.py +10 -1
  79. package/scripts/search_output.py +83 -16
  80. package/scripts/source_audit.py +331 -0
  81. package/scripts/sync_backends.py +31 -1
  82. package/scripts/wechat_article.py +5 -3
  83. package/scripts/wide_research.py +4 -1
  84. package/scripts/x_article_fetch.py +2 -1
  85. package/sub-skills/local-search/parsers.py +6 -1
  86. package/sub-skills/local-seek/scripts/seek.py +390 -24
  87. package/sub-skills/local-seek/scripts/seek_fts.py +20 -9
  88. package/sub-skills/local-seek/scripts/seek_rank.py +64 -1
  89. package/engines/specs/cinii.yaml +0 -44
@@ -31,6 +31,7 @@ if str(SCRIPT_DIR) not in sys.path:
31
31
  sys.path.insert(0, str(SCRIPT_DIR))
32
32
 
33
33
  from config import load_config # noqa: E402
34
+ import engine_states # noqa: E402
34
35
  from engine_env import missing_env_for, env_ready # noqa: E402
35
36
  from engine_admission import record_validation, load_admission # noqa: E402
36
37
  from engine_status import engine_detail # noqa: E402
@@ -214,21 +215,21 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
214
215
  if not spec:
215
216
  return {
216
217
  "ok": False,
217
- "status": "error",
218
+ "status": engine_states.VALIDATION_STATUS_ERROR,
218
219
  "engine": engine_id,
219
220
  "error": "engine_not_in_config",
220
221
  }
221
222
  if not spec.get("enabled", True):
222
223
  return {
223
224
  "ok": False,
224
- "status": "skipped",
225
+ "status": engine_states.VALIDATION_STATUS_SKIPPED,
225
226
  "engine": engine_id,
226
227
  "error": "disabled_in_config",
227
228
  }
228
229
  if not env_ready(engine_id, spec):
229
230
  return {
230
231
  "ok": False,
231
- "status": "skipped",
232
+ "status": engine_states.VALIDATION_STATUS_SKIPPED,
232
233
  "engine": engine_id,
233
234
  "error": "missing_env",
234
235
  "missing_env": missing_env_for(engine_id, spec),
@@ -239,7 +240,7 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
239
240
  if engine_id not in reg:
240
241
  return {
241
242
  "ok": False,
242
- "status": "error",
243
+ "status": engine_states.VALIDATION_STATUS_ERROR,
243
244
  "engine": engine_id,
244
245
  "error": "no_builder_or_not_registered",
245
246
  "type": spec.get("type"),
@@ -259,7 +260,7 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
259
260
  except Exception as e:
260
261
  return {
261
262
  "ok": False,
262
- "status": "error",
263
+ "status": engine_states.VALIDATION_STATUS_ERROR,
263
264
  "engine": engine_id,
264
265
  "error": f"{type(e).__name__}: {e}",
265
266
  "latency_ms": round((time.time() - t0) * 1000, 1),
@@ -284,7 +285,8 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
284
285
  ok = False
285
286
  return {
286
287
  "ok": ok,
287
- "status": "pass" if ok else "fail",
288
+ "status": (engine_states.VALIDATION_STATUS_PASS if ok
289
+ else engine_states.VALIDATION_STATUS_FAIL),
288
290
  "engine": engine_id,
289
291
  "query": query,
290
292
  "count": len(results),
@@ -313,11 +315,11 @@ def run_quality(engine_id: str, *, queries: list[dict[str, str]] | None = None,
313
315
  """质量基准:多 query 空结果率、平均延迟、字段完整率。"""
314
316
  spec = _get_spec(engine_id)
315
317
  if not spec or not spec.get("enabled", True):
316
- return {"ok": False, "status": "skipped", "engine": engine_id, "error": "disabled_or_missing"}
318
+ return {"ok": False, "status": engine_states.VALIDATION_STATUS_SKIPPED, "engine": engine_id, "error": "disabled_or_missing"}
317
319
  if not env_ready(engine_id, spec):
318
320
  return {
319
321
  "ok": False,
320
- "status": "skipped",
322
+ "status": engine_states.VALIDATION_STATUS_SKIPPED,
321
323
  "engine": engine_id,
322
324
  "error": "missing_env",
323
325
  "missing_env": missing_env_for(engine_id, spec),
@@ -392,7 +394,8 @@ def run_quality(engine_id: str, *, queries: list[dict[str, str]] | None = None,
392
394
 
393
395
  return {
394
396
  "ok": ok,
395
- "status": "pass" if ok else "fail",
397
+ "status": (engine_states.VALIDATION_STATUS_PASS if ok
398
+ else engine_states.VALIDATION_STATUS_FAIL),
396
399
  "engine": engine_id,
397
400
  "quality_score": quality_score,
398
401
  "pass_rate": round(pass_rate, 3),
@@ -410,7 +413,7 @@ def run_quality(engine_id: str, *, queries: list[dict[str, str]] | None = None,
410
413
  def validate_engine(
411
414
  engine_id: str,
412
415
  *,
413
- stage: str = "health",
416
+ stage: str = engine_states.VALIDATION_STAGE_HEALTH,
414
417
  admit: bool = False,
415
418
  timeout: float = 10.0,
416
419
  write_doc: bool = False,
@@ -419,8 +422,9 @@ def validate_engine(
419
422
  """执行验证并可选写入 admission。"""
420
423
  stages = []
421
424
  if stage == "all":
422
- stages = ["health", "quality"]
423
- elif stage in ("health", "quality"):
425
+ stages = [engine_states.VALIDATION_STAGE_HEALTH,
426
+ engine_states.VALIDATION_STAGE_QUALITY]
427
+ elif stage in engine_states.VALIDATION_STAGES:
424
428
  stages = [stage]
425
429
  else:
426
430
  return {"ok": False, "error": f"unknown stage: {stage}"}
@@ -430,43 +434,44 @@ def validate_engine(
430
434
  "stage_requested": stage,
431
435
  "stages": {},
432
436
  "ok": True,
433
- "status": "pass",
437
+ "status": engine_states.VALIDATION_STATUS_PASS,
434
438
  "profile": profile,
435
439
  }
436
440
  passed: list[str] = []
437
441
  health_res = None
438
442
  quality_res = None
439
443
 
440
- if "health" in stages:
444
+ if engine_states.VALIDATION_STAGE_HEALTH in stages:
441
445
  health_res = run_health(engine_id, timeout=timeout)
442
446
  report["stages"]["health"] = health_res
443
- if health_res.get("status") == "skipped":
447
+ if health_res.get("status") == engine_states.VALIDATION_STATUS_SKIPPED:
444
448
  report["ok"] = False
445
- report["status"] = "skipped"
449
+ report["status"] = engine_states.VALIDATION_STATUS_SKIPPED
446
450
  report["skip_reason"] = health_res.get("error")
447
451
  elif health_res.get("ok"):
448
- passed.append("health")
452
+ passed.append(engine_states.VALIDATION_STAGE_HEALTH)
449
453
  else:
450
454
  report["ok"] = False
451
- report["status"] = "fail"
455
+ report["status"] = engine_states.VALIDATION_STATUS_FAIL
452
456
 
453
- if "quality" in stages and report.get("status") != "skipped":
457
+ if ("quality" in stages and report.get("status")
458
+ != engine_states.VALIDATION_STATUS_SKIPPED):
454
459
  quality_res = run_quality(engine_id, timeout=timeout, profile=profile)
455
460
  report["stages"]["quality"] = quality_res
456
- if quality_res.get("status") == "skipped":
461
+ if quality_res.get("status") == engine_states.VALIDATION_STATUS_SKIPPED:
457
462
  report["ok"] = False
458
- report["status"] = "skipped"
463
+ report["status"] = engine_states.VALIDATION_STATUS_SKIPPED
459
464
  report["skip_reason"] = quality_res.get("error")
460
465
  elif quality_res.get("ok"):
461
- passed.append("quality")
466
+ passed.append(engine_states.VALIDATION_STAGE_QUALITY)
462
467
  else:
463
468
  report["ok"] = False
464
- if report["status"] != "skipped":
465
- report["status"] = "fail"
469
+ if report["status"] != engine_states.VALIDATION_STATUS_SKIPPED:
470
+ report["status"] = engine_states.VALIDATION_STATUS_FAIL
466
471
 
467
472
  # 写 admission
468
- if report.get("status") != "skipped":
469
- blocked = not ("health" in passed)
473
+ if report.get("status") != engine_states.VALIDATION_STATUS_SKIPPED:
474
+ blocked = not (engine_states.VALIDATION_STAGE_HEALTH in passed)
470
475
  # reason 只在**被 block** 时写:它表达「为什么不能用」。
471
476
  # 未 block 时留空——`record_validation` 的不变式是
472
477
  # 「blocked=False ⇒ reason 为空」,成功路径上写
@@ -474,7 +479,8 @@ def validate_engine(
474
479
  # blocked=false/reason=validation_passed,与注释宣称的语义矛盾)。
475
480
  # 成功与否由 blocked/admitted_at/stages_passed 表达,不需要 reason。
476
481
  if blocked:
477
- reason = (health_res or {}).get("error") or "health_failed"
482
+ reason = ((health_res or {}).get("error")
483
+ or engine_states.ADMISSION_REASON_HEALTH_FAILED)
478
484
  else:
479
485
  reason = ""
480
486
  avg_lat = None
@@ -489,17 +495,17 @@ def validate_engine(
489
495
  stages_passed=passed,
490
496
  quality_score=qscore,
491
497
  avg_latency_ms=avg_lat,
492
- blocked=blocked if ("health" in stages) else None,
498
+ blocked=blocked if (engine_states.VALIDATION_STAGE_HEALTH in stages) else None,
493
499
  reason=reason,
494
500
  health=health_res,
495
501
  quality=quality_res,
496
- admit=admit and ("health" in passed),
502
+ admit=admit and (engine_states.VALIDATION_STAGE_HEALTH in passed),
497
503
  )
498
504
  report["admission"] = adm
499
505
  else:
500
506
  report["admission"] = load_admission(engine_id)
501
507
 
502
- if write_doc and report.get("status") == "pass":
508
+ if write_doc and report.get("status") == engine_states.VALIDATION_STATUS_PASS:
503
509
  path = _write_engine_doc(engine_id, report)
504
510
  report["doc_path"] = str(path)
505
511
 
@@ -514,8 +520,8 @@ def _write_engine_doc(engine_id: str, report: dict[str, Any]) -> Path:
514
520
  path = docs / f"{engine_id}.md"
515
521
  detail = report.get("detail") or engine_detail(engine_id)
516
522
  adm = report.get("admission") or {}
517
- health = (report.get("stages") or {}).get("health") or {}
518
- quality = (report.get("stages") or {}).get("quality") or {}
523
+ health = (report.get("stages") or {}).get(engine_states.VALIDATION_STAGE_HEALTH) or {}
524
+ quality = (report.get("stages") or {}).get(engine_states.VALIDATION_STAGE_QUALITY) or {}
519
525
  lines = [
520
526
  f"# 引擎:`{engine_id}`",
521
527
  "",
@@ -576,7 +582,8 @@ def _free_engine_ids() -> list[str]:
576
582
  def main() -> int:
577
583
  parser = argparse.ArgumentParser(description="Argo 引擎标准化验证")
578
584
  parser.add_argument("--engine", "-e", help="引擎 ID")
579
- parser.add_argument("--stage", default="health", choices=["health", "quality", "all"])
585
+ parser.add_argument("--stage", default=engine_states.VALIDATION_STAGE_HEALTH,
586
+ choices=[*sorted(engine_states.VALIDATION_STAGES), "all"])
580
587
  parser.add_argument("--admit", action="store_true", help="通过后写入准入状态")
581
588
  parser.add_argument("--write-doc", action="store_true", help="通过后生成 docs/engines/<id>.md")
582
589
  parser.add_argument("--timeout", type=float, default=10.0)
@@ -608,30 +615,31 @@ def main() -> int:
608
615
  stage = args.stage
609
616
  admit = args.admit
610
617
  if args.all_free and args.stage == "all" and len(targets) > 3:
611
- stage = "health"
618
+ stage = engine_states.VALIDATION_STAGE_HEALTH
612
619
  rep = validate_engine(
613
620
  eng, stage=stage, admit=admit, timeout=args.timeout,
614
621
  write_doc=args.write_doc, profile=args.profile,
615
622
  )
616
623
  reports.append(rep)
617
- if rep.get("status") == "fail":
624
+ if rep.get("status") == engine_states.VALIDATION_STATUS_FAIL:
618
625
  exit_ok = False
619
- elif args.strict and rep.get("status") != "pass":
626
+ elif (args.strict and rep.get("status")
627
+ != engine_states.VALIDATION_STATUS_PASS):
620
628
  # skipped 也是「这个源没证明自己能交付」:夜间门禁要的是
621
629
  # 11 个关键源全部 pass,缺 key/改名/禁用都不该静默全绿。
622
630
  exit_ok = False
623
631
  if not args.json:
624
632
  st = rep.get("status")
625
633
  lat = ""
626
- h = (rep.get("stages") or {}).get("health") or {}
634
+ h = (rep.get("stages") or {}).get(engine_states.VALIDATION_STAGE_HEALTH) or {}
627
635
  if h.get("latency_ms") is not None:
628
636
  lat = f" {h['latency_ms']}ms"
629
- q = (rep.get("stages") or {}).get("quality") or {}
637
+ q = (rep.get("stages") or {}).get(engine_states.VALIDATION_STAGE_QUALITY) or {}
630
638
  qnote = f" q={q.get('quality_score')}" if q else ""
631
639
  print(f"[{st}] {eng}{lat}{qnote} stages_passed={ (rep.get('admission') or {}).get('stages_passed')}")
632
640
  if rep.get("skip_reason"):
633
641
  print(f" skip: {rep['skip_reason']}")
634
- if st == "fail":
642
+ if st == engine_states.VALIDATION_STATUS_FAIL:
635
643
  err = h.get("error") or q.get("error") or rep.get("error")
636
644
  print(f" error: {err}")
637
645
 
@@ -104,6 +104,9 @@ from engines_builders import (
104
104
  _build_google_scholar_engine,
105
105
  _build_v2ex_engine,
106
106
  _build_bing_rss_engine,
107
+ _build_repology_engine,
108
+ _build_grep_app_engine,
109
+ _build_hf_papers_engine,
107
110
  _build_ths_hot_engine,
108
111
  _build_cls_telegraph_engine,
109
112
  _build_em_global_news_engine,
@@ -455,6 +458,9 @@ _BUILDERS = {
455
458
  "tracemoe": _build_tracemoe_engine,
456
459
  "pixiv": _build_pixiv_engine,
457
460
  "bing_rss": _build_bing_rss_engine,
461
+ "repology": _build_repology_engine,
462
+ "grep_app": _build_grep_app_engine,
463
+ "hf_papers": _build_hf_papers_engine,
458
464
  "ths_hot": _build_ths_hot_engine,
459
465
  "cls_telegraph": _build_cls_telegraph_engine,
460
466
  "twitter_syndication": _build_twitter_syndication_engine,
@@ -800,7 +800,18 @@ def _parse_http_payload(raw: str, fmt: str, eng: str, n: int,
800
800
  _get_logger().warning(f"HTTP 引擎业务错误: {eng} {env_err[:120]}")
801
801
  return [{"error": f"{eng} {env_err}", "source": eng}]
802
802
  limit = max(1, int(n or 5))
803
- # 专用 JSON 解析器优先(DDG Instant Answer / UAPI / Semantic Scholar 等)
803
+ # 0. 注册响应解析器优先(spec.response.parser 显式声明,P1-2)
804
+ try:
805
+ from engines_parsers import resolve as _resolve_parsers
806
+ _parsers = _resolve_parsers(spec)
807
+ if _parsers:
808
+ _cur = data
809
+ for _p in _parsers:
810
+ _cur = _p(_cur, spec)
811
+ return _apply_url_kind(_ensure_engine_source(_cur, eng)[:limit], spec)
812
+ except Exception as _pe:
813
+ _get_logger().warning(f"注册解析器失败: {eng} {_pe}")
814
+ # 1. 专用 JSON 解析器兜底(DDG Instant Answer / UAPI / Semantic Scholar 等)
804
815
  custom = _CUSTOM_JSON_PARSERS.get(eng)
805
816
  if custom:
806
817
  return _apply_url_kind(_ensure_engine_source(custom(data), eng)[:limit], spec)
@@ -860,11 +871,10 @@ def _parse_http_payload(raw: str, fmt: str, eng: str, n: int,
860
871
  parsed, eng, preserve=bool(spec.get("preserve_source"))
861
872
  )[:limit],
862
873
  spec)
863
- if isinstance(data, list):
864
- return _ensure_engine_source(
865
- _parse_generic({"results": data}, eng, limit), eng
866
- )[:limit]
867
- return _ensure_engine_source(_parse_generic(data, eng, limit), eng)[:limit]
874
+ parsed = _parse_generic(data, eng, limit, spec)
875
+ return _apply_url_kind(_ensure_engine_source(
876
+ parsed, eng, preserve=bool(spec.get("preserve_source"))
877
+ )[:limit], spec)
868
878
 
869
879
 
870
880
  # ── HTML 网页解析引擎 ─────────────────────────────────────────────────────────
@@ -1032,7 +1042,7 @@ def _build_html_engine(spec: dict[str, Any]) -> Any:
1032
1042
  containers = soup.select(container_sel)
1033
1043
  except Exception:
1034
1044
  return []
1035
- from bs4 import NavigableString
1045
+ from bs4 import Comment, NavigableString
1036
1046
 
1037
1047
  def _el_text(el) -> str:
1038
1048
  """提取元素文本。兼容 bs4 4.13+ 将页面文本标记为 TemplateString、
@@ -1046,7 +1056,10 @@ def _build_html_engine(spec: dict[str, Any]) -> Any:
1046
1056
  while stack:
1047
1057
  node = stack.pop(0)
1048
1058
  if isinstance(node, NavigableString):
1049
- parts.append(str(node))
1059
+ # Comment 是 NavigableString 子类:搜狗把内部标记写成
1060
+ # <!--awbg0--> 混进结果标题(实测 2026-11-10),剥离。
1061
+ if not isinstance(node, Comment):
1062
+ parts.append(str(node))
1050
1063
  elif hasattr(node, "contents"):
1051
1064
  stack = node.contents + stack
1052
1065
  return "".join(parts)
@@ -1248,78 +1261,11 @@ def _parse_xml(text: str, engine_name: str) -> list[dict[str, Any]]:
1248
1261
  return results
1249
1262
 
1250
1263
 
1251
- def _parse_generic(data: dict[str, Any], engine_name: str = "?",
1252
- limit: int = 10) -> list[dict[str, Any]]:
1253
- """通用 JSON 解析:自动探测常见列表路径与字段别名。
1254
-
1255
- 列表探测(最多 3 层,只走已知键):
1256
- - 顶层 results/items/data/works/search 等
1257
- - 一层嵌套(data.results / data.value)
1258
- - 二层嵌套(data.webPages.value —— 博查等 AI 搜索 API)
1259
-
1260
- 字段别名:title|name|heading;url|URL|html_url|link|href;
1261
- snippet|summary|content|description|abstract。
1262
- """
1263
- list_keys = (
1264
- "results", "items", "value", "works", "search", "data",
1265
- "organic", "webPages", "hits", "documents", "entries",
1266
- )
1267
-
1268
- def _find_items(obj: Any, depth: int = 0) -> list | None:
1269
- if depth > 3 or obj is None:
1270
- return None
1271
- if isinstance(obj, list):
1272
- # 空列表或 dict 元素列表视为结果集;纯标量列表跳过
1273
- if not obj or isinstance(obj[0], dict):
1274
- return obj
1275
- return None
1276
- if not isinstance(obj, dict):
1277
- return None
1278
- for key in list_keys:
1279
- if key not in obj:
1280
- continue
1281
- found = _find_items(obj[key], depth + 1)
1282
- if found is not None:
1283
- return found
1284
- # 浅层扫描嵌套 dict(避免深扫整棵树误抓无关数组)
1285
- if depth < 2:
1286
- for v in obj.values():
1287
- if isinstance(v, dict):
1288
- found = _find_items(v, depth + 1)
1289
- if found is not None:
1290
- return found
1291
- return None
1292
-
1293
- items = _find_items(data) if isinstance(data, (dict, list)) else None
1294
- if not items or not isinstance(items, list):
1295
- return []
1296
-
1297
- results: list[dict[str, Any]] = []
1298
- for i in items:
1299
- if not isinstance(i, dict):
1300
- continue
1301
- title = i.get("title") or i.get("name") or i.get("heading") or i.get("Title") or ""
1302
- if isinstance(title, list):
1303
- title = title[0] if title else ""
1304
- url = (
1305
- i.get("url") or i.get("URL") or i.get("html_url")
1306
- or i.get("link") or i.get("href") or ""
1307
- )
1308
- snippet = (
1309
- i.get("snippet") or i.get("summary") or i.get("content")
1310
- or i.get("description") or i.get("abstract") or ""
1311
- )
1312
- if isinstance(snippet, list):
1313
- snippet = snippet[0] if snippet else ""
1314
- score = rank_score(next((v for v in (i.get("score"), i.get("relevance_score")) if v not in (None, "")), 0.5), len(results)) # 哨兵判空:显式 0 分不得膨胀成 0.5
1315
- results.append({
1316
- "title": str(title)[:200],
1317
- "url": str(url),
1318
- "snippet": str(snippet)[:300],
1319
- "score": score,
1320
- "source": engine_name,
1321
- })
1322
- return results[:limit]
1264
+ def _parse_generic(data: dict[str, Any] | list, engine_name: str = "?",
1265
+ limit: int = 10, spec: dict[str, Any] | None = None) -> list[dict[str, Any]]:
1266
+ """通用智能推断 JSON 解析(委托 engines_parsers.parse_smart_generic)。"""
1267
+ from engines_parsers import parse_smart_generic
1268
+ return parse_smart_generic(data, engine_name, limit, spec)
1323
1269
 
1324
1270
 
1325
1271
  def _ensure_engine_source(
@@ -80,6 +80,8 @@ from engines_builders_cn import (
80
80
  from engines_builders_batch12 import (
81
81
  _build_so_engine,
82
82
  _build_shenma_engine,
83
+ _build_repology_engine,
84
+ _build_grep_app_engine,
83
85
  )
84
86
 
85
87
  from engines_builders_batch13 import (
@@ -96,6 +98,9 @@ from engines_builders_batch14 import (
96
98
  from engines_builders_batch15 import (
97
99
  _build_yuanbao_engine,
98
100
  )
101
+ from engines_builders_batch16 import (
102
+ _build_hf_papers_engine,
103
+ )
99
104
  from engines_builders_data import (
100
105
  _build_open_library_engine,
101
106
  _build_weread_engine,
@@ -13,6 +13,7 @@ tests/test_new_source_reachability.py::_DORMANT_ALLOWLIST。
13
13
 
14
14
  from __future__ import annotations
15
15
 
16
+ import json
16
17
  import logging
17
18
  import re
18
19
  import urllib.request
@@ -101,3 +102,170 @@ def _build_shenma_engine(spec: dict[str, Any]) -> Any:
101
102
  logger.warning(f"神马搜索失败: {e}")
102
103
  return []
103
104
  return _engine
105
+
106
+
107
+ # ── Repology 跨发行版包生态版本与状态真相(免认证)────────────────────
108
+
109
+ def _build_repology_engine(spec: dict[str, Any]) -> Any:
110
+ """Repology 全网 Linux/UNIX 跨包管理器生态版本真相(免认证)。
111
+
112
+ 覆盖 Debian、Arch、Nix、Alpine、Homebrew、Fedora 等数百个仓库的真实版本与生命周期状态。
113
+ """
114
+ timeout = spec.get("timeout", 10)
115
+
116
+ @safe_search
117
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
118
+ to = _timeout or timeout
119
+ cleaned = re.sub(r"[,,。?!?\s]+", " ", query or "").strip()
120
+ tokens = [t for t in cleaned.split(" ") if t and not any(w in t.lower() for w in ("包", "版本", "依赖", "软件", "package", "version"))]
121
+ q = tokens[0] if tokens else (cleaned.split(" ")[0] if cleaned else "")
122
+ if not q:
123
+ return []
124
+
125
+ import urllib.parse as up
126
+ url = f"https://repology.org/api/v1/projects/?search={up.quote(q)}"
127
+ from engines_base import _http_get_raw
128
+ raw = _http_get_raw(url, {"Accept": "application/json", "User-Agent": "Mozilla/5.0"}, to, engine="repology")
129
+ if not raw:
130
+ return []
131
+ try:
132
+ data = json.loads(raw)
133
+ except json.JSONDecodeError:
134
+ return []
135
+ if not isinstance(data, dict):
136
+ return []
137
+
138
+ results: list[dict[str, Any]] = []
139
+ for proj_name, entries in list(data.items())[:n]:
140
+ if not isinstance(entries, list) or not entries:
141
+ continue
142
+ newest_ver = ""
143
+ repos_summary = []
144
+ for item in entries:
145
+ if not isinstance(item, dict):
146
+ continue
147
+ v = item.get("version") or ""
148
+ repo = item.get("repo") or ""
149
+ status = item.get("status") or ""
150
+ if status == "newest" and not newest_ver:
151
+ newest_ver = v
152
+ if any(k in repo for k in ("debian", "arch", "nix", "homebrew", "alpine", "fedora", "ubuntu")):
153
+ if len(repos_summary) < 4:
154
+ repos_summary.append(f"{repo}: {v}")
155
+ if not newest_ver and entries:
156
+ newest_ver = entries[0].get("version", "?")
157
+
158
+ repo_text = " · ".join(repos_summary) if repos_summary else f"共收录于 {len(entries)} 个仓库"
159
+ snippet = f"最新版本: {newest_ver} | 主要发行版: {repo_text}"
160
+ results.append({
161
+ "title": f"{proj_name} (Repology 跨发行版包详情)",
162
+ "url": f"https://repology.org/project/{proj_name}/versions",
163
+ "snippet": snippet,
164
+ "source": "repology",
165
+ })
166
+ return results
167
+ return _engine
168
+
169
+
170
+ # ── Grep.app 全球百万 GitHub 核心代码正则检索(官方 MCP 传输免认证)─────
171
+
172
+ _GREP_APP_MCP_URL = "https://mcp.grep.app"
173
+
174
+
175
+ def _build_grep_app_engine(spec: dict[str, Any]) -> Any:
176
+ """Grep.app 全网开源代码精准检索引擎(官方 MCP 通道,免认证)。
177
+
178
+ 通过官方 MCP 端点直接调用 searchGitHub,避开常规前端 WAF 挑战,
179
+ 支持字面量代码匹配与正则搜索,返回包含仓库、文件路径与行号的真实代码片段。
180
+ """
181
+ timeout = spec.get("timeout", 10)
182
+
183
+ @safe_search
184
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
185
+ to = _timeout or timeout
186
+ q = (query or "").strip()
187
+ if not q:
188
+ return []
189
+
190
+ from engines_builders_tech import _parse_mcp_wire, _mcp_error_of
191
+
192
+ payload = {
193
+ "jsonrpc": "2.0",
194
+ "id": 1,
195
+ "method": "tools/call",
196
+ "params": {
197
+ "name": "searchGitHub",
198
+ "arguments": {
199
+ "query": q,
200
+ },
201
+ },
202
+ }
203
+ body = json.dumps(payload).encode("utf-8")
204
+ headers = {
205
+ "Content-Type": "application/json",
206
+ "Accept": "application/json, text/event-stream",
207
+ "User-Agent": (
208
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
209
+ "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
210
+ ),
211
+ }
212
+
213
+ req = urllib.request.Request(_GREP_APP_MCP_URL, data=body, headers=headers)
214
+ try:
215
+ with http_open(req, timeout=to, engine=spec.get("_name", "grep_app")) as resp:
216
+ raw = resp.read().decode("utf-8", "replace")
217
+ except Exception as e:
218
+ logger.warning(f"grep_app MCP 请求失败: {e}")
219
+ return []
220
+
221
+ data = _parse_mcp_wire(raw)
222
+ if not isinstance(data, dict):
223
+ return []
224
+
225
+ mcp_err = _mcp_error_of(data)
226
+ if mcp_err:
227
+ logger.warning(f"grep_app MCP 上游错误: {mcp_err}")
228
+ return []
229
+
230
+ result = data.get("result")
231
+ if not isinstance(result, dict):
232
+ return []
233
+
234
+ content = result.get("content") or []
235
+ results: list[dict[str, Any]] = []
236
+
237
+ for item in content:
238
+ if not isinstance(item, dict):
239
+ continue
240
+ text = item.get("text") or ""
241
+ if not text:
242
+ continue
243
+
244
+ repo_m = re.search(r"Repository:\s*(\S+)", text)
245
+ path_m = re.search(r"Path:\s*(\S+)", text)
246
+ url_m = re.search(r"URL:\s*(\S+)", text)
247
+ snip_m = re.search(r"Snippets:\s*(.*)", text, re.S)
248
+
249
+ repo = repo_m.group(1) if repo_m else ""
250
+ path = path_m.group(1) if path_m else ""
251
+ url = url_m.group(1) if url_m else ""
252
+ snippet = snip_m.group(1).strip() if snip_m else text[:250]
253
+
254
+ if not url:
255
+ continue
256
+
257
+ title = f"{repo}: {path}" if repo and path else (path or repo or "code snippet")
258
+ results.append({
259
+ "title": title,
260
+ "url": url,
261
+ "snippet": snippet[:350],
262
+ "source": "grep_app",
263
+ })
264
+ if len(results) >= n:
265
+ break
266
+
267
+ return results
268
+
269
+ return _engine
270
+
271
+