argo-search 2.13.0 → 2.14.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 (129) hide show
  1. package/AGENTS.md +93 -0
  2. package/README.es.md +30 -8
  3. package/README.ja.md +30 -8
  4. package/README.ko.md +30 -8
  5. package/README.md +511 -596
  6. package/README.zh.md +975 -0
  7. package/SKILL.md +1 -1
  8. package/assets/readme/counts.json +1 -1
  9. package/backends/domain_profiles.json +90 -6
  10. package/backends/engine_registry.yaml +222 -32
  11. package/backends/env_passthrough.txt +2 -0
  12. package/backends/quota_profiles.json +151 -11
  13. package/bin/argo +3 -0
  14. package/config.yaml +50 -4
  15. package/docs/CHANGELOG.md +45 -0
  16. package/docs/COMMIT_STANDARD.md +98 -0
  17. package/docs/ENGINE_CATALOG.md +100 -81
  18. package/docs/MCP_SETUP.md +1 -1
  19. package/docs/RELEASE_NOTES_v2.14.0.md +88 -0
  20. package/docs/RELEASE_NOTES_v2.14.1.md +80 -0
  21. package/docs/RELEASING.md +52 -0
  22. package/engines/specs/artic.yaml +11 -1
  23. package/engines/specs/cleveland.yaml +15 -1
  24. package/engines/specs/clinicaltrials.yaml +24 -1
  25. package/engines/specs/cnii.yaml +17 -1
  26. package/engines/specs/coingecko.yaml +10 -2
  27. package/engines/specs/dbpedia.yaml +32 -0
  28. package/engines/specs/deezer.yaml +12 -1
  29. package/engines/specs/doaj.yaml +14 -1
  30. package/engines/specs/endoflife.yaml +16 -1
  31. package/engines/specs/eu_opendata.yaml +11 -1
  32. package/engines/specs/europeana.yaml +19 -1
  33. package/engines/specs/feed.yaml +62 -0
  34. package/engines/specs/figshare.yaml +12 -1
  35. package/engines/specs/fourget.yaml +23 -0
  36. package/engines/specs/grep_app.yaml +19 -0
  37. package/engines/specs/hackernews.yaml +17 -1
  38. package/engines/specs/hal.yaml +19 -1
  39. package/engines/specs/hf_datasets.yaml +59 -0
  40. package/engines/specs/hf_papers.yaml +42 -0
  41. package/engines/specs/jikan.yaml +12 -10
  42. package/engines/specs/kaggle.yaml +46 -0
  43. package/engines/specs/local_baidu.yaml +5 -0
  44. package/engines/specs/local_seek.yaml +34 -0
  45. package/engines/specs/local_yandex.yaml +37 -0
  46. package/engines/specs/maven.yaml +61 -0
  47. package/engines/specs/mojeek.yaml +31 -0
  48. package/engines/specs/mwmbl.yaml +39 -0
  49. package/engines/specs/nasa_cmr.yaml +12 -1
  50. package/engines/specs/nuget.yaml +57 -0
  51. package/engines/specs/openaire.yaml +34 -0
  52. package/engines/specs/repology.yaml +18 -0
  53. package/engines/specs/tatoeba.yaml +14 -1
  54. package/engines/specs/tvmaze.yaml +5 -1
  55. package/engines/specs/usda.yaml +14 -1
  56. package/package.json +14 -10
  57. package/packages/dsh-plugin/dsh/client.js +1 -0
  58. package/packages/dsh-plugin/dsh/native-tools.mjs +85 -116
  59. package/packages/dsh-plugin/dsh/runner.js +35 -1
  60. package/packages/dsh-plugin/dsh/specs.js +3 -1
  61. package/packages/dsh-plugin/dsh/wide-research.js +5 -3
  62. package/packages/dsh-plugin/package.json +1 -1
  63. package/packages/dsh-plugin/test/client.test.js +6 -0
  64. package/packages/dsh-plugin/test/config.test.js +5 -1
  65. package/packages/dsh-plugin/test/index.test.js +3 -1
  66. package/packages/dsh-plugin/test/size-gate.test.js +2 -2
  67. package/scripts/badcase_causes.py +81 -0
  68. package/scripts/badcase_ledger.py +336 -19
  69. package/scripts/build_release_assets.sh +43 -15
  70. package/scripts/cache.py +3 -3
  71. package/scripts/check_commit_report.py +168 -0
  72. package/scripts/dormant_ledger.py +225 -0
  73. package/scripts/engine_admission.py +9 -5
  74. package/scripts/engine_families.py +13 -2
  75. package/scripts/engine_policy.py +1 -1
  76. package/scripts/engine_states.py +398 -8
  77. package/scripts/engine_status.py +31 -0
  78. package/scripts/engine_validate.py +224 -40
  79. package/scripts/engines.py +4 -34
  80. package/scripts/engines_base.py +53 -147
  81. package/scripts/engines_builders.py +2 -33
  82. package/scripts/engines_builders_batch12.py +168 -0
  83. package/scripts/engines_builders_batch16.py +13 -0
  84. package/scripts/engines_builders_batch9.py +0 -204
  85. package/scripts/engines_builders_feeds.py +148 -30
  86. package/scripts/engines_builders_intl.py +0 -328
  87. package/scripts/engines_builders_science.py +0 -85
  88. package/scripts/engines_builders_tech.py +0 -98
  89. package/scripts/engines_parsers.py +924 -0
  90. package/scripts/evidence_loop.py +91 -4
  91. package/scripts/fetch_browser.py +4 -2
  92. package/scripts/fetch_jsrun.py +2 -1
  93. package/scripts/fetch_v3.py +22 -22
  94. package/scripts/gen_engine_catalog.py +2 -2
  95. package/scripts/gen_native_tools.py +46 -18
  96. package/scripts/local_intent.py +175 -0
  97. package/scripts/local_seek.py +256 -91
  98. package/scripts/local_seek_adapter.py +87 -0
  99. package/scripts/mcp_handlers.py +124 -72
  100. package/scripts/mcp_server.py +1 -1
  101. package/scripts/mcp_tools.py +143 -61
  102. package/scripts/mcp_transport.py +42 -10
  103. package/scripts/pre-commit +68 -1
  104. package/scripts/recovery.py +14 -5
  105. package/scripts/recovery_l0.py +5 -3
  106. package/scripts/release.py +20 -11
  107. package/scripts/release_check.py +1 -1
  108. package/scripts/research.py +1 -1
  109. package/scripts/research_gates.py +3 -3
  110. package/scripts/route_lang.py +6 -1
  111. package/scripts/route_policy.py +26 -14
  112. package/scripts/search.py +33 -25
  113. package/scripts/search_cli.py +52 -6
  114. package/scripts/search_output.py +83 -16
  115. package/scripts/secret_guard.py +106 -0
  116. package/scripts/semantic_evidence.py +230 -15
  117. package/scripts/settings_page.py +80 -8
  118. package/scripts/source_audit.py +408 -0
  119. package/scripts/sync_backends.py +38 -1
  120. package/scripts/wechat_article.py +5 -3
  121. package/scripts/wide_research.py +4 -1
  122. package/scripts/x_article_fetch.py +2 -1
  123. package/sub-skills/local-search/parsers.py +6 -1
  124. package/sub-skills/local-seek/scripts/seek.py +390 -24
  125. package/sub-skills/local-seek/scripts/seek_fts.py +28 -9
  126. package/sub-skills/local-seek/scripts/seek_rank.py +64 -1
  127. package/README.en.md +0 -814
  128. package/engines/specs/cinii.yaml +0 -44
  129. package/scripts/image_vision/vision_probe +0 -0
@@ -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
@@ -38,6 +39,11 @@ from cli_io import dumps
38
39
 
39
40
  REQUIRED_KEYS = ("title", "url", "source")
40
41
 
42
+ # --apply 的最低置信度:diagnose_schema_drift 对「容器位移或 title+url 同时
43
+ # 命中」给 0.95,对「单字段启发式猜测」给 0.80。后者不足以自动改写 Spec
44
+ # 真源——改错了没有回滚凭据,必须留给人核对 suggested_patch。
45
+ _APPLY_MIN_CONFIDENCE = 0.95
46
+
41
47
  # 垂类引擎 health canary(通用词会误杀快讯/行情类)
42
48
  ENGINE_CANARY_QUERIES: dict[str, str] = {
43
49
  "fxtwitter": "OpenAI",
@@ -214,21 +220,21 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
214
220
  if not spec:
215
221
  return {
216
222
  "ok": False,
217
- "status": "error",
223
+ "status": engine_states.VALIDATION_STATUS_ERROR,
218
224
  "engine": engine_id,
219
225
  "error": "engine_not_in_config",
220
226
  }
221
227
  if not spec.get("enabled", True):
222
228
  return {
223
229
  "ok": False,
224
- "status": "skipped",
230
+ "status": engine_states.VALIDATION_STATUS_SKIPPED,
225
231
  "engine": engine_id,
226
232
  "error": "disabled_in_config",
227
233
  }
228
234
  if not env_ready(engine_id, spec):
229
235
  return {
230
236
  "ok": False,
231
- "status": "skipped",
237
+ "status": engine_states.VALIDATION_STATUS_SKIPPED,
232
238
  "engine": engine_id,
233
239
  "error": "missing_env",
234
240
  "missing_env": missing_env_for(engine_id, spec),
@@ -239,7 +245,7 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
239
245
  if engine_id not in reg:
240
246
  return {
241
247
  "ok": False,
242
- "status": "error",
248
+ "status": engine_states.VALIDATION_STATUS_ERROR,
243
249
  "engine": engine_id,
244
250
  "error": "no_builder_or_not_registered",
245
251
  "type": spec.get("type"),
@@ -259,7 +265,7 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
259
265
  except Exception as e:
260
266
  return {
261
267
  "ok": False,
262
- "status": "error",
268
+ "status": engine_states.VALIDATION_STATUS_ERROR,
263
269
  "engine": engine_id,
264
270
  "error": f"{type(e).__name__}: {e}",
265
271
  "latency_ms": round((time.time() - t0) * 1000, 1),
@@ -284,7 +290,8 @@ def run_health(engine_id: str, *, query: str | None = None, n: int = 3,
284
290
  ok = False
285
291
  return {
286
292
  "ok": ok,
287
- "status": "pass" if ok else "fail",
293
+ "status": (engine_states.VALIDATION_STATUS_PASS if ok
294
+ else engine_states.VALIDATION_STATUS_FAIL),
288
295
  "engine": engine_id,
289
296
  "query": query,
290
297
  "count": len(results),
@@ -313,11 +320,11 @@ def run_quality(engine_id: str, *, queries: list[dict[str, str]] | None = None,
313
320
  """质量基准:多 query 空结果率、平均延迟、字段完整率。"""
314
321
  spec = _get_spec(engine_id)
315
322
  if not spec or not spec.get("enabled", True):
316
- return {"ok": False, "status": "skipped", "engine": engine_id, "error": "disabled_or_missing"}
323
+ return {"ok": False, "status": engine_states.VALIDATION_STATUS_SKIPPED, "engine": engine_id, "error": "disabled_or_missing"}
317
324
  if not env_ready(engine_id, spec):
318
325
  return {
319
326
  "ok": False,
320
- "status": "skipped",
327
+ "status": engine_states.VALIDATION_STATUS_SKIPPED,
321
328
  "engine": engine_id,
322
329
  "error": "missing_env",
323
330
  "missing_env": missing_env_for(engine_id, spec),
@@ -392,7 +399,8 @@ def run_quality(engine_id: str, *, queries: list[dict[str, str]] | None = None,
392
399
 
393
400
  return {
394
401
  "ok": ok,
395
- "status": "pass" if ok else "fail",
402
+ "status": (engine_states.VALIDATION_STATUS_PASS if ok
403
+ else engine_states.VALIDATION_STATUS_FAIL),
396
404
  "engine": engine_id,
397
405
  "quality_score": quality_score,
398
406
  "pass_rate": round(pass_rate, 3),
@@ -407,20 +415,117 @@ def run_quality(engine_id: str, *, queries: list[dict[str, str]] | None = None,
407
415
  }
408
416
 
409
417
 
418
+ def family_claim_missing(engine_id: str, spec: dict[str, Any]) -> bool:
419
+ """family 判定(单引擎口径,准入与全局测试同消费这一份)。"""
420
+ from engine_families import _ENGINE_FAMILY_OVERRIDES
421
+ return not (spec.get("family") or engine_id in _ENGINE_FAMILY_OVERRIDES)
422
+
423
+
424
+ def check_contracts(engine_id: str) -> list[str]:
425
+ """清单契约检查(准入时点可判定的静态对账):family 显式声明 + skill_registry。
426
+
427
+ 单一真源:判定逻辑提炼自 tests/test_engine_families.py 与
428
+ tests/test_skill_registry_contract.py,那两个测试改为对本函数对拍——
429
+ 防止「测试一套判定、准入另一套」漂移。休眠台账不同:它要到引擎被排进
430
+ 域 combo 之后才可判定,归 sync_backends.check_dormant_ledger(domains
431
+ 变更后跑 sync 即发现)。
432
+ """
433
+ issues: list[str] = []
434
+ cfg = load_config()
435
+ engines_map = cfg.get("engines") or {}
436
+ spec = engines_map.get(engine_id)
437
+ if spec is None:
438
+ try:
439
+ from config import get_engines
440
+ spec = get_engines(cfg, routable_only=False).get(engine_id)
441
+ except Exception:
442
+ spec = None
443
+ if spec is None:
444
+ return [f"engine {engine_id} 不在 config.yaml engines 里,清单契约无从检查"]
445
+ # 1) family 必须显式声明(不许静默落到默认 web_general)
446
+ if family_claim_missing(engine_id, spec):
447
+ issues.append(
448
+ "缺 family 显式声明:补 config.yaml 的 family 字段或 "
449
+ "engine_families._ENGINE_FAMILY_OVERRIDES 覆盖表")
450
+ # 2) coverage 声明 skill(config 原始或 specs 文件任一)→ 常量必须同步
451
+ has_skill = "skill" in (spec.get("coverage") or [])
452
+ if not has_skill:
453
+ spec_path = ROOT / "engines" / "specs" / f"{engine_id}.yaml"
454
+ if spec_path.exists():
455
+ from yaml_load import load as _yaml_load
456
+ raw = _yaml_load(str(spec_path)) or {}
457
+ has_skill = "skill" in (raw.get("coverage") or [])
458
+ if has_skill:
459
+ from candidate_envelope import SKILL_REGISTRY_ENGINES
460
+ if engine_id not in SKILL_REGISTRY_ENGINES:
461
+ issues.append(
462
+ "spec coverage 声明了 skill,但 candidate_envelope."
463
+ "SKILL_REGISTRY_ENGINES 未含本引擎——新增技能目录源时两边要一起改")
464
+ return issues
465
+
466
+
467
+ def probe_engine_raw(engine_id: str, query: str = "test", timeout: float = 10.0) -> Any:
468
+ """对 HTTP 引擎发起一次探测请求,返回解析后的原生 JSON 结构(供结构漂移诊断用)。"""
469
+ import urllib.request as _urllib_request
470
+ import urllib.parse as _up
471
+ import json as _json
472
+
473
+ spec = _get_spec(engine_id)
474
+ if not spec or spec.get("type") != "http":
475
+ return None
476
+ url_template = spec.get("url", "")
477
+ if not url_template:
478
+ return None
479
+
480
+ query_param = spec.get("query_param", "q")
481
+ extra_params = spec.get("extra_params", {})
482
+ headers = dict(spec.get("headers", {}))
483
+ headers.setdefault("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)")
484
+ headers.setdefault("Accept", "application/json")
485
+
486
+ parts: list[str] = []
487
+ if query_param:
488
+ parts.append(f"{query_param}={_up.quote(query)}")
489
+ for k, v in extra_params.items():
490
+ parts.append(f"{k}={_up.quote(str(v))}")
491
+
492
+ sep = "&" if "?" in url_template else "?"
493
+ full_url = url_template + (sep + "&".join(parts) if parts else "")
494
+ try:
495
+ req = _urllib_request.Request(full_url, headers=headers)
496
+ # 走代理感知出口(net_proxy.open_url)而非裸 urlopen:后者不认
497
+ # config.yaml 的 network.proxy,在必须经代理出网的环境里会连不上
498
+ # (issue #13 同类)。全仓门禁 test_http_attribution 会扫裸 urlopen。
499
+ from net_proxy import open_url as _open_url
500
+ with _open_url(req, timeout=timeout) as resp:
501
+ raw = resp.read().decode("utf-8", errors="replace")
502
+ return _json.loads(raw)
503
+ except Exception:
504
+ return None
505
+
506
+
410
507
  def validate_engine(
411
508
  engine_id: str,
412
509
  *,
413
- stage: str = "health",
510
+ stage: str = engine_states.VALIDATION_STAGE_HEALTH,
414
511
  admit: bool = False,
415
512
  timeout: float = 10.0,
416
513
  write_doc: bool = False,
417
514
  profile: str = "default",
515
+ diagnose: bool = False,
516
+ apply: bool = False,
418
517
  ) -> dict[str, Any]:
419
- """执行验证并可选写入 admission。"""
518
+ """执行验证并可选写入 admission。
519
+
520
+ apply:是否把结构漂移诊断建议的 output_map 补丁**写回 Spec 真源**。
521
+ 默认 False 只输出预览(report["suggested_patch"]),不碰磁盘。
522
+ """
420
523
  stages = []
421
524
  if stage == "all":
422
- stages = ["health", "quality"]
423
- elif stage in ("health", "quality"):
525
+ stages = [engine_states.VALIDATION_STAGE_CONTRACT,
526
+ engine_states.VALIDATION_STAGE_HEALTH,
527
+ engine_states.VALIDATION_STAGE_QUALITY]
528
+ elif stage in engine_states.VALIDATION_STAGES:
424
529
  stages = [stage]
425
530
  else:
426
531
  return {"ok": False, "error": f"unknown stage: {stage}"}
@@ -430,43 +535,59 @@ def validate_engine(
430
535
  "stage_requested": stage,
431
536
  "stages": {},
432
537
  "ok": True,
433
- "status": "pass",
538
+ "status": engine_states.VALIDATION_STATUS_PASS,
434
539
  "profile": profile,
435
540
  }
436
541
  passed: list[str] = []
437
542
  health_res = None
438
543
  quality_res = None
439
544
 
440
- if "health" in stages:
545
+ # contract 先于 health/quality:纯静态毫秒级,失败即短路——「先查声明
546
+ # 再测行为」,清单缺口不必烧网络探针。
547
+ contract_issues: list[str] = []
548
+ if engine_states.VALIDATION_STAGE_CONTRACT in stages:
549
+ contract_issues = check_contracts(engine_id)
550
+ report["stages"]["contract"] = {"ok": not contract_issues,
551
+ "issues": contract_issues}
552
+ if contract_issues:
553
+ report["ok"] = False
554
+ report["status"] = engine_states.VALIDATION_STATUS_FAIL
555
+ stages = [s for s in stages
556
+ if s == engine_states.VALIDATION_STAGE_CONTRACT]
557
+ else:
558
+ passed.append(engine_states.VALIDATION_STAGE_CONTRACT)
559
+
560
+ if engine_states.VALIDATION_STAGE_HEALTH in stages:
441
561
  health_res = run_health(engine_id, timeout=timeout)
442
562
  report["stages"]["health"] = health_res
443
- if health_res.get("status") == "skipped":
563
+ if health_res.get("status") == engine_states.VALIDATION_STATUS_SKIPPED:
444
564
  report["ok"] = False
445
- report["status"] = "skipped"
565
+ report["status"] = engine_states.VALIDATION_STATUS_SKIPPED
446
566
  report["skip_reason"] = health_res.get("error")
447
567
  elif health_res.get("ok"):
448
- passed.append("health")
568
+ passed.append(engine_states.VALIDATION_STAGE_HEALTH)
449
569
  else:
450
570
  report["ok"] = False
451
- report["status"] = "fail"
571
+ report["status"] = engine_states.VALIDATION_STATUS_FAIL
452
572
 
453
- if "quality" in stages and report.get("status") != "skipped":
573
+ if ("quality" in stages and report.get("status")
574
+ != engine_states.VALIDATION_STATUS_SKIPPED):
454
575
  quality_res = run_quality(engine_id, timeout=timeout, profile=profile)
455
576
  report["stages"]["quality"] = quality_res
456
- if quality_res.get("status") == "skipped":
577
+ if quality_res.get("status") == engine_states.VALIDATION_STATUS_SKIPPED:
457
578
  report["ok"] = False
458
- report["status"] = "skipped"
579
+ report["status"] = engine_states.VALIDATION_STATUS_SKIPPED
459
580
  report["skip_reason"] = quality_res.get("error")
460
581
  elif quality_res.get("ok"):
461
- passed.append("quality")
582
+ passed.append(engine_states.VALIDATION_STAGE_QUALITY)
462
583
  else:
463
584
  report["ok"] = False
464
- if report["status"] != "skipped":
465
- report["status"] = "fail"
585
+ if report["status"] != engine_states.VALIDATION_STATUS_SKIPPED:
586
+ report["status"] = engine_states.VALIDATION_STATUS_FAIL
466
587
 
467
588
  # 写 admission
468
- if report.get("status") != "skipped":
469
- blocked = not ("health" in passed)
589
+ if report.get("status") != engine_states.VALIDATION_STATUS_SKIPPED:
590
+ blocked = not (engine_states.VALIDATION_STAGE_HEALTH in passed)
470
591
  # reason 只在**被 block** 时写:它表达「为什么不能用」。
471
592
  # 未 block 时留空——`record_validation` 的不变式是
472
593
  # 「blocked=False ⇒ reason 为空」,成功路径上写
@@ -474,7 +595,9 @@ def validate_engine(
474
595
  # blocked=false/reason=validation_passed,与注释宣称的语义矛盾)。
475
596
  # 成功与否由 blocked/admitted_at/stages_passed 表达,不需要 reason。
476
597
  if blocked:
477
- reason = (health_res or {}).get("error") or "health_failed"
598
+ reason = (contract_issues[0] if contract_issues
599
+ else (health_res or {}).get("error")
600
+ or engine_states.ADMISSION_REASON_HEALTH_FAILED)
478
601
  else:
479
602
  reason = ""
480
603
  avg_lat = None
@@ -489,20 +612,59 @@ def validate_engine(
489
612
  stages_passed=passed,
490
613
  quality_score=qscore,
491
614
  avg_latency_ms=avg_lat,
492
- blocked=blocked if ("health" in stages) else None,
615
+ # contract 失败必须显式 block:此时 passed 为空,record 默认分支
616
+ # 会把「空 passed」当不表态(blocked=False)——清单缺口就漏过去了
617
+ blocked=(True if contract_issues else
618
+ (blocked if (engine_states.VALIDATION_STAGE_HEALTH in stages)
619
+ else None)),
493
620
  reason=reason,
494
621
  health=health_res,
495
622
  quality=quality_res,
496
- admit=admit and ("health" in passed),
623
+ admit=admit and not contract_issues
624
+ and (engine_states.VALIDATION_STAGE_HEALTH in passed),
497
625
  )
498
626
  report["admission"] = adm
499
627
  else:
500
628
  report["admission"] = load_admission(engine_id)
501
629
 
502
- if write_doc and report.get("status") == "pass":
630
+ if write_doc and report.get("status") == engine_states.VALIDATION_STATUS_PASS:
503
631
  path = _write_engine_doc(engine_id, report)
504
632
  report["doc_path"] = str(path)
505
633
 
634
+ # 结构漂移自省对拍(针对声明式 HTTP 源)
635
+ # --fix 是预览态:诊断结果进 report 供人过目,不写盘。
636
+ # --apply 才落盘,且要过置信度门槛——启发式选出的 0.80 建议不能
637
+ # 自动改写唯一真源 Spec(改错了没有回滚凭据)。
638
+ spec = _get_spec(engine_id)
639
+ if (diagnose or apply or (report.get("status") == engine_states.VALIDATION_STATUS_FAIL
640
+ and spec.get("type") == "http")):
641
+ if spec.get("type") == "http" and (spec.get("output_map") or spec.get("response")):
642
+ try:
643
+ from engines_parsers import diagnose_schema_drift, apply_schema_patch
644
+ canary = spec.get("canary_query") or ENGINE_CANARY_QUERIES.get(engine_id) or "test"
645
+ raw_data = probe_engine_raw(engine_id, query=canary, timeout=timeout)
646
+ if raw_data is not None:
647
+ drift_diag = diagnose_schema_drift(raw_data, spec)
648
+ report["schema_drift"] = drift_diag
649
+ suggested = drift_diag.get("suggested_patch") or {}
650
+ if suggested:
651
+ report["suggested_patch"] = suggested
652
+ if apply and drift_diag.get("drift_detected") and suggested:
653
+ confidence = float(drift_diag.get("confidence") or 0.0)
654
+ if confidence >= _APPLY_MIN_CONFIDENCE:
655
+ spec_path = ROOT / "engines" / "specs" / f"{engine_id}.yaml"
656
+ ok, msg = apply_schema_patch(spec_path, suggested)
657
+ if ok:
658
+ report["fix_applied"] = True
659
+ report["fix_msg"] = msg
660
+ else:
661
+ report["fix_blocked_low_confidence"] = True
662
+ report["fix_msg"] = (
663
+ f"置信度 {confidence:.0%} 低于 {_APPLY_MIN_CONFIDENCE:.0%},"
664
+ "不自动改写 Spec;请人工核对 suggested_patch 后手动更新")
665
+ except Exception as _ex:
666
+ report["schema_drift_error"] = str(_ex)
667
+
506
668
  report["detail"] = engine_detail(engine_id)
507
669
  return report
508
670
 
@@ -514,8 +676,8 @@ def _write_engine_doc(engine_id: str, report: dict[str, Any]) -> Path:
514
676
  path = docs / f"{engine_id}.md"
515
677
  detail = report.get("detail") or engine_detail(engine_id)
516
678
  adm = report.get("admission") or {}
517
- health = (report.get("stages") or {}).get("health") or {}
518
- quality = (report.get("stages") or {}).get("quality") or {}
679
+ health = (report.get("stages") or {}).get(engine_states.VALIDATION_STAGE_HEALTH) or {}
680
+ quality = (report.get("stages") or {}).get(engine_states.VALIDATION_STAGE_QUALITY) or {}
519
681
  lines = [
520
682
  f"# 引擎:`{engine_id}`",
521
683
  "",
@@ -576,7 +738,8 @@ def _free_engine_ids() -> list[str]:
576
738
  def main() -> int:
577
739
  parser = argparse.ArgumentParser(description="Argo 引擎标准化验证")
578
740
  parser.add_argument("--engine", "-e", help="引擎 ID")
579
- parser.add_argument("--stage", default="health", choices=["health", "quality", "all"])
741
+ parser.add_argument("--stage", default=engine_states.VALIDATION_STAGE_HEALTH,
742
+ choices=[*sorted(engine_states.VALIDATION_STAGES), "all"])
580
743
  parser.add_argument("--admit", action="store_true", help="通过后写入准入状态")
581
744
  parser.add_argument("--write-doc", action="store_true", help="通过后生成 docs/engines/<id>.md")
582
745
  parser.add_argument("--timeout", type=float, default=10.0)
@@ -589,6 +752,15 @@ def main() -> int:
589
752
  "--strict", action="store_true",
590
753
  help="skipped(缺 key/被禁用/源改名)也算失败——夜间交付门禁用。"
591
754
  "默认宽松:批量体检时跳过未配置的源不是故障。")
755
+ parser.add_argument("--diagnose", action="store_true",
756
+ help="对声明式 HTTP 引擎执行深入结构漂移诊断")
757
+ parser.add_argument("--fix", dest="fix_preview", action="store_true",
758
+ help="诊断并输出建议的 output_map 补丁(预览,不写盘);"
759
+ "等同于 --diagnose,保留旧命令名")
760
+ parser.add_argument("--apply", action="store_true",
761
+ help="将建议的 output_map 补丁写入对应 Spec 文件"
762
+ "(需置信度不低于 95 个百分点);"
763
+ "不显式给这个参数就绝不改写真源")
592
764
  args = parser.parse_args()
593
765
 
594
766
  targets: list[str] = []
@@ -608,32 +780,44 @@ def main() -> int:
608
780
  stage = args.stage
609
781
  admit = args.admit
610
782
  if args.all_free and args.stage == "all" and len(targets) > 3:
611
- stage = "health"
783
+ stage = engine_states.VALIDATION_STAGE_HEALTH
612
784
  rep = validate_engine(
613
785
  eng, stage=stage, admit=admit, timeout=args.timeout,
614
786
  write_doc=args.write_doc, profile=args.profile,
787
+ diagnose=args.diagnose or args.fix_preview, apply=args.apply,
615
788
  )
616
789
  reports.append(rep)
617
- if rep.get("status") == "fail":
790
+ if rep.get("status") == engine_states.VALIDATION_STATUS_FAIL:
618
791
  exit_ok = False
619
- elif args.strict and rep.get("status") != "pass":
792
+ elif (args.strict and rep.get("status")
793
+ != engine_states.VALIDATION_STATUS_PASS):
620
794
  # skipped 也是「这个源没证明自己能交付」:夜间门禁要的是
621
795
  # 11 个关键源全部 pass,缺 key/改名/禁用都不该静默全绿。
622
796
  exit_ok = False
623
797
  if not args.json:
624
798
  st = rep.get("status")
625
799
  lat = ""
626
- h = (rep.get("stages") or {}).get("health") or {}
800
+ h = (rep.get("stages") or {}).get(engine_states.VALIDATION_STAGE_HEALTH) or {}
627
801
  if h.get("latency_ms") is not None:
628
802
  lat = f" {h['latency_ms']}ms"
629
- q = (rep.get("stages") or {}).get("quality") or {}
803
+ q = (rep.get("stages") or {}).get(engine_states.VALIDATION_STAGE_QUALITY) or {}
630
804
  qnote = f" q={q.get('quality_score')}" if q else ""
631
805
  print(f"[{st}] {eng}{lat}{qnote} stages_passed={ (rep.get('admission') or {}).get('stages_passed')}")
632
806
  if rep.get("skip_reason"):
633
807
  print(f" skip: {rep['skip_reason']}")
634
- if st == "fail":
808
+ if st == engine_states.VALIDATION_STATUS_FAIL:
635
809
  err = h.get("error") or q.get("error") or rep.get("error")
636
810
  print(f" error: {err}")
811
+ if rep.get("schema_drift"):
812
+ from engines_parsers import render_drift_report
813
+ print(render_drift_report(rep["schema_drift"], eng))
814
+ if rep.get("fix_applied"):
815
+ print(f" [apply] {rep.get('fix_msg', '已自动更新 Spec 文件')}")
816
+ elif rep.get("fix_blocked_low_confidence"):
817
+ print(f" [apply 未落盘] {rep.get('fix_msg')}")
818
+ elif rep.get("suggested_patch") and not args.json:
819
+ print(" [fix] 已给出建议补丁(预览态,未写盘);"
820
+ "确认无误后加 --apply 才落盘")
637
821
 
638
822
  if args.json:
639
823
  payload = reports if len(reports) > 1 else reports[0]
@@ -73,11 +73,6 @@ from engines_builders import (
73
73
  _build_jolpica_engine,
74
74
  _build_openf1_engine,
75
75
  _build_openligadb_engine,
76
- _build_artic_engine,
77
- _build_cleveland_engine,
78
- _build_tvmaze_engine,
79
- _build_jikan_engine,
80
- _build_deezer_engine,
81
76
  _build_listenbrainz_engine,
82
77
  _build_egov_law_engine,
83
78
  _build_k10plus_engine,
@@ -99,11 +94,12 @@ from engines_builders import (
99
94
  _build_tencent_quote_engine,
100
95
  _build_em_flow_engine,
101
96
  _build_wechat_sogou_engine,
102
- _build_hackernews_engine,
103
97
  _build_stackoverflow_engine,
104
98
  _build_google_scholar_engine,
105
99
  _build_v2ex_engine,
106
100
  _build_bing_rss_engine,
101
+ _build_repology_engine,
102
+ _build_grep_app_engine,
107
103
  _build_ths_hot_engine,
108
104
  _build_cls_telegraph_engine,
109
105
  _build_em_global_news_engine,
@@ -149,7 +145,6 @@ from engines_builders import (
149
145
  _build_rfc_editor_engine,
150
146
  _build_twitter_syndication_engine,
151
147
  _build_deps_dev_engine,
152
- _build_endoflife_engine,
153
148
  _build_biorxiv_engine,
154
149
  _build_un_comtrade_engine,
155
150
  _build_uniprot_engine,
@@ -158,11 +153,9 @@ from engines_builders import (
158
153
  _build_gutenberg_engine,
159
154
  _build_wayback_cdx_engine,
160
155
  _build_usgs_engine,
161
- _build_nasa_cmr_engine,
162
156
  _build_free_dictionary_engine,
163
157
  _build_baidu_baike_engine,
164
158
  _build_pypi_engine,
165
- _build_clinicaltrials_engine,
166
159
  _build_openfda_engine,
167
160
  _build_juejin_engine,
168
161
  _build_models_dev_engine,
@@ -187,23 +180,15 @@ from engines_builders import (
187
180
  _build_google_patents_engine,
188
181
  _build_marginalia_engine,
189
182
  _build_wiby_engine,
190
- _build_cnii_engine,
191
183
  _build_ndl_engine,
192
184
  _build_kor_law_engine,
193
185
  _build_hatena_bookmark_engine,
194
186
  _build_dnb_engine,
195
- _build_doaj_engine,
196
- _build_europeana_engine,
197
- _build_hal_engine,
198
- _build_eu_opendata_engine,
199
187
  _build_open_meteo_engine,
200
188
  _build_searchmysite_engine,
201
189
  _build_lieu_engine,
202
190
  _build_opensky_engine,
203
191
  _build_electricity_maps_engine,
204
- _build_usda_engine,
205
- _build_tatoeba_engine,
206
- _build_figshare_engine,
207
192
  _build_tencent_kline_engine,
208
193
  _build_qq_music_engine,
209
194
  _build_github_engine,
@@ -422,7 +407,6 @@ _BUILDERS = {
422
407
  "tencent_quote": _build_tencent_quote_engine,
423
408
  "em_flow": _build_em_flow_engine,
424
409
  "wechat_sogou": _build_wechat_sogou_engine,
425
- "hackernews": _build_hackernews_engine,
426
410
  "stackoverflow": _build_stackoverflow_engine,
427
411
  "std_samr": _build_std_samr_engine,
428
412
  "openstd": _build_openstd_engine,
@@ -455,11 +439,12 @@ _BUILDERS = {
455
439
  "tracemoe": _build_tracemoe_engine,
456
440
  "pixiv": _build_pixiv_engine,
457
441
  "bing_rss": _build_bing_rss_engine,
442
+ "repology": _build_repology_engine,
443
+ "grep_app": _build_grep_app_engine,
458
444
  "ths_hot": _build_ths_hot_engine,
459
445
  "cls_telegraph": _build_cls_telegraph_engine,
460
446
  "twitter_syndication": _build_twitter_syndication_engine,
461
447
  "deps_dev": _build_deps_dev_engine,
462
- "endoflife": _build_endoflife_engine,
463
448
  "biorxiv": _build_biorxiv_engine,
464
449
  "un_comtrade": _build_un_comtrade_engine,
465
450
  "em_global_news": _build_em_global_news_engine,
@@ -491,11 +476,9 @@ _BUILDERS = {
491
476
  "gutenberg": _build_gutenberg_engine,
492
477
  "wayback_cdx": _build_wayback_cdx_engine,
493
478
  "usgs": _build_usgs_engine,
494
- "nasa_cmr": _build_nasa_cmr_engine,
495
479
  "free_dictionary": _build_free_dictionary_engine,
496
480
  "baidu_baike": _build_baidu_baike_engine,
497
481
  "pypi": _build_pypi_engine,
498
- "clinicaltrials": _build_clinicaltrials_engine,
499
482
  "openfda": _build_openfda_engine,
500
483
  "juejin": _build_juejin_engine,
501
484
  "models_dev": _build_models_dev_engine,
@@ -527,23 +510,15 @@ _BUILDERS = {
527
510
  "marginalia": _build_marginalia_engine,
528
511
  "wiby": _build_wiby_engine,
529
512
  "rss_feed": _build_rss_feed_engine,
530
- "cnii": _build_cnii_engine,
531
513
  "ndl": _build_ndl_engine,
532
514
  "kor_law": _build_kor_law_engine,
533
515
  "hatena_bookmark": _build_hatena_bookmark_engine,
534
516
  "dnb": _build_dnb_engine,
535
- "doaj": _build_doaj_engine,
536
- "europeana": _build_europeana_engine,
537
- "hal": _build_hal_engine,
538
- "eu_opendata": _build_eu_opendata_engine,
539
517
  "open_meteo": _build_open_meteo_engine,
540
518
  "searchmysite": _build_searchmysite_engine,
541
519
  "lieu": _build_lieu_engine,
542
520
  "opensky": _build_opensky_engine,
543
521
  "electricity_maps": _build_electricity_maps_engine,
544
- "usda": _build_usda_engine,
545
- "tatoeba": _build_tatoeba_engine,
546
- "figshare": _build_figshare_engine,
547
522
  "tencent_kline": _build_tencent_kline_engine,
548
523
  "qq_music": _build_qq_music_engine,
549
524
  "who_don": _build_who_don_engine,
@@ -557,12 +532,7 @@ _BUILDERS = {
557
532
  "jolpica": _build_jolpica_engine,
558
533
  "openf1": _build_openf1_engine,
559
534
  "openligadb": _build_openligadb_engine,
560
- "artic": _build_artic_engine,
561
- "cleveland": _build_cleveland_engine,
562
535
  "wikimedia_commons": _build_wikimedia_commons_engine,
563
- "tvmaze": _build_tvmaze_engine,
564
- "jikan": _build_jikan_engine,
565
- "deezer": _build_deezer_engine,
566
536
  "listenbrainz": _build_listenbrainz_engine,
567
537
  "egov_law": _build_egov_law_engine,
568
538
  "k10plus": _build_k10plus_engine,