#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = ["httpx>=0.27", "pyyaml>=6.0"]
# ///
"""Reflexes doctor — post-install verification, no pip install."""
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from reflexes.doctor import run_doctor  # noqa: E402

if __name__ == "__main__":
    import argparse
    p = argparse.ArgumentParser(prog="reflexes-doctor")
    p.add_argument("--config", default=None)
    p.add_argument("--reflexes", default="")
    p.add_argument("--check-update", action="store_true",
                   help="Only check for a newer Reflexes version (fast; no evaluator probe).")
    a = p.parse_args()

    # Fast standalone update check — for a SessionStart hook or the agent's
    # orient step. Fail-silent, always exits 0.
    if a.check_update:
        try:
            from reflexes import __version__
            from reflexes.update import update_status_line
            print(update_status_line(__version__))
        except Exception:
            pass
        sys.exit(0)

    groups = [g.strip() for g in a.reflexes.split(",") if g.strip()]
    sys.exit(run_doctor(config=a.config, groups=groups))
