import os
from pathlib import Path


def is_bench_af_root(path: Path) -> bool:
    """
    Check if the current directory is the root of the Bench-AF project.
    """
    return os.path.exists(path / ".bench-af-components")

def find_bench_af_root() -> Path | None:
    """
    Find the root of the Bench-AF project.
    """
    current_dir = Path.cwd()
    while not is_bench_af_root(current_dir):
        if current_dir == Path("/"):
            return None
        current_dir = current_dir.parent
    return current_dir

def get_bench_af_root() -> Path:
    """
    Get the root of the Bench-AF project.
    """
    root = find_bench_af_root()
    if root is None:
        raise FileNotFoundError("You are not in a Bench-AF project.")
    return root
