daemon: fix UTF-8 panics on multi-byte character truncation

&str[..n] panics when n falls inside a multi-byte UTF-8 sequence.
This crashed the daemon when processing IRC messages containing
Hebrew/Yiddish characters (ehashman's messages hit byte 79-81).

Replace all byte-index truncation with chars().take(n).collect()
in tmux send_prompt preview, notification logging, and git context
truncation.

Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-03-05 21:15:40 -05:00
parent 308fbe4c28
commit bea1bd5680
3 changed files with 4 additions and 3 deletions

View file

@ -50,7 +50,7 @@ pub fn git_context() -> String {
} }
let ctx = parts.join(" | "); let ctx = parts.join(" | ");
if ctx.len() > 300 { if ctx.len() > 300 {
ctx[..300].to_string() ctx.chars().take(300).collect()
} else { } else {
ctx ctx
} }

View file

@ -169,7 +169,7 @@ impl NotifyState {
info!( info!(
"notification: type={ntype} urgency={urgency} threshold={threshold} msg={}", "notification: type={ntype} urgency={urgency} threshold={threshold} msg={}",
&message[..message.len().min(80)] message.chars().take(80).collect::<String>()
); );
self.pending.push(Notification { self.pending.push(Notification {

View file

@ -32,7 +32,8 @@ pub fn find_claude_pane() -> Option<String> {
/// ///
/// Sequence: Escape q C-c C-u (clear input), wait, type message, Enter. /// Sequence: Escape q C-c C-u (clear input), wait, type message, Enter.
pub fn send_prompt(pane: &str, msg: &str) -> bool { pub fn send_prompt(pane: &str, msg: &str) -> bool {
info!("SEND [{pane}]: {}...", &msg[..msg.len().min(100)]); let preview: String = msg.chars().take(100).collect();
info!("SEND [{pane}]: {preview}...");
let send = |keys: &[&str]| { let send = |keys: &[&str]| {
Command::new("tmux") Command::new("tmux")