"""
Skill Loader — auto-discovers skills from the skills/ directory.
"""

import importlib
import pkgutil
import os

def load_all_skills():
    """Import all Python files in skills/ to trigger register_skill() calls."""
    from nexus_gate_pkg.engine.skills import REGISTRY
    
    skills_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "skills")
    if not os.path.isdir(skills_dir):
        return REGISTRY
    
    for filename in sorted(os.listdir(skills_dir)):
        if filename.endswith(".py") and not filename.startswith("_"):
            module_name = f"nexus_gate_pkg.skills.{filename[:-3]}"
            try:
                importlib.import_module(module_name)
            except Exception as e:
                print(f"Warning: failed to load skill {module_name}: {e}")
    
    return REGISTRY
