import os
import json


def find_module_root(cwd: str) -> str | None:
    # Prefer src layout
    src_dir = os.path.join(cwd, "src")
    if os.path.isdir(src_dir):
        for name in os.listdir(src_dir):
            path = os.path.join(src_dir, name)
            if os.path.isdir(path) and os.path.isfile(os.path.join(path, "__init__.py")):
                return os.path.relpath(path, cwd).replace("\\", "/")

    # Fallback: top-level package dir containing __init__.py
    for name in os.listdir(cwd):
        if name in {"tests", "test", "benchmarks", "venv", ".venv", "build", "dist", ".git"}:
            continue
        path = os.path.join(cwd, name)
        if os.path.isdir(path) and os.path.isfile(os.path.join(path, "__init__.py")):
            return name
    return None


def find_tests_root(cwd: str) -> str | None:
    for cand in ("tests", "test", "testing"):
        if os.path.isdir(os.path.join(cwd, cand)):
            return cand
    return None


def main() -> None:
    cwd = os.getcwd()
    module_root = find_module_root(cwd)
    tests_root = find_tests_root(cwd)
    print(json.dumps({
        "module_root": module_root or "",
        "tests_root": tests_root or "",
    }))


if __name__ == "__main__":
    main()


