insight-chat: code-review polish on the chat system_prompt override

- Trim the override input once via Option::map(str::trim).filter(...).
- Use matches!() in restore_system_prompt_override's Prepended arm so
  it reads consistently with the Replaced arm.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cameron Cordes
2026-05-07 14:40:04 -04:00
parent faa289882f
commit 428f24b0f8

View File

@@ -1205,10 +1205,7 @@ pub(crate) fn apply_system_prompt_override(
messages: &mut Vec<ChatMessage>,
override_prompt: Option<&str>,
) -> Option<SystemPromptStash> {
let prompt = match override_prompt {
Some(s) if !s.trim().is_empty() => s.trim().to_string(),
_ => return None,
};
let prompt = override_prompt.map(str::trim).filter(|s| !s.is_empty())?.to_string();
if let Some(first) = messages.first_mut()
&& first.role == "system"
{
@@ -1235,7 +1232,7 @@ pub(crate) fn restore_system_prompt_override(
}
}
SystemPromptStash::Prepended => {
if !messages.is_empty() && messages[0].role == "system" {
if matches!(messages.first(), Some(m) if m.role == "system") {
messages.remove(0);
}
}