with open('monitor_activation.py', 'r') as f:
    content = f.read()

# Replace measure_signal_coherence to check actions list
old_coherence = '''    def measure_signal_coherence(self, swarm):
        """Check if agents are synchronized"""
        # Check if all agents have recent activity
        current_time = time.time()
        coherent_agents = 0
        
        for agent in swarm.agents:
            last_action = agent.state.get('last_action_time', 0)
            # Agent is coherent if active within last 60 seconds
            if current_time - last_action < 60:
                coherent_agents += 1
        
        coherence = coherent_agents / len(swarm.agents) if swarm.agents else 0
        return coherence'''

new_coherence = '''    def measure_signal_coherence(self, swarm):
        """Check if agents are synchronized"""
        # Check if agents have executed actions (sign of coherent operation)
        coherent_agents = 0
        
        for agent in swarm.agents:
            # Agent is coherent if it has executed at least one action
            if agent.state.get('actions') and len(agent.state['actions']) > 0:
                coherent_agents += 1
        
        coherence = coherent_agents / len(swarm.agents) if swarm.agents else 0
        return coherence'''

content = content.replace(old_coherence, new_coherence)

with open('monitor_activation.py', 'w') as f:
    f.write(content)

print("✅ Fixed coherence detection")
