storkit: merge 430_bug_status_command_traffic_light_dots_not_coloured_in_matrix

This commit is contained in:
dave
2026-03-28 13:55:01 +00:00
parent eff8f6a6a6
commit fe0a032e8e
3 changed files with 153 additions and 3 deletions
+48
View File
@@ -180,6 +180,54 @@ pub fn commands() -> &'static [BotCommand] {
]
}
/// Like [`try_handle_command`] but returns `(plain_body, html_body)`.
///
/// The plain body is unchanged Markdown text suitable for the Matrix `body`
/// field (non-HTML clients). The HTML body is suitable for `formatted_body`.
///
/// The pipeline-status command (no args) injects Matrix `<font data-mx-color>`
/// tags on the traffic-light dots. All other commands produce HTML by running
/// the plain body through pulldown-cmark.
pub fn try_handle_command_with_html(
dispatch: &CommandDispatch<'_>,
message: &str,
) -> Option<(String, String)> {
let command_text = strip_bot_mention(message, dispatch.bot_name, dispatch.bot_user_id);
let trimmed = command_text.trim();
if !trimmed.is_empty() {
let (cmd_name, args) = match trimmed.split_once(char::is_whitespace) {
Some((c, a)) => (c, a.trim()),
None => (trimmed, ""),
};
// Only the no-arg status variant shows the pipeline with traffic-light
// dots; `status <number>` is a triage dump that needs no colour tags.
if cmd_name.eq_ignore_ascii_case("status") && args.is_empty() {
let body = status::build_pipeline_status(dispatch.project_root, dispatch.agents);
let html = status::build_pipeline_status_html(dispatch.project_root, dispatch.agents);
return Some((body, html));
}
}
// Generic path: plain text body → Markdown-to-HTML.
let body = try_handle_command(dispatch, message)?;
let html = plain_to_html(&body);
Some((body, html))
}
/// Convert a Markdown string to HTML using the same options as the Matrix
/// transport's `markdown_to_html` helper.
fn plain_to_html(markdown: &str) -> String {
use pulldown_cmark::{Options, Parser, html};
let normalized = crate::chat::util::normalize_line_breaks(markdown);
let options = Options::ENABLE_TABLES
| Options::ENABLE_FOOTNOTES
| Options::ENABLE_STRIKETHROUGH
| Options::ENABLE_TASKLISTS;
let parser = Parser::new_ext(&normalized, options);
let mut out = String::new();
html::push_html(&mut out, parser);
out
}
/// Try to match a user message against a registered bot command.
///
/// The message is expected to be the raw body text (e.g., `"@timmy help"`).