#!/usr/bin/env python3 """Upload agent_traces.jsonl to a Hugging Face Dataset (CodeFlow-style).""" from __future__ import annotations import argparse import sys from pathlib import Path from huggingface_hub import HfApi from trace_store import TRACE_JSONL_PATH, trace_file_exists def main() -> int: parser = argparse.ArgumentParser( description="Upload agent_traces.jsonl to a Hugging Face Dataset.", ) parser.add_argument( "--repo", required=True, help="Target dataset repo id, e.g. your-username/car-diagnostic-agent-traces", ) parser.add_argument( "--path", type=Path, default=TRACE_JSONL_PATH, help=f"Local JSONL file (default: {TRACE_JSONL_PATH})", ) parser.add_argument( "--remote-path", default="agent_traces.jsonl", help="Path inside the dataset repo (default: agent_traces.jsonl)", ) parser.add_argument( "--private", action="store_true", help="Create the dataset as private if it does not exist", ) args = parser.parse_args() if not args.path.is_file() or args.path.stat().st_size == 0: print(f"No trace file at {args.path}", file=sys.stderr) return 1 api = HfApi() try: api.repo_info(args.repo, repo_type="dataset") except Exception: api.create_repo( args.repo, repo_type="dataset", private=args.private, exist_ok=True, ) api.upload_file( path_or_fileobj=str(args.path), path_in_repo=args.remote_path, repo_id=args.repo, repo_type="dataset", commit_message="Update agent traces JSONL", ) print(f"Uploaded {args.path} → {args.repo}/{args.remote_path}") return 0 if __name__ == "__main__": raise SystemExit(main())