"""CLI wrapper around migrate_runtime_primitives (src/workers/tasks/migrate_runtime_primitives.py)
for existing project repos -- the project-repo equivalent of migrate_template_primitives.py.

Runs the same worker task the admin endpoint (POST /api/admin/runtime-primitives/migrate)
triggers, but as a plain script -- no running server, no admin auth token, just this
process's own DB/Redis/GitHub App credentials (same .env as the API). Run this on the
server, same reasoning as migrate_template_primitives.py: it needs Redis reachable (to
enqueue preview provisioning after a push) and the proper async context for the Core
pack-install DB writes.

Usage:
    python scripts/migrate_project_primitives.py
    python scripts/migrate_project_primitives.py --project-id <uuid>
"""
from __future__ import annotations

import argparse
import asyncio
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))


def main() -> None:
    from src.workers.tasks.migrate_runtime_primitives import migrate_runtime_primitives

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--project-id", help="Only process this project's UUID (omit for up to 100 active projects)")
    args = parser.parse_args()

    result = asyncio.run(migrate_runtime_primitives({}, project_id=args.project_id))
    print(result)


if __name__ == "__main__":
    main()
