import re
import pathlib

root = pathlib.Path("/opt/ai-avatar-demo")
extensions = [".py", ".sh"]
keywords = [
    "AccessToken", "VideoGrants", "RoomServiceClient", "create_room",
    "list_rooms", "delete_room", "LIVEKIT_API_KEY", "LIVEKIT_API_SECRET", "LIVEKIT_URL"
]

for p in root.rglob("*"):
    if not p.is_file():
        continue
    parts = p.parts
    if ".venv" in parts or "models" in parts or ".git" in parts or "data" in parts or "__pycache__" in parts:
        continue
    if p.suffix.lower() not in extensions:
        continue
        
    try:
        with open(p, "r", encoding="utf-8", errors="ignore") as f:
            lines = f.readlines()
        
        matches = []
        for idx, line in enumerate(lines):
            match = False
            for kw in keywords:
                if kw in line:
                    match = True
                    break
            if match:
                matches.append((idx+1, line.strip()))
                
        if matches:
            clean_path = "".join([c if ord(c) < 128 else "?" for c in str(p)])
            print(f"---FILE {clean_path}")
            for line_num, content in matches[:40]:
                clean_content = "".join([c if ord(c) < 128 else "?" for c in content])
                print(f"  {line_num}: {clean_content}")
    except Exception:
        pass
