set_status: add status_set_at timestamp (mtime of status file)

This commit is contained in:
damocles 2026-05-23 01:08:50 +02:00 committed by Mara
parent fe2933b213
commit 8e8e8a771f
7 changed files with 75 additions and 14 deletions

View file

@ -54,6 +54,7 @@ pub enum SocketReply {
role: String,
hyperhive_rev: Option<String>,
status_text: Option<String>,
status_set_at: Option<i64>,
},
}
@ -76,11 +77,13 @@ impl From<hive_sh4re::AgentResponse> for SocketReply {
role,
hyperhive_rev,
status_text,
status_set_at,
} => Self::Whoami {
name,
role,
hyperhive_rev,
status_text,
status_set_at,
},
}
}
@ -106,11 +109,13 @@ impl From<hive_sh4re::ManagerResponse> for SocketReply {
role,
hyperhive_rev,
status_text,
status_set_at,
} => Self::Whoami {
name,
role,
hyperhive_rev,
status_text,
status_set_at,
},
}
}
@ -275,11 +280,22 @@ pub fn format_whoami(resp: Result<SocketReply, anyhow::Error>) -> String {
role,
hyperhive_rev,
status_text,
status_set_at,
}) => {
let rev = hyperhive_rev.as_deref().unwrap_or("<unknown>");
let mut out = format!("name: {name}\nrole: {role}\nhyperhive_rev: {rev}");
if let Some(s) = status_text {
out.push_str(&format!("\nstatus: {s}"));
let age = status_set_at.and_then(|ts| {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH).ok()?.as_secs();
let secs = now.saturating_sub(ts as u64);
Some(format_age_secs(secs))
});
if let Some(a) = age {
out.push_str(&format!("\nstatus: {s} (set {a} ago)"));
} else {
out.push_str(&format!("\nstatus: {s}"));
}
}
out
}
@ -289,6 +305,19 @@ pub fn format_whoami(resp: Result<SocketReply, anyhow::Error>) -> String {
}
}
/// Format a duration in seconds as a human-readable age string.
fn format_age_secs(secs: u64) -> String {
if secs < 60 {
format!("{secs}s")
} else if secs < 3600 {
format!("{}m", secs / 60)
} else if secs < 86400 {
format!("{}h", secs / 3600)
} else {
format!("{}d", secs / 86400)
}
}
/// Common envelope around every MCP tool handler: pre-log → run →
/// post-log. The inbox-status hint used to be appended to every tool
/// result; that lives in the wake prompt + UI header now, so tool