story-kit: merge 298_story_bot_htop_command_with_live_updating_process_dashboard
Adds htop bot command with live-updating Matrix message showing system load and per-agent CPU/memory usage. Supports timeout override and htop stop. Resolved conflict with git command in commands.rs registry. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -172,6 +172,9 @@ pub struct BotContext {
|
||||
pub ambient_rooms: Arc<std::sync::Mutex<HashSet<OwnedRoomId>>>,
|
||||
/// Agent pool for checking agent availability.
|
||||
pub agents: Arc<AgentPool>,
|
||||
/// Per-room htop monitoring sessions. Keyed by room ID; each entry holds
|
||||
/// a stop-signal sender that the background task watches.
|
||||
pub htop_sessions: super::htop::HtopSessions,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -376,6 +379,7 @@ pub async fn run_bot(
|
||||
bot_name,
|
||||
ambient_rooms: Arc::new(std::sync::Mutex::new(persisted_ambient)),
|
||||
agents,
|
||||
htop_sessions: Arc::new(TokioMutex::new(HashMap::new())),
|
||||
};
|
||||
|
||||
slog!("[matrix-bot] Cryptographic identity verification is always ON — commands from unencrypted rooms or unverified devices are rejected");
|
||||
@@ -799,6 +803,30 @@ async fn on_room_message(
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for the htop command, which requires async Matrix access (Room)
|
||||
// and cannot be handled by the sync command registry.
|
||||
if let Some(htop_cmd) =
|
||||
super::htop::extract_htop_command(&user_message, &ctx.bot_name, ctx.bot_user_id.as_str())
|
||||
{
|
||||
slog!("[matrix-bot] Handling htop command from {sender}: {htop_cmd:?}");
|
||||
match htop_cmd {
|
||||
super::htop::HtopCommand::Stop => {
|
||||
super::htop::handle_htop_stop(&room, &incoming_room_id, &ctx.htop_sessions).await;
|
||||
}
|
||||
super::htop::HtopCommand::Start { duration_secs } => {
|
||||
super::htop::handle_htop_start(
|
||||
&room,
|
||||
&incoming_room_id,
|
||||
&ctx.htop_sessions,
|
||||
Arc::clone(&ctx.agents),
|
||||
duration_secs,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Spawn a separate task so the Matrix sync loop is not blocked while we
|
||||
// wait for the LLM response (which can take several seconds).
|
||||
tokio::spawn(async move {
|
||||
@@ -1309,6 +1337,7 @@ mod tests {
|
||||
bot_name: "Assistant".to_string(),
|
||||
ambient_rooms: Arc::new(std::sync::Mutex::new(HashSet::new())),
|
||||
agents: Arc::new(AgentPool::new_test(3000)),
|
||||
htop_sessions: Arc::new(TokioMutex::new(HashMap::new())),
|
||||
};
|
||||
// Clone must work (required by Matrix SDK event handler injection).
|
||||
let _cloned = ctx.clone();
|
||||
|
||||
Reference in New Issue
Block a user