hyperhive/hive-ag3nt/src/mcp_loose_ends.rs

42 lines
1.5 KiB
Rust

//! Generic scanner for MCP loose-end summary files.
//!
//! External MCP daemons (hive-bash-mcp, hive-matrix-mcp, etc.) write
//! JSON files to `$HYPERHIVE_HARNESS_DIR/mcp-loose-ends/<name>.json`.
//! Each file contains a JSON array of plain-text summary strings.
//!
//! The harness reads all files in this directory in `get_loose_ends` to
//! surface active background work from any MCP without hardcoding
//! per-MCP knowledge here.
use std::path::PathBuf;
/// Resolution lives in `hive_sh4re::paths` so the harness + every MCP
/// daemon agree on where loose-end summary files are written.
fn loose_ends_dir() -> PathBuf {
hive_sh4re::paths::mcp_loose_ends_dir()
}
/// Collect all loose-end summary strings published by external MCP daemons.
/// Each string is a single line suitable for inclusion in `get_loose_ends`
/// output. Returns an empty vec if the directory doesn't exist or is empty.
#[must_use]
pub fn collect() -> Vec<String> {
let Ok(rd) = std::fs::read_dir(loose_ends_dir()) else {
return Vec::new();
};
let mut out = Vec::new();
for entry in rd.flatten() {
let path = entry.path();
if path.extension().and_then(|e| e.to_str()) != Some("json") {
continue;
}
let Ok(content) = std::fs::read_to_string(&path) else {
continue;
};
let Ok(items) = serde_json::from_str::<Vec<String>>(&content) else {
continue;
};
out.extend(items);
}
out
}