"""Mirror run traces to a HF Dataset repo (plan §15.4) when HF_TOKEN is present. Falls back silently to local-only traces/ otherwise. Run: python -m scripts.push_traces [--repo Shanmuk4622/autosource-traces] """ from __future__ import annotations import argparse import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from core.config import api_key, settings, traces_dir # noqa: E402 def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("--repo", default="Shanmuk4622/autosource-traces") args = parser.parse_args() token = api_key("HF_TOKEN") if not token or not settings()["features"]["hf_trace_mirror"]: print("[push_traces] HF_TOKEN missing or mirror disabled — local traces only.") return from huggingface_hub import HfApi api = HfApi(token=token) api.create_repo(args.repo, repo_type="dataset", exist_ok=True, private=False) api.upload_folder( folder_path=str(traces_dir()), repo_id=args.repo, repo_type="dataset", ignore_patterns=[".llm_cache.json", "*.decision.json"], commit_message="mirror local run traces", ) print(f"[push_traces] mirrored traces/ -> hf.co/datasets/{args.repo}") if __name__ == "__main__": main()