@@ -18,6 +18,8 @@ import (
1818 // ---------------------------------------------------------------------------
1919
2020 func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
21+ m.frameLines = nil // invalidate per-frame wrap cache
22+
2123 switch msg := msg.(type) {
2224
2325 // -- Window resize -------------------------------------------------------
@@ -42,9 +44,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4244 return mdl, cmd
4345 }
4446
45- // -- Frame tick (60fps) — flush deferred highlight/wrap work -------------
47+ // -- Frame tick (60fps) — rebuild streaming entries for live updates ------
4648 case tickMsg:
47- m.flushDirty()
49+ m.tickStreaming()
4850 return m, frameTick()
4951
5052 // -- LLM batch (multiple messages drained from updateChan) ---------------
@@ -64,7 +66,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6466 case ShellOutputMsg:
6567 m.ensureStreaming()
6668 m.streamingContent += msg.Content
67- m.dirty = true
69+ m.streamDirty = true
6870 return m, nil
6971
7072 case undoMsg:
@@ -209,32 +211,28 @@ func (m Model) handleLLMBatch(batch llmBatchMsg) (tea.Model, tea.Cmd) {
209211 case llmReasoningDeltaMsg:
210212 m.ensureStreaming()
211213 m.streamingReasoning += msg.content
212- m.dirty = true
214+ m.streamDirty = true
213215
214216 case llmContentDeltaMsg:
215217 m.ensureStreaming()
216218 m.streamingContent += msg.content
217- m.dirty = true
219+ m.streamDirty = true
218220
219221 case llmHistoryMsg:
220222 m.history = append(m.history, msg.msg)
221223 m.saveMessage(msg.msg)
222224
223225 case llmAssistantMsg:
224- m.flushDirty()
225226 m.applyAssistantMsg(msg)
226227
227228 case llmToolResultMsg:
228- m.flushDirty()
229229 m.applyToolResultMsg(msg)
230230
231231 case llmErrorMsg:
232- m.flushDirty()
233232 m.appendText("", m.styles.Error.Render("Error: "+msg.err.Error()), "")
234233 return m, nil
235234
236235 case llmDoneMsg:
237- m.flushDirty()
238236 m.demoteOldUndo()
239237 m.appendText("")
240238 sep := m.makeSeparator(msg.duration.Round(time.Second).String(), msg.timestamp)
@@ -248,6 +246,14 @@ func (m Model) handleLLMBatch(batch llmBatchMsg) (tea.Model, tea.Cmd) {
248246 return m, m.waitForLLMUpdate()
249247 }
250248
249+// tickStreaming rebuilds streaming entries when new content has arrived.
250+func (m *Model) tickStreaming() {
251+ if m.streamDirty {
252+ m.rebuildStreamEntries()
253+ m.streamDirty = false
254+ }
255+}
256+
251257 // ensureStreaming initialises stream state on the first delta of a turn.
252258 func (m *Model) ensureStreaming() {
253259 if m.streaming {
@@ -255,20 +261,10 @@ func (m *Model) ensureStreaming() {
255261 }
256262 m.streaming = true
257263 m.streamEntryStart = len(m.convEntries)
258- m.streamWrapStart = len(m.wrappedConvLines())
259264 m.streamingReasoning = ""
260265 m.streamingContent = ""
261266 }
262267
263-// flushDirty rebuilds stream entries if dirty, then clears the flag.
264-// Called before finalization messages that clear streaming state.
265-func (m *Model) flushDirty() {
266- if m.dirty && m.streaming {
267- m.rebuildStreamEntries()
268- }
269- m.dirty = false
270-}
271-
272268 // applyAssistantMsg finalizes streaming state and appends the assistant's
273269 // response entries. Extracted so handleLLMBatch can reuse the logic.
274270 func (m *Model) applyAssistantMsg(msg llmAssistantMsg) {
@@ -312,7 +308,6 @@ func (m *Model) clearStreaming() {
312308 m.streamEntryStart = -1
313309 m.streamingReasoning = ""
314310 m.streamingContent = ""
315- m.convLines = nil
316311 }
317312
318313 // applyToolResultMsg appends tool result display entries.
@@ -489,7 +484,6 @@ func (m *Model) demoteOldUndo() {
489484 m.convEntries[i].kind = entrySeparator
490485 // full field carries the original separator display text.
491486 m.convEntries[i].display = m.convEntries[i].full
492- m.convLines = nil // invalidate cache
493487 return
494488 }
495489 }
@@ -521,7 +515,6 @@ func (m *Model) trimOldTurns() {
521515 m.turnBoundaries[i].historyIdx -= histOff
522516 }
523517
524- m.convLines = nil // invalidate wrap cache
525518 }
526519 }
527520
@@ -546,7 +539,6 @@ func (m *Model) handleUndo() Model {
546539 // 2. Truncate in-memory history and display.
547540 m.history = m.history[:tb.historyIdx]
548541 m.convEntries = m.convEntries[:tb.convIdx]
549- m.convLines = nil // invalidate cache
550542
551543 // 2b. Show error after truncation so it's visible.
552544 if undoErr != nil {
@@ -579,7 +571,6 @@ func (m *Model) handleUndo() Model {
579571 if m.convEntries[i].kind == entrySeparator {
580572 // full carries the original separator display text.
581573 m.convEntries[i] = m.makeUndoEntry(m.convEntries[i].full)
582- m.convLines = nil
583574 break
584575 }
585576 }