#!/usr/bin/env python3
"""Doc sync check: ensure README mentions every top-level directory."""

import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent.parent
README = ROOT / "README.md"

# Directories that should be mentioned in README.
EXPECTED_DIRS = {
    "Core",
    "formal",
    "python",
    "qubo",
    "tests",
    "docs",
}

# Directories that exist but need not be advertised in README.
OPTIONAL_DIRS = {
    ".git",
    ".github",
    "__pycache__",
    ".venv",
    ".venv-actual",
    "node_modules",
    "build",
    "lake-packages",
    ".lake",
}


def main() -> int:
    if not README.exists():
        print("ERROR: README.md not found")
        return 1

    text = README.read_text(encoding="utf-8")
    top_level = {p.name for p in ROOT.iterdir() if p.is_dir()}
    required = EXPECTED_DIRS & top_level
    missing = [d for d in sorted(required) if d not in text]

    if missing:
        print("ERROR: README.md does not mention these directories:")
        for d in missing:
            print(f"  - {d}")
        return 1

    print("OK: README.md mentions all expected top-level directories.")
    return 0


if __name__ == "__main__":
    sys.exit(main())
