#!/usr/bin/env python3 from __future__ import annotations import json from pathlib import Path ROOT = Path(__file__).resolve().parents[1] PIPELINE = json.loads((ROOT / "config" / "pipeline.json").read_text(encoding="utf-8")) SOURCES = json.loads((ROOT / "config" / "sources.json").read_text(encoding="utf-8")) DOC = ROOT / "docs" / "ops-thresholds.generated.md" def main() -> int: quality = PIPELINE.get("quality_gate", {}) recall = PIPELINE.get("semantic_candidate_recall", {}) lines = [ "# AI日报运维阈值(自动生成)", "", "> 由 `scripts/generate_ops_docs.py` 从 `config/pipeline.json` 和 `config/sources.json` 生成;不要手改本文件。", "", "## Quality Gate", "", ] for key in sorted(quality): lines.append(f"- `{key}`: `{quality[key]}`") lines.extend(["", "## Semantic Candidate Recall", ""]) for key in sorted(recall): lines.append(f"- `{key}`: `{recall[key]}`") lines.extend(["", "## Sources", "", "| source | required | failure_policy | min_items | retries | timeout_seconds |", "|---|---:|---|---:|---:|---:|"]) for source in SOURCES: lines.append( f"| {source['name']} | {source.get('required', False)} | {source.get('failure_policy', '')} | " f"{source.get('min_items', 0)} | {source.get('retries', 0)} | {source.get('timeout_seconds', '')} |" ) DOC.write_text("\n".join(lines) + "\n", encoding="utf-8") print(DOC) return 0 if __name__ == "__main__": raise SystemExit(main())