diff --git a/src-tauri/src/context.rs b/src-tauri/src/context.rs index aa55389..11bd2bf 100644 --- a/src-tauri/src/context.rs +++ b/src-tauri/src/context.rs @@ -602,6 +602,48 @@ pub struct Briefing { pub sections: Vec, } +/// Bereinigt Message-Content fuer das Briefing: +/// - Entfernt HTML-Tags (Thinking-Blocks, div, span etc.) +/// - Entfernt mehrfache Leerzeichen/Zeilenumbrueche +fn strip_html_for_briefing(content: &str) -> String { + let mut result = String::with_capacity(content.len()); + let mut in_tag = false; + let mut last_was_space = false; + + for ch in content.chars() { + match ch { + '<' => in_tag = true, + '>' => { + in_tag = false; + // Nach einem Tag ein Leerzeichen einfuegen (statt nichts) + if !last_was_space { + result.push(' '); + last_was_space = true; + } + } + _ if in_tag => {} // Innerhalb eines Tags: ignorieren + '\n' | '\r' => { + if !last_was_space { + result.push(' '); + last_was_space = true; + } + } + ' ' | '\t' => { + if !last_was_space { + result.push(' '); + last_was_space = true; + } + } + _ => { + result.push(ch); + last_was_space = false; + } + } + } + + result.trim().to_string() +} + /// Generiert ein Projekt-Briefing aus allen verfügbaren Quellen: /// - Sticky Context (Schicht 1) /// - Projekt-Kontext / Archiv (Schicht 2) @@ -687,16 +729,18 @@ pub async fn generate_briefing( "system" => "⚙️", _ => "?", }; - // Content kürzen auf 300 Zeichen - let content = if msg.content.len() > 300 { - let end = msg.content.char_indices() + // Content bereinigen: HTML-Tags und Thinking-Blocks strippen + let cleaned = strip_html_for_briefing(&msg.content); + // Auf 300 Zeichen kuerzen + let content = if cleaned.len() > 300 { + let end = cleaned.char_indices() .take_while(|(i, _)| *i < 300) .last() .map(|(i, c)| i + c.len_utf8()) - .unwrap_or(300.min(msg.content.len())); - format!("{}…", &msg.content[..end]) + .unwrap_or(300.min(cleaned.len())); + format!("{}...", &cleaned[..end]) } else { - msg.content.clone() + cleaned }; summary_parts.push(format!("{} {}", role_label, content)); }