@@ -104,7 +104,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
104104 case llmBatchMsg:
105105 return m.handleLLMBatch(msg)
106106
107- // -- LLM messages --------------------------------------------------------
107+ // -- LLM user message (sent before streaming begins) ---------------------
108108 case llmUserMsg:
109109 now := time.Now()
110110 m.history = append(m.history, provider.Message{
@@ -120,122 +120,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
120120 }
121121 return m, tea.Batch(m.processLLM(), m.waitForLLMUpdate())
122122
123- case llmReasoningDeltaMsg:
124- if !m.streaming {
125- m.streaming = true
126- m.streamEntryStart = len(m.convEntries)
127- m.streamWrapStart = len(m.wrappedConvLines())
128- m.streamingReasoning = ""
129- m.streamingContent = ""
130- }
131- m.streamingReasoning += msg.content
132- m.rebuildStreamEntries()
133- if m.scrollOffset == 0 {
134- m.scrollOffset = 0 // stay pinned
135- }
136- return m, m.waitForLLMUpdate()
137-
138- case llmContentDeltaMsg:
139- if !m.streaming {
140- m.streaming = true
141- m.streamEntryStart = len(m.convEntries)
142- m.streamWrapStart = len(m.wrappedConvLines())
143- m.streamingReasoning = ""
144- m.streamingContent = ""
145- }
146- m.streamingContent += msg.content
147- m.rebuildStreamEntries()
148- if m.scrollOffset == 0 {
149- m.scrollOffset = 0 // stay pinned
150- }
151- return m, m.waitForLLMUpdate()
152-
153- case llmHistoryMsg:
154- m.history = append(m.history, msg.msg)
155- return m, m.waitForLLMUpdate()
156-
157- case llmAssistantMsg:
158- // Finalize streaming state: replace streaming entries with final styled content
159- if m.streaming {
160- m.streaming = false
161- // Remove streaming entries
162- if m.streamEntryStart >= 0 && m.streamEntryStart <= len(m.convEntries) {
163- m.convEntries = m.convEntries[:m.streamEntryStart]
164- }
165- m.streamEntryStart = -1
166- m.streamingReasoning = ""
167- m.streamingContent = ""
168- m.convLines = nil // invalidate cache
169- }
170-
171- if msg.reasoning != "" {
172- wasBottom := m.appendText(styledLines(msg.reasoning, m.styles.Muted)...)
173- m.appendText("")
174- if wasBottom {
175- m.scrollOffset = 0
176- }
177- }
178- if msg.content != "" {
179- wasBottom := m.appendText(styledLines(msg.content, m.styles.Text)...)
180- m.appendText("")
181- if wasBottom {
182- m.scrollOffset = 0
183- }
184- }
185- for _, tc := range msg.toolCalls {
186- entry := m.styles.ToolArrow.Render("→") + " " + m.styles.ToolCall.Render(tc.Name+"(...)")
187- wasBottom := m.appendText(entry)
188- if wasBottom {
189- m.scrollOffset = 0
190- }
191- }
192- return m, m.waitForLLMUpdate()
193-
194- case llmToolResultMsg:
195- // Extract file path from tool result header (Opened/Edited/Created)
196- var filePath string
197- if sm := toolResultFileRe.FindStringSubmatch(msg.content); sm != nil {
198- filePath = sm[1]
199- }
200-
201- lines := strings.Split(msg.content, "\n")
202- preview := lines
203- truncated := false
204- if len(lines) > maxPreviewLines {
205- preview = lines[:maxPreviewLines]
206- truncated = true
207- }
208-
209- arrow := m.styles.ToolArrow.Render("←") + " "
210- var wasBottom bool
211- for i, line := range preview {
212- display := m.styles.Dim.Render(line)
213- if i == 0 {
214- display = arrow + display
215- wasBottom = m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content})
216- } else {
217- m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content})
218- }
219- }
220- if truncated {
221- hint := fmt.Sprintf(" ... %d more lines (click to view)", len(lines)-maxPreviewLines)
222- m.appendConv(convEntry{display: m.styles.Muted.Render(hint), kind: entryToolResult, filePath: filePath, full: msg.content})
223- }
224- if wasBottom {
225- m.scrollOffset = 0
226- }
227- return m, m.waitForLLMUpdate()
228-
229- case llmErrorMsg:
230- m.appendText("", m.styles.Error.Render("Error: "+msg.err.Error()), "")
231- return m, nil
232-
233- case llmDoneMsg:
234- m.appendText("")
235- sep := m.makeSeparator(msg.duration.Round(time.Second).String(), msg.timestamp)
236- m.appendText(sep)
237- return m, nil
238-
239123 case mcp_tools.ShowMsg:
240124 m.editor.SetValue(msg.Content)
241125 m.editor.Language = msg.Language
@@ -288,7 +172,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
288172 // at the end, avoiding per-token re-wraps.
289173 func (m Model) handleLLMBatch(batch llmBatchMsg) (tea.Model, tea.Cmd) {
290174 needRebuild := false
291- var finalCmd tea.Cmd
292175
293176 for _, raw := range batch {
294177 switch msg := raw.(type) {
@@ -355,14 +238,8 @@ func (m Model) handleLLMBatch(batch llmBatchMsg) (tea.Model, tea.Cmd) {
355238 m.rebuildStreamEntries()
356239 }
357240
358- // Keep scroll pinned to bottom during streaming.
359- if m.scrollOffset == 0 {
360- m.scrollOffset = 0
361- }
362-
363241 // More messages may follow — keep listening.
364- finalCmd = m.waitForLLMUpdate()
365- return m, finalCmd
242+ return m, m.waitForLLMUpdate()
366243 }
367244
368245 // applyAssistantMsg finalizes streaming state and appends the assistant's