fix: strip leading newline from assistant responses

Christian Rocha and Crush created

💘 Generated with Crush

Co-Authored-By: Crush <crush@charm.land>

Change summary

internal/agent/agent.go | 7 +++++++
1 file changed, 7 insertions(+)

Detailed changes

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)
 		},