rosfix 0.2.0

High-Performance Multi-Language Static Verification and Active Remediation Engine for ROS 2
Documentation
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// The 7 distinct Agent Domains as defined in the MAS architecture.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum AgentDomain {
    RealTimeAndMCU,          // Agent 1
    ExecutorAndDeadlock,     // Agent 2
    NetworkAndTopology,      // Agent 3
    KinematicsAndControl,    // Agent 4
    Security,                // Agent 5
    RuntimeArchitecture,     // Agent 6
    BuildSystem,             // Agent 7
}

/// The core task payload posted to the Blackboard by the Rust CLI.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentTask {
    /// A unique identifier for the task.
    pub task_id: String,
    
    /// Which expert domain this task falls under.
    pub target_domain: AgentDomain,
    
    /// The absolute path to the file containing the violation.
    pub file_path: String,
    
    /// The specific text snippet or AST block causing the issue.
    pub violation_context: String,
    
    /// The diagnostic error message generated by the static analysis.
    pub diagnostic_message: String,
    
    /// Any semantic metadata gathered (e.g., node name, topic, QoS).
    pub semantic_metadata: HashMap<String, String>,
}

/// A simulated event bus where the Rust CLI posts tasks and Agents read from it.
/// In a real distributed system, this could be backed by Redis, MQTT, or a JSON file.
pub struct BlackboardEventBus {
    tasks: Vec<AgentTask>,
}

impl BlackboardEventBus {
    pub fn new() -> Self {
        Self { tasks: Vec::new() }
    }

    /// The Rust CLI frontend calls this to broadcast an issue to the agents.
    pub fn post_task(&mut self, task: AgentTask) {
        // In production, this would serialize the task to JSON and post to a broker.
        self.tasks.push(task);
    }

    /// Autonomous Agents call this to see if there are any tasks in their domain.
    pub fn poll_tasks(&mut self, domain: &AgentDomain) -> Vec<AgentTask> {
        let matched_tasks: Vec<AgentTask> = self.tasks
            .iter()
            .filter(|t| &t.target_domain == domain)
            .cloned()
            .collect();
            
        // Remove polled tasks from the blackboard (claim them)
        self.tasks.retain(|t| &t.target_domain != domain);
        
        matched_tasks
    }
}