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