From 119dc8c146563f737454488072fe42ce364ec6b6 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 8 Apr 2026 17:25:47 -0400 Subject: [PATCH] Store trimmed text in Content and Thinking nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was checking trim but storing untrimmed. Now stores the trimmed version — no leading/trailing whitespace in the AST. Co-Authored-By: Proof of Concept --- src/agent/context.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/agent/context.rs b/src/agent/context.rs index 62beff9..4aef3e8 100644 --- a/src/agent/context.rs +++ b/src/agent/context.rs @@ -527,8 +527,8 @@ impl ResponseParser { self.think_buf.push_str(&self.buf[..end]); self.buf = self.buf[end + 8..].to_string(); self.in_think = false; - let text = std::mem::take(&mut self.think_buf); - if !text.trim().is_empty() { + let text = std::mem::take(&mut self.think_buf).trim().to_string(); + if !text.is_empty() { self.push_child(ctx, AstNode::thinking(text)); } continue; @@ -623,7 +623,8 @@ impl ResponseParser { fn flush_content(&mut self, ctx: &mut ContextState) { if !self.content_parts.is_empty() { let text: String = self.content_parts.drain(..).collect(); - if !text.trim().is_empty() { + let text = text.trim().to_string(); + if !text.is_empty() { self.push_child(ctx, AstNode::content(text)); } }