#!/usr/bin/env python3
"""Clean up all redundant test/training files."""
import os
from pathlib import Path

root = Path("c:/MONIKA")

# Patterns to remove
patterns = [
    "test_*.py",
    "train_*.py", 
    "create_*.py",
    "diagnose_*.py",
    "check_*.py",
    "fix_*.py",
    "quick_*.py",
    "*_test.py",
    "*_debug.py",
    "audit_*.py",
    "emergency_*.py",
    "*monika*.py",  # Keep start_mcp_server.py though
    "*stability*.py",
    "*protection*.py",
    "*training*.py",
    "*breakthrough*.py",
    "bulk_*.py",
    "automated_*.py",
    "comprehensive_*.py",
    "collaborative_*.py",
    "enhance_*.py",
    "explore_*.py",
    "final_*.py",
    "full_*.py",
    "ignite_*.py",
    "init_*.py",
    "intensive_*.py",
    "minimal_*.py",
    "nuclear_*.py",
    "permanent_*.py",
    "process_*.py",
    "rebirth_*.py",
    "ultra_*.py",
    "symbiosis_*.py",
    "claude_*.py",
    "download_*.py",
    "extract_*.py",
    "eval.*.py",
]

# Keep these essential files
keep = {
    "start_mcp_server.py",
    "start.standard.py", 
    "__init__.py",
    "cleanup.tmp.py"
}

removed = []
for pattern in patterns:
    for f in root.glob(pattern):
        if f.name in keep or "salience_os_seed" in str(f):
            continue
        try:
            f.unlink()
            removed.append(f.name)
        except Exception as e:
            print(f"Could not remove {f.name}: {e}")

# Remove markdown reports
for f in root.glob("*.md"):
    if f.name not in ["abstract.md", "concept.md"]:
        try:
            f.unlink()
            removed.append(f.name)
        except:
            pass

# Remove txt training files
for f in root.glob("*training*.txt"):
    try:
        f.unlink()
        removed.append(f.name)
    except:
        pass

for f in root.glob("*corpus*.txt"):
    try:
        f.unlink()
        removed.append(f.name)
    except:
        pass

for f in root.glob("alice_*.txt"):
    try:
        f.unlink()
        removed.append(f.name)
    except:
        pass

# Remove large json files
for f in root.glob("*.json"):
    if f.name not in ["mcp_config.monika.json", "conversation_state.json"]:
        if f.stat().st_size > 100000:  # >100KB
            try:
                f.unlink()
                removed.append(f.name)
            except:
                pass

print(f"Removed {len(removed)} files")
print("Kept: start_mcp_server.py, start.standard.py, mcp_config.monika.json")
