From c15697286286fc9c0d811b2ce338dcf737fab8b2 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Sun, 2 Nov 2025 09:03:43 -0500 Subject: [PATCH] fix: strip leading newline from assistant responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💘 Generated with Crush Co-Authored-By: Crush --- internal/agent/agent.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 5a70195ce8e3bd1cbb06af3ce8be50e6b3a2c58e..4e0bd35fd955ea5e6d4b7fa16e9c85a176bddbfd 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -276,6 +276,13 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy return a.messages.Update(genCtx, *currentAssistant) }, OnTextDelta: func(id string, text string) error { + // Strip leading newline from initial text content. This is is + // particularly important in non-interactive mode where leading + // newlines are very visible. + if len(currentAssistant.Parts) == 0 && strings.HasPrefix(text, "\n") { + text = strings.TrimPrefix(text, "\n") + } + currentAssistant.AppendContent(text) return a.messages.Update(genCtx, *currentAssistant) },