fix: replace bash_tasks.rs with generic mcp_loose_ends scanner
- hive-ag3nt: remove bash_tasks.rs entirely; add mcp_loose_ends.rs that scans harness/mcp-loose-ends/*.json generically (no bash knowledge) - hive-bash-mcp: daemon writes mcp-loose-ends/bash.json on every task state transition (pending/running/done/interrupted/timed_out) - get_loose_ends: reads mcp_loose_ends::collect() instead of bash-specific code - implements the generic mechanism from #1162
This commit is contained in:
parent
8b559eceec
commit
8731474104
6 changed files with 119 additions and 93 deletions
|
|
@ -48,6 +48,24 @@ pub fn hyperhive_socket() -> PathBuf {
|
|||
.map_or_else(|| PathBuf::from("/run/hive/mcp.sock"), PathBuf::from)
|
||||
}
|
||||
|
||||
/// Directory where MCP daemons write loose-end summary files for the harness.
|
||||
/// Each daemon writes `<name>.json` here; the harness scans the dir in
|
||||
/// `get_loose_ends` to surface active work from all MCPs generically.
|
||||
#[must_use]
|
||||
pub fn mcp_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")
|
||||
}
|
||||
|
||||
/// Full path for a task's JSON metadata file.
|
||||
#[must_use]
|
||||
pub fn task_json(id: &str) -> PathBuf {
|
||||
|
|
|
|||
|
|
@ -84,6 +84,42 @@ pub fn read_task(id: &str) -> Option<TaskFile> {
|
|||
serde_json::from_str(&s).ok()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Loose-ends file (generic MCP loose-ends protocol)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Rewrite `mcp-loose-ends/bash.json` with a summary of all currently
|
||||
/// active (Pending or Running) tasks. The harness scans this directory
|
||||
/// generically in `get_loose_ends` — no bash-specific code needed there.
|
||||
///
|
||||
/// File format: a JSON array of plain-text summary strings, one per
|
||||
/// loose-end item. The harness includes them verbatim in the output.
|
||||
/// Atomic write (tmp + rename) so the harness never reads a partial file.
|
||||
fn refresh_loose_ends() {
|
||||
let active = active_tasks();
|
||||
let dir = paths::mcp_loose_ends_dir();
|
||||
if let Err(e) = std::fs::create_dir_all(&dir) {
|
||||
tracing::warn!(error = ?e, "bash_runner: create mcp-loose-ends dir failed");
|
||||
return;
|
||||
}
|
||||
let items: Vec<String> = active
|
||||
.iter()
|
||||
.map(|t| {
|
||||
let age = now_unix() - t.created_at;
|
||||
format!(
|
||||
"bash task `{}` status={:?}, cmd: `{}`, age {}s",
|
||||
t.id, t.status, t.cmd, age
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let dest = dir.join("bash.json");
|
||||
let tmp = dest.with_extension("json.tmp");
|
||||
let json = serde_json::to_string(&items).unwrap_or_else(|_| "[]".to_owned());
|
||||
if let Err(e) = std::fs::write(&tmp, &json).and_then(|_| std::fs::rename(&tmp, &dest)) {
|
||||
tracing::warn!(error = ?e, "bash_runner: write mcp-loose-ends/bash.json failed");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public API used by daemon dispatch
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -110,6 +146,7 @@ pub fn submit_task(cmd: String, timeout_secs: Option<u64>) -> Result<String> {
|
|||
stderr_tail: None,
|
||||
};
|
||||
write_task(&task)?;
|
||||
refresh_loose_ends();
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
|
|
@ -216,6 +253,7 @@ async fn mark_interrupted(socket: &Path) {
|
|||
if let Err(e) = write_task(&task) {
|
||||
tracing::warn!(id = %id, error = ?e, "bash_runner: write interrupted state failed");
|
||||
}
|
||||
refresh_loose_ends();
|
||||
send_wake(socket, &id, "interrupted (daemon restarted)", None).await;
|
||||
}
|
||||
}
|
||||
|
|
@ -266,6 +304,7 @@ async fn run_task(mut task: TaskFile, socket: &Path) {
|
|||
if let Err(e) = write_task(&task) {
|
||||
tracing::warn!(id = %id, error = ?e, "bash_runner: write running state failed");
|
||||
}
|
||||
refresh_loose_ends();
|
||||
|
||||
let out_path = paths::task_out(&id);
|
||||
let err_path = paths::task_err(&id);
|
||||
|
|
@ -299,6 +338,7 @@ async fn run_task(mut task: TaskFile, socket: &Path) {
|
|||
if let Err(e) = write_task(&task) {
|
||||
tracing::warn!(id = %id, error = ?e, "bash_runner: write done state failed");
|
||||
}
|
||||
refresh_loose_ends();
|
||||
|
||||
let summary = if timed_out {
|
||||
format!("timed out after {}s", task.timeout_secs)
|
||||
|
|
|
|||
Loading…
Reference in a new issue