Implement chrs-backbeat: Temporal orchestration with Pulse/Reverb and agent synchronization

This commit is contained in:
anthonyrawlins
2026-03-04 03:07:01 +11:00
parent ffe37a4292
commit 00623ac125
4 changed files with 204 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
[package]
name = "chrs-backbeat-demo"
version = "0.1.0"
edition = "2021"
[dependencies]
chrs-agent = { path = "../chrs-agent" }
chrs-backbeat = { path = "../chrs-backbeat" }
chrs-mail = { path = "../chrs-mail" }
chrs-council = { path = "../chrs-council" }
tokio = { version = "1", features = ["full"] }
serde_json = "1.0"
uuid = { version = "1.0", features = ["v4"] }
chrono = "0.4"

View File

@@ -0,0 +1,67 @@
use chrs_agent::CHORUSAgent;
use chrs_backbeat::{Pulse, Reverb};
use chrs_council::Role;
use chrs_mail::Mailbox;
use std::fs;
use std::path::Path;
use tokio::time::{sleep, Duration};
use chrono::Utc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== CHORUS BACKBEAT Rhythmic Orchestration Demo ===");
// 1. Setup shared environment
let base_path = Path::new("/tmp/chrs_backbeat_demo");
if base_path.exists() {
fs::remove_dir_all(base_path)?;
}
fs::create_dir_all(base_path)?;
let mail_db = base_path.join("mail.sqlite");
let shared_mailbox = Mailbox::open(&mail_db)?;
// 2. Initialize Pulse (Broadcaster)
let pulse = Pulse::new("chorus-cluster-01", 30, shared_mailbox.clone()); // 30 BPM = 2s per beat
// 3. Initialize Agents
let mut architect = CHORUSAgent::init("agent-architect", Role::Architect, &base_path.join("architect")).await?;
let mut coder = CHORUSAgent::init("agent-coder", Role::Coder, &base_path.join("coder")).await?;
let mut auditor = CHORUSAgent::init("agent-auditor", Role::Auditor, &base_path.join("auditor")).await?;
architect.mailbox = shared_mailbox.clone();
coder.mailbox = shared_mailbox.clone();
auditor.mailbox = shared_mailbox.clone();
// 4. Initialize Reverb (Rollup)
let reverb = Reverb::new(shared_mailbox.clone());
// 5. Start Everything
let pulse_handle = tokio::spawn(async move { pulse.run().await });
let mut arch_handle_inner = architect;
tokio::spawn(async move { arch_handle_inner.run_loop().await });
let mut coder_handle_inner = coder;
tokio::spawn(async move { coder_handle_inner.run_loop().await });
let mut aud_handle_inner = auditor;
tokio::spawn(async move { aud_handle_inner.run_loop().await });
println!("[DEMO] Pulse and Agents started. Observing for 20 seconds...");
let start_time = Utc::now();
for _ in 0..10 {
sleep(Duration::from_secs(2)).await;
match reverb.collect_report(start_time) {
Ok(claims) => {
println!("[REVERB] Received {} status claims in this window.", claims.len());
for claim in claims {
// println!(" - Agent {}: Beat {}, State: {}", claim.agent_id, claim.beat_index, claim.state);
}
}
Err(e) => eprintln!("[REVERB] Error: {}", e),
}
}
println!("
=== DEMO COMPLETE ===");
Ok(())
}