#!/usr/bin/env python3
"""Cross-platform entrypoint for note CRUD flow."""

from __future__ import annotations

import subprocess
import sys
from pathlib import Path

from _resolve_lark_cli import resolve_lark_cli_prefix


def main() -> int:
    script_dir = Path(__file__).resolve().parent
    base_dir = script_dir.parent
    cli_prefix = resolve_lark_cli_prefix(base_dir)
    runner = script_dir / "openclaw_notes_crud.py"

    proc = subprocess.run(
        [
            sys.executable,
            str(runner),
            *sum([["--lark-cli-prefix", p] for p in cli_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())
