#!/usr/bin/env python3
"""Write a local registry-cache.json from @ab-templates/metadata.

Usage:
    python3 scripts/sync_registry.py                    # write cache
    python3 scripts/sync_registry.py --registry <path>  # use custom registry source

The cache is a lightweight summary for LLM prompts and offline use.
The authoritative source is template-library/packages/metadata/registry.json.
"""
from __future__ import annotations

import argparse
import sys
import os

# Make video_dsl.runtime importable regardless of CWD.
_SKILL_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, _SKILL_DIR)

from video_dsl.runtime.template_binder import sync_registry  # noqa: E402


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
    parser.add_argument(
        "--registry",
        default=None,
        help="Path to @ab-templates/metadata registry.json (auto-detected if omitted)",
    )
    parser.add_argument(
        "--output",
        default=None,
        help="Output path for the cache file (default: video_dsl/registry-cache.json)",
    )
    args = parser.parse_args()

    out = sync_registry(output_path=args.output, registry_path=args.registry)
    print(f"wrote {out}")
    return 0


if __name__ == "__main__":
    sys.exit(main())
