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:
@@ -93,6 +93,11 @@ pub fn commands() -> &'static [BotCommand] {
|
||||
description: "Show git status: branch, uncommitted changes, and ahead/behind remote",
|
||||
handler: handle_git,
|
||||
},
|
||||
BotCommand {
|
||||
name: "htop",
|
||||
description: "Show live system and agent process dashboard (`htop`, `htop 10m`, `htop stop`)",
|
||||
handler: handle_htop_fallback,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -442,6 +447,16 @@ fn handle_git(ctx: &CommandContext) -> Option<String> {
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// Fallback handler for the `htop` command when it is not intercepted by the
|
||||
/// async handler in `on_room_message`. In practice this is never called —
|
||||
/// htop is detected and handled before `try_handle_command` is invoked.
|
||||
/// The entry exists in the registry only so `help` lists it.
|
||||
///
|
||||
/// Returns `None` to prevent the LLM from receiving "htop" as a prompt.
|
||||
fn handle_htop_fallback(_ctx: &CommandContext) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -726,7 +741,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// -- help lists status and ambient --------------------------------------
|
||||
// -- help lists status, ambient, and htop --------------------------------
|
||||
|
||||
#[test]
|
||||
fn help_output_includes_status() {
|
||||
@@ -742,6 +757,24 @@ mod tests {
|
||||
assert!(output.contains("ambient"), "help should list ambient command: {output}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_output_includes_htop() {
|
||||
let result = try_cmd_addressed("Timmy", "@timmy:homeserver.local", "@timmy help");
|
||||
let output = result.unwrap();
|
||||
assert!(output.contains("htop"), "help should list htop command: {output}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn htop_command_falls_through_to_none() {
|
||||
// The htop handler returns None so the message is handled asynchronously
|
||||
// in on_room_message, not here. try_handle_command must return None.
|
||||
let result = try_cmd_addressed("Timmy", "@timmy:homeserver.local", "@timmy htop");
|
||||
assert!(
|
||||
result.is_none(),
|
||||
"htop should not produce a sync response (handled async): {result:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// -- strip_prefix_ci ----------------------------------------------------
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user