with open('autonomous_swarm.py', 'r') as f:
    lines = f.readlines()

# Find where to insert the import (after other imports, before class definitions)
import_added = False
new_lines = []

for i, line in enumerate(lines):
    new_lines.append(line)
    
    # Add import after the last import statement but before first class
    if 'import' in line and not import_added:
        # Check if next few lines have more imports
        has_more_imports = False
        for j in range(i+1, min(i+5, len(lines))):
            if 'import' in lines[j] or 'from' in lines[j]:
                has_more_imports = True
                break
        
        if not has_more_imports and 'class' not in lines[i+1]:
            new_lines.append('from monitor_activation import MonitorActivation\n')
            import_added = True

with open('autonomous_swarm.py', 'w') as f:
    f.writelines(new_lines)

print("✅ Import added")
