//! Hive-mind convergence documentation — writes deterministic audit trail. use std::path::{Path, PathBuf}; use anyhow::Result; use tracing::info; use crate::workflow::hive_mind::types::NodeOutput; /// Write a deterministic audit trail for a hive-mind convergence. /// /// Flow: create docs/runs/ dir → build markdown content → write file. /// This is deterministic (not an LLM step) and never skippable. pub fn write_hive_mind_convergence( run_dir: &Path, nodes: &[NodeOutput], consensus: &str, ) -> Result { let docs_dir = run_dir.join("docs/runs"); std::fs::create_dir_all(&docs_dir)?; let timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S"); let filename = format!("{timestamp}-hive-mind-convergence.md"); let filepath = docs_dir.join(&filename); let mut content = String::new(); content.push_str(&format!("# Hive Mind Convergence — {timestamp}\n\n")); content.push_str("## Node Outputs\n\n"); for node in nodes { content.push_str(&format!("### {} — {}\n\n", node.id, node.directive)); content.push_str(&format!("{}\n\n", node.output)); } content.push_str("## Consensus\n\n"); content.push_str(consensus); content.push('\n'); std::fs::write(&filepath, content)?; info!("Hive mind convergence written to {:?}", filepath); Ok(filepath) }