#!/usr/bin/env python3
"""Thin wrapper that delegates to the canonical render_video.py with --resolve-only forced on.

The two-phase video pipeline shares one Python implementation:

  prepare_video_assets  →  render_video.py --resolve-only ...  (this file)
  render_video          →  render_video.py ...                 (sibling skill)

By exec'ing the canonical script we get verbatim stdout / stderr / exit-code / signal forwarding
without any subprocess wrapper layer. The agent layer's stdout parsing for the
"📦 render job jobId: N" line therefore continues to work unchanged.

The wrapper unconditionally injects --resolve-only as the first argument. The MCP tool schema for
this skill excludes job_id / render_plan / resolve_only / upload_title / no_upload / renderer, so
the LLM cannot push this entry point into Phase 3 territory; even if a shell caller passes those
flags directly to this wrapper, --resolve-only still wins because asset-resolve-and-exit always
short-circuits before the render step in render_video.py.
"""
from __future__ import annotations

import os
import sys


def _canonical_script_path() -> str:
    """Resolve the absolute path to the render-video skill's render_video.py.

    Layout (relative to this file):
        apps/ab-skill/skills/prepare-video-assets/scripts/prepare_video_assets.py  <-- HERE
        apps/ab-skill/skills/render-video/scripts/render_video.py                  <-- target

    The relative jump is ../../render-video/scripts/render_video.py.
    """
    here = os.path.dirname(os.path.abspath(__file__))
    return os.path.normpath(
        os.path.join(here, "..", "..", "render-video", "scripts", "render_video.py")
    )


def main() -> None:
    script = _canonical_script_path()
    if not os.path.isfile(script):
        # Fail fast with a human-readable message rather than letting execv raise OSError.
        print(
            f"❌ prepare_video_assets wrapper could not locate the canonical render script.\n"
            f"   Expected at: {script}\n"
            f"   This indicates the render-video skill is missing from the skill tree.",
            file=sys.stderr,
        )
        sys.exit(2)
    # Force --resolve-only into argv before any user-supplied flag.
    forwarded = ["--resolve-only", *sys.argv[1:]]
    os.execv(sys.executable, [sys.executable, script, *forwarded])


if __name__ == "__main__":
    main()
