use brainwires::agents::{AgentMessage, CommunicationHub, FileLockManager, LockType};
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let hub = CommunicationHub::new();
let lock_manager = Arc::new(FileLockManager::new());
hub.register_agent("agent-1".to_string()).await?;
hub.register_agent("agent-2".to_string()).await?;
{
let _read1 = lock_manager
.acquire_lock("agent-1", "src/auth.rs", LockType::Read)
.await?;
let _read2 = lock_manager
.acquire_lock("agent-2", "src/auth.rs", LockType::Read)
.await?;
println!("Two agents reading src/auth.rs concurrently");
}
{
let _write = lock_manager
.acquire_lock("agent-1", "src/auth.rs", LockType::Write)
.await?;
println!("One agent has exclusive write access to src/auth.rs");
}
hub.broadcast(
"agent-1".to_string(),
AgentMessage::StatusUpdate {
agent_id: "agent-1".to_string(),
status: "working".to_string(),
details: Some("Analyzing auth module".to_string()),
},
)
.await?;
match hub.receive_message("agent-2").await {
Some(envelope) => println!("agent-2 received: {:?}", envelope.message),
None => println!("No messages in queue"),
}
println!("\nAgent infrastructure ready!");
println!(" - CommunicationHub: broadcasting messages between agents");
println!(" - FileLockManager: coordinating file access with read/write locks");
Ok(())
}