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
|
|
@ -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