"""FINBOX monitor autoload helper.

Usage (replace the 22-line FINBOX_MONITOR_AUTOLOAD block):
    from _monitor_autoload import finbox_autoload
    finbox_autoload()
"""

import sys
from pathlib import Path


def finbox_autoload():
    """Auto-load FINBOX monitor guard if available."""
    try:
        current = Path(__file__).resolve()
        for parent in (current.parent, *current.parents):
            monitor_dir = parent / "skill_monitor"
            if (monitor_dir / "monitor_guard.py").exists():
                sys.path.insert(0, str(monitor_dir))
                try:
                    from monitor_guard import autoload
                    autoload()
                finally:
                    try:
                        sys.path.remove(str(monitor_dir))
                    except ValueError:
                        pass
                break
    except Exception:
        pass
