- restore count in get_loose_ends: 'N local task(s):' instead of bare 'local task(s):' - add cross-crate coupling comment to both mcp_loose_ends_dir() copies - add comment in hive-bash-daemon service env explaining HYPERHIVE_HARNESS_DIR is already injected via systemd.globalEnvironment by the meta flake
53 lines
1.9 KiB
Rust
53 lines
1.9 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;
|
|
|
|
/// NOTE: the base-dir resolution logic here is intentionally mirrored in
|
|
/// `hive-bash-mcp/src/paths.rs::mcp_loose_ends_dir()`. They can't share
|
|
/// code across crates — keep them in sync if the fallback logic changes.
|
|
fn loose_ends_dir() -> PathBuf {
|
|
let base = if let Some(p) = std::env::var_os("HYPERHIVE_HARNESS_DIR") {
|
|
PathBuf::from(p)
|
|
} else {
|
|
let state = std::env::var("HYPERHIVE_STATE_DIR").unwrap_or_default();
|
|
let state_path = PathBuf::from(&state);
|
|
state_path
|
|
.parent()
|
|
.map(|p| p.join("harness"))
|
|
.unwrap_or_else(|| PathBuf::from(state))
|
|
};
|
|
base.join("mcp-loose-ends")
|
|
}
|
|
|
|
/// 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
|
|
}
|