"""Path helpers for project layout."""

from __future__ import annotations

from pathlib import Path


def _find_project_root() -> Path:
    """Find project root by looking for config.toml.

    1. Walk up from cwd (handles `uv tool install` — package lives outside repo)
    2. Fall back to __file__-relative (handles editable install from packages/pipeline/)
    """
    # Try cwd first — works when gskills is run from repo root (or any subdir)
    p = Path.cwd().resolve()
    while p != p.parent:
        if (p / "config.toml").exists():
            return p
        p = p.parent

    # Fallback: __file__-relative (3 levels up: clawbench → clawbench → packages → root)
    return Path(__file__).resolve().parents[3]


_PROJECT_ROOT = _find_project_root()
