#!/usr/bin/env python3 """Dry-run or execute the bounded internal RAG candidate canary.""" from __future__ import annotations import argparse import contextlib import json import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) from services.internal_rag_candidate_canary_service import ( # noqa: E402 run_internal_rag_candidate_canary, ) def main() -> int: parser = argparse.ArgumentParser( description="執行 PixelRAG candidate 到內部 pgvector RAG 的受控 canary。" ) parser.add_argument("--candidate-knowledge-receipt-root") parser.add_argument("--output-root") parser.add_argument("--platform", action="append", dest="platforms") parser.add_argument("--max-age-hours", type=int, default=168) parser.add_argument("--limit", type=int, default=1) parser.add_argument("--similarity-threshold", type=float, default=0.70) parser.add_argument("--execute", action="store_true") parser.add_argument("--write-receipt", action="store_true") args = parser.parse_args() with contextlib.redirect_stdout(sys.stderr): payload = run_internal_rag_candidate_canary( candidate_knowledge_receipt_root=args.candidate_knowledge_receipt_root, output_root=args.output_root, platform=tuple(args.platforms or ()), max_age_hours=args.max_age_hours, limit=args.limit, similarity_threshold=args.similarity_threshold, execute=args.execute, write_receipt=bool(args.execute and args.write_receipt), ) print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True)) return 0 if payload.get("success") else 1 if __name__ == "__main__": raise SystemExit(main())