from pathlib import Path
import os


class PromptLoader:
    def __init__(self, prompts_dir: Path | None = None) -> None:
        base = prompts_dir or Path(__file__).resolve().parent / "prompts"
        env_override = os.getenv("AGENT_PROMPTS_DIR", "").strip()
        self._dir = Path(env_override) if env_override else base

    def load(self, name: str) -> str:
        path = self._dir / f"{name}.txt"
        if not path.is_file():
            return ""
        return path.read_text(encoding="utf-8").strip()
