storkit: merge 439_refactor_unify_story_stuck_states_into_a_single_status_field

This commit is contained in:
dave
2026-03-28 18:33:22 +00:00
parent 5dcc35a1b3
commit 8ee59f5dc1
8 changed files with 17 additions and 258 deletions
+2 -31
View File
@@ -6,6 +6,7 @@
//! running.
use crate::agents::AgentPool;
use crate::chat::util::strip_bot_mention;
use std::path::Path;
use std::sync::Arc;
@@ -22,7 +23,7 @@ pub fn extract_rebuild_command(
bot_name: &str,
bot_user_id: &str,
) -> Option<RebuildCommand> {
let stripped = strip_mention(message, bot_name, bot_user_id);
let stripped = strip_bot_mention(message, bot_name, bot_user_id);
let trimmed = stripped
.trim()
.trim_start_matches(|c: char| !c.is_alphanumeric());
@@ -56,36 +57,6 @@ pub async fn handle_rebuild(
}
}
/// Strip the bot mention prefix from a raw Matrix message body.
fn strip_mention<'a>(message: &'a str, bot_name: &str, bot_user_id: &str) -> &'a str {
let trimmed = message.trim();
if let Some(rest) = strip_prefix_ci(trimmed, bot_user_id) {
return rest;
}
if let Some(localpart) = bot_user_id.split(':').next()
&& let Some(rest) = strip_prefix_ci(trimmed, localpart)
{
return rest;
}
if let Some(rest) = strip_prefix_ci(trimmed, bot_name) {
return rest;
}
trimmed
}
fn strip_prefix_ci<'a>(text: &'a str, prefix: &str) -> Option<&'a str> {
let candidate = text.get(..prefix.len())?;
if !candidate.eq_ignore_ascii_case(prefix) {
return None;
}
let rest = &text[prefix.len()..];
match rest.chars().next() {
None => Some(rest),
Some(c) if c.is_alphanumeric() || c == '-' || c == '_' => None,
_ => Some(rest),
}
}
// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------