@@ -9,6 +9,7 @@ import (
99 "github.com/charmbracelet/bubbles/textarea"
1010 tea "github.com/charmbracelet/bubbletea"
1111 "github.com/charmbracelet/lipgloss"
12+ "github.com/charmbracelet/x/ansi"
1213 "github.com/xonecas/symb/internal/llm"
1314 "github.com/xonecas/symb/internal/mcp"
1415 "github.com/xonecas/symb/internal/provider"
@@ -17,11 +18,12 @@ import (
1718
1819 // Model is the application model
1920 type Model struct {
20- width int
21- height int
22- spinner spinner.Model
23- editor editorarea.Model // Left pane: code editor
24- agentInput textarea.Model // Right pane: agent input box
21+ width int
22+ height int
23+ rightPaneWidth int // Width of conversation pane for wrapping
24+ spinner spinner.Model
25+ editor editorarea.Model // Left pane: code editor
26+ agentInput textarea.Model // Right pane: agent input box
2527
2628 // LLM components
2729 provider provider.Provider
@@ -84,24 +86,49 @@ func (m Model) Init() tea.Cmd {
8486 return tea.Batch(m.spinner.Tick, editorarea.Blink)
8587 }
8688
89+// wrapText wraps text to the conversation pane width, applying style after wrapping.
90+// Returns lines that fit within the pane width.
91+func (m Model) wrapText(text string, style lipgloss.Style) []string {
92+ if m.rightPaneWidth <= 0 {
93+ // Fallback if width not set yet
94+ lines := strings.Split(text, "\n")
95+ result := make([]string, len(lines))
96+ for i, line := range lines {
97+ result[i] = style.Render(line)
98+ }
99+ return result
100+ }
101+
102+ // Word wrap first, then apply style to each line
103+ // ansi.Wordwrap preserves ANSI codes and handles wide characters
104+ wrapped := ansi.Wordwrap(text, m.rightPaneWidth, "")
105+ lines := strings.Split(wrapped, "\n")
106+
107+ // Apply style to each wrapped line
108+ result := make([]string, len(lines))
109+ for i, line := range lines {
110+ result[i] = style.Render(line)
111+ }
112+ return result
113+}
114+
87115 // llmUserMsg adds user message to conversation (ELM Msg)
88116 type llmUserMsg struct {
89117 content string
90118 }
91119
92-// llmAssistantMsg adds assistant message (ELM Msg)
120+// llmAssistantMsg adds complete assistant message block (ELM Msg)
121+// Includes reasoning, content, and tool calls as a single cohesive unit
93122 type llmAssistantMsg struct {
94- content string
95-}
96-
97-// llmToolCallMsg adds tool call (ELM Msg)
98-type llmToolCallMsg struct {
99- name string
123+ reasoning string
124+ content string
125+ toolCalls []provider.ToolCall
100126 }
101127
102128 // llmToolResultMsg adds tool result (ELM Msg)
103129 type llmToolResultMsg struct {
104- content string
130+ toolCallID string
131+ content string
105132 }
106133
107134 // llmDoneMsg adds timestamp separator (ELM Msg)
@@ -152,18 +179,18 @@ func (m Model) processLLM() tea.Cmd {
152179 m.updateChan <- llmHistoryMsg{msg: msg}
153180
154181 if msg.Role == "assistant" {
155- // Send tool calls
156- for _, tc := range msg.ToolCalls {
157- m.updateChan <- llmToolCallMsg{name: tc.Name}
158- }
159- // Send assistant content
160- if msg.Content != "" {
161- m.updateChan <- llmAssistantMsg{content: msg.Content}
182+ // Send complete assistant message as single block
183+ m.updateChan <- llmAssistantMsg{
184+ reasoning: msg.Reasoning,
185+ content: msg.Content,
186+ toolCalls: msg.ToolCalls,
162187 }
163188 } else if msg.Role == "tool" {
164- // Send tool result
165- firstLine := strings.Split(msg.Content, "\n")[0]
166- m.updateChan <- llmToolResultMsg{content: firstLine}
189+ // Send full tool result (wrapping will be handled by wrapText)
190+ m.updateChan <- llmToolResultMsg{
191+ toolCallID: msg.ToolCallID,
192+ content: msg.Content,
193+ }
167194 }
168195 },
169196 }
@@ -219,9 +246,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
219246 })
220247 // Format and display user message first
221248 grayStyle := lipgloss.NewStyle().Foreground(ColorGray)
222- for _, line := range strings.Split(msg.content, "\n") {
223- m.conversation = append(m.conversation, grayStyle.Render(line))
224- }
249+ wrappedLines := m.wrapText(msg.content, grayStyle)
250+ m.conversation = append(m.conversation, wrappedLines...)
225251 m.conversation = append(m.conversation, "")
226252 // Add timestamp separator after message
227253 timestamp := now.Format("15:04")
@@ -244,18 +270,36 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
244270 return m, m.waitForLLMUpdate() // Continue listening
245271
246272 case llmAssistantMsg:
247- for _, line := range strings.Split(msg.content, "\n") {
248- m.conversation = append(m.conversation, line)
273+ // Display complete assistant message block: reasoning, content, then tool calls
274+ plainStyle := lipgloss.NewStyle()
275+ grayStyle := lipgloss.NewStyle().Foreground(ColorGray)
276+
277+ // Display reasoning if present
278+ if msg.reasoning != "" {
279+ wrappedLines := m.wrapText(msg.reasoning, grayStyle)
280+ m.conversation = append(m.conversation, wrappedLines...)
281+ m.conversation = append(m.conversation, "")
282+ }
283+
284+ // Display content
285+ if msg.content != "" {
286+ wrappedLines := m.wrapText(msg.content, plainStyle)
287+ m.conversation = append(m.conversation, wrappedLines...)
288+ m.conversation = append(m.conversation, "")
289+ }
290+
291+ // Display tool calls
292+ for _, tc := range msg.toolCalls {
293+ wrappedLines := m.wrapText("→ "+tc.Name+"(...)", plainStyle)
294+ m.conversation = append(m.conversation, wrappedLines...)
249295 }
250- m.conversation = append(m.conversation, "")
251- return m, m.waitForLLMUpdate() // Continue listening
252296
253- case llmToolCallMsg:
254- m.conversation = append(m.conversation, "→ "+msg.name+"(...)")
255297 return m, m.waitForLLMUpdate() // Continue listening
256298
257299 case llmToolResultMsg:
258- m.conversation = append(m.conversation, "← "+msg.content)
300+ plainStyle := lipgloss.NewStyle()
301+ wrappedLines := m.wrapText("← "+msg.content, plainStyle)
302+ m.conversation = append(m.conversation, wrappedLines...)
259303 return m, m.waitForLLMUpdate() // Continue listening
260304
261305 case llmErrorMsg:
@@ -287,6 +331,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
287331
288332 halfWidth := m.width / 2
289333 contentHeight := m.height - 2 // -2 for status separator and status bar
334+ m.rightPaneWidth = m.width - halfWidth - 1
290335
291336 // Left pane: editor
292337 m.editor.SetWidth(halfWidth - 1)
@@ -336,8 +381,7 @@ func (m Model) View() string {
336381 agentInputView := m.agentInput.View()
337382 agentInputLines := strings.Split(agentInputView, "\n")
338383
339- // Content rows
340- rightPaneWidth := m.width - halfWidth - 1
384+ // Content rows - use the stored rightPaneWidth from model
341385 for i := 0; i < contentHeight; i++ {
342386 // Left pane: editor
343387 if i < len(editorLines) {
@@ -377,32 +421,31 @@ func (m Model) View() string {
377421 if lineIdx < totalLines {
378422 line := m.conversation[lineIdx]
379423 lineWidth := lipgloss.Width(line)
380- if lineWidth > rightPaneWidth {
381- line = line[:rightPaneWidth]
382- lineWidth = rightPaneWidth
383- }
384424 b.WriteString(line)
385- b.WriteString(strings.Repeat(" ", rightPaneWidth-lineWidth))
425+ // Pad to full width
426+ if lineWidth < m.rightPaneWidth {
427+ b.WriteString(strings.Repeat(" ", m.rightPaneWidth-lineWidth))
428+ }
386429 } else {
387- b.WriteString(strings.Repeat(" ", rightPaneWidth))
430+ b.WriteString(strings.Repeat(" ", m.rightPaneWidth))
388431 }
389432 } else if i == separatorRow {
390433 // Separator line
391- b.WriteString(borderStyle.Render(strings.Repeat("─", rightPaneWidth)))
434+ b.WriteString(borderStyle.Render(strings.Repeat("─", m.rightPaneWidth)))
392435 } else {
393436 // Input area (last 3 rows)
394437 lineIdx := i - inputStartRow
395438 if lineIdx < len(agentInputLines) {
396439 line := agentInputLines[lineIdx]
397440 lineWidth := lipgloss.Width(line)
398- if lineWidth > rightPaneWidth {
399- line = line[:rightPaneWidth]
400- lineWidth = rightPaneWidth
441+ if lineWidth > m.rightPaneWidth {
442+ line = line[:m.rightPaneWidth]
443+ lineWidth = m.rightPaneWidth
401444 }
402445 b.WriteString(line)
403- b.WriteString(strings.Repeat(" ", rightPaneWidth-lineWidth))
446+ b.WriteString(strings.Repeat(" ", m.rightPaneWidth-lineWidth))
404447 } else {
405- b.WriteString(strings.Repeat(" ", rightPaneWidth))
448+ b.WriteString(strings.Repeat(" ", m.rightPaneWidth))
406449 }
407450 }