#!/usr/bin/env python3
"""Cross-platform local wrapper for vibe-notionbot."""

from __future__ import annotations

import shutil
import subprocess
import sys


def resolve_prefix() -> list[str]:
    npx = shutil.which("npx")
    if npx:
        return [npx, "-y", "-p", "vibe-notion", "vibe-notionbot"]

    local_bin = shutil.which("vibe-notionbot")
    if local_bin:
        return [local_bin]

    raise FileNotFoundError(
        "missing notion runner: npx or vibe-notionbot not found on PATH."
    )


def main() -> int:
    prefix = resolve_prefix()
    proc = subprocess.run(prefix + sys.argv[1:], capture_output=True, text=True)
    if proc.stdout:
        sys.stdout.write(proc.stdout)
    if proc.stderr:
        sys.stderr.write(proc.stderr)
    return proc.returncode


if __name__ == "__main__":
    raise SystemExit(main())
