xonecas.io
60255
Zn

Zoea-Nova / commit 564c71b

feat(tui): add smart truncation for reasoning messages

- Show first line, [x more], last 2 lines when reasoning > 3 lines
- Verbose toggle (v key) shows full reasoning without truncation
- Add comprehensive test coverage for reasoning truncation
- Consistent with JSON tree truncation behavior

xonecas2026-02-05 564c71b07737d560f47d3159aabe2445b5888807 parent 7f31b63

2 files changed

internal/tui/focus.go+45−1
@@ -322,6 +322,10 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool) []string {
322322 Foreground(lipgloss.Color("213")). // Lighter purple for reasoning text
323323 Background(logBgColor)
324324
325+ dimmedStyle := lipgloss.NewStyle().
326+ Foreground(lipgloss.Color("240")). // Dim gray for truncation indicator
327+ Background(logBgColor)
328+
325329 reasoningHeader := "REASONING:"
326330 reasoningHeaderWidth := len(reasoningHeader) + 1 // +1 for space after
327331 reasoningContentWidth := maxWidth - reasoningHeaderWidth - padLeft - padRight
@@ -332,7 +336,30 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool) []string {
332336 // Wrap reasoning text
333337 wrappedReasoning := wrapText(entry.Reasoning, reasoningContentWidth)
334338
335- for i, line := range wrappedReasoning {
339+ // Smart truncation: show first line, "[x more]", last 2 lines if verbose is false and > 3 lines
340+ const reasoningTruncateThreshold = 3
341+ const reasoningShowLast = 2
342+ shouldTruncate := !verbose && len(wrappedReasoning) > reasoningTruncateThreshold
343+
344+ var linesToShow []int
345+ if shouldTruncate {
346+ // First line
347+ linesToShow = append(linesToShow, 0)
348+ // Last 2 lines
349+ for i := len(wrappedReasoning) - reasoningShowLast; i < len(wrappedReasoning); i++ {
350+ linesToShow = append(linesToShow, i)
351+ }
352+ } else {
353+ // Show all lines
354+ for i := 0; i < len(wrappedReasoning); i++ {
355+ linesToShow = append(linesToShow, i)
356+ }
357+ }
358+
359+ truncatedCount := len(wrappedReasoning) - len(linesToShow)
360+
361+ for idx, i := range linesToShow {
362+ line := wrappedReasoning[i]
336363 lineLen := lipgloss.Width(line)
337364 remainingWidth := reasoningContentWidth - lineLen
338365 if remainingWidth < 0 {
@@ -340,6 +367,23 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool) []string {
340367 }
341368 paddedLine := line + strings.Repeat(" ", remainingWidth+padRight)
342369
370+ // Insert truncation indicator after first line
371+ if shouldTruncate && idx == 1 {
372+ truncMsg := fmt.Sprintf("[%d more]", truncatedCount)
373+ truncMsgLen := lipgloss.Width(truncMsg)
374+ truncRemainingWidth := reasoningContentWidth - truncMsgLen
375+ if truncRemainingWidth < 0 {
376+ truncRemainingWidth = 0
377+ }
378+ truncPaddedLine := truncMsg + strings.Repeat(" ", truncRemainingWidth+padRight)
379+
380+ leftPad := contentStyle.Render(strings.Repeat(" ", padLeft))
381+ indent := strings.Repeat(" ", reasoningHeaderWidth)
382+ styledIndent := contentStyle.Render(indent)
383+ styledTrunc := dimmedStyle.Render(truncPaddedLine)
384+ result = append(result, leftPad+styledIndent+styledTrunc)
385+ }
386+
343387 if i == 0 {
344388 // First line: left pad + styled header + space + content
345389 leftPad := contentStyle.Render(strings.Repeat(" ", padLeft))
internal/tui/focus_test.go+62−0
@@ -115,6 +115,68 @@ func TestRenderLogEntryWithReasoning(t *testing.T) {
115115 }
116116 }
117117
118+func TestRenderLogEntryWithReasoningTruncation(t *testing.T) {
119+ // Force color output for testing
120+ lipgloss.SetColorProfile(termenv.TrueColor)
121+ defer lipgloss.SetColorProfile(termenv.Ascii)
122+
123+ // Create reasoning with multiple lines that will wrap
124+ longReasoning := "First line of reasoning that explains the initial thought process. " +
125+ "Second line continues with more detailed analysis of the situation. " +
126+ "Third line adds even more context about the decision. " +
127+ "Fourth line provides additional justification. " +
128+ "Fifth line concludes the reasoning with final thoughts."
129+
130+ entry := LogEntry{
131+ Role: "assistant",
132+ Source: "llm",
133+ Content: "I will proceed with the plan.",
134+ Reasoning: longReasoning,
135+ Timestamp: time.Now(),
136+ }
137+
138+ maxWidth := 80
139+
140+ // Test with verbose=false (should truncate)
141+ linesTruncated := renderLogEntryImpl(entry, maxWidth, false)
142+ outputTruncated := strings.Join(linesTruncated, "\n")
143+
144+ // Should contain truncation indicator
145+ if !strings.Contains(outputTruncated, "more]") {
146+ t.Error("Expected truncation indicator '[x more]' in non-verbose output")
147+ }
148+
149+ // Should contain first line
150+ if !strings.Contains(outputTruncated, "First line") {
151+ t.Error("Expected first line of reasoning in truncated output")
152+ }
153+
154+ // Should contain last lines
155+ if !strings.Contains(outputTruncated, "final thoughts") {
156+ t.Error("Expected last line of reasoning in truncated output")
157+ }
158+
159+ // Test with verbose=true (should show all)
160+ linesVerbose := renderLogEntryImpl(entry, maxWidth, true)
161+ outputVerbose := strings.Join(linesVerbose, "\n")
162+
163+ // Should NOT contain truncation indicator
164+ if strings.Contains(outputVerbose, "more]") {
165+ t.Error("Should not show truncation indicator in verbose mode")
166+ }
167+
168+ // Should contain all parts of reasoning
169+ if !strings.Contains(outputVerbose, "First line") {
170+ t.Error("Expected first line in verbose output")
171+ }
172+ if !strings.Contains(outputVerbose, "Third line") {
173+ t.Error("Expected middle lines in verbose output")
174+ }
175+ if !strings.Contains(outputVerbose, "final thoughts") {
176+ t.Error("Expected last line in verbose output")
177+ }
178+}
179+
118180 func TestRenderLogEntryToolWithJSON(t *testing.T) {
119181 lipgloss.SetColorProfile(termenv.TrueColor)
120182 defer lipgloss.SetColorProfile(termenv.Ascii)