huskies: merge 1149 story huskies health chat command — surface gateway, sled, matrix, creds, and build-hash status

This commit is contained in:
dave
2026-05-19 20:11:55 +00:00
parent 5d0801854c
commit 9a286315a3
6 changed files with 732 additions and 1 deletions
@@ -19,6 +19,20 @@ use super::super::verification::check_sender_verified;
use super::handle_message;
/// Return `true` when the message is a `health` command addressed to the bot.
///
/// Recognised case-insensitively as the single word `health` after stripping the bot
/// mention prefix. Any trailing whitespace is ignored; extra arguments are not
/// expected and are silently discarded.
fn extract_health_command(message: &str, bot_name: &str, bot_user_id: &str) -> bool {
let stripped = crate::chat::util::strip_bot_mention(message, bot_name, bot_user_id);
let trimmed = stripped
.trim()
.trim_start_matches(|c: char| !c.is_alphanumeric());
let cmd = trimmed.split_whitespace().next().unwrap_or("");
cmd.eq_ignore_ascii_case("health")
}
/// Return `true` when the message is a "rebuild gateway" command addressed to the bot.
///
/// The command is recognised case-insensitively as `rebuild gateway` after stripping
@@ -100,6 +114,12 @@ pub(in crate::chat::transport::matrix::bot) async fn on_room_message(
return;
}
// Update last-event timestamp so the `health` command can detect a stale sync loop.
ctx.last_matrix_event_ms.store(
chrono::Utc::now().timestamp_millis(),
std::sync::atomic::Ordering::Relaxed,
);
// Ignore the bot's own messages to prevent echo loops.
if ev.sender == ctx.matrix_user_id {
return;
@@ -249,6 +269,7 @@ pub(in crate::chat::transport::matrix::bot) async fn on_room_message(
"config",
"project-rebuild",
"upgrade",
"health",
];
let stripped = crate::chat::util::strip_bot_mention(
@@ -546,6 +567,26 @@ pub(in crate::chat::transport::matrix::bot) async fn on_room_message(
return;
}
// `health` — async subsystem health report (gateway + standalone).
if extract_health_command(
&user_message,
&ctx.services.bot_name,
ctx.matrix_user_id.as_str(),
) {
slog!("[matrix-bot] Handling 'health' from {sender}");
let response = super::super::super::health::run_health_check(&ctx).await;
let html = markdown_to_html(&response);
if let Ok(msg_id) = ctx
.transport
.send_message(&room_id_str, &response, &html)
.await
&& let Ok(event_id) = msg_id.parse()
{
ctx.bot_sent_event_ids.lock().await.insert(event_id);
}
return;
}
// Check for bot-level commands (help, status, ambient, …) before invoking
// the LLM. All commands are registered in commands.rs — no special-casing
// needed here.