xonecas.io
60255
Zn

Zoea-Nova / commit 0ef17f7

feat(focus sidebar): rough starting point

xonecas2026-02-09 0ef17f778cb3860fa14a30dd9767e514cc1ec7d0 parent 599f607

9 files changed

internal/core/mysis.go+25−5
@@ -2075,15 +2075,35 @@ func (m *Mysis) cacheSnapshotToolResult(toolName string, result *mcp.ToolResult,
20752075 return
20762076 }
20772077
2078- // Need active account to cache
2078+ // Extract game tick and username from result
2079+ payload, ok := parseToolResultPayload(result)
2080+ if !ok {
2081+ return
2082+ }
2083+
2084+ // Try to extract username from result (for myses with pre-provided credentials)
20792085 username := m.CurrentAccountUsername()
20802086 if username == "" {
2081- return
2087+ // Try to extract from result payload (nested under player.username)
2088+ if payloadMap, ok := payload.(map[string]interface{}); ok {
2089+ if player, ok := payloadMap["player"].(map[string]interface{}); ok {
2090+ if extractedUsername, ok := player["username"].(string); ok && extractedUsername != "" {
2091+ username = extractedUsername
2092+ // Also extract session_id if present
2093+ sessionID := m.CurrentSessionID()
2094+ if sessionID == "" {
2095+ // Try to get from current tool arguments or system prompt
2096+ // For now, just set the username without session
2097+ }
2098+ // Set the account so future caching works
2099+ m.setCurrentAccount(username, "", sessionID)
2100+ }
2101+ }
2102+ }
20822103 }
20832104
2084- // Extract game tick from result
2085- payload, ok := parseToolResultPayload(result)
2086- if !ok {
2105+ // Still no username - can't cache
2106+ if username == "" {
20872107 return
20882108 }
20892109
internal/store/game_state.go+4−4
@@ -138,16 +138,16 @@ func (s *GameStateSnapshot) RecencyMessage(currentTick int64) string {
138138 // Future tick (shouldn't happen, but handle gracefully)
139139 return "just now"
140140 }
141- return fmt.Sprintf("%d ticks ago (%d seconds)", ticksAgo, ticksAgo*10)
141+ return fmt.Sprintf("T%d ago (%ds)", ticksAgo, ticksAgo*10)
142142 }
143143
144144 // Fallback to wall clock time
145145 elapsed := time.Since(s.CapturedAt)
146146 if elapsed < time.Minute {
147- return fmt.Sprintf("%.0f seconds ago", elapsed.Seconds())
147+ return fmt.Sprintf("%.0fs ago", elapsed.Seconds())
148148 }
149149 if elapsed < time.Hour {
150- return fmt.Sprintf("%.0f minutes ago", elapsed.Minutes())
150+ return fmt.Sprintf("%.0f m ago", elapsed.Minutes())
151151 }
152- return fmt.Sprintf("%.1f hours ago", elapsed.Hours())
152+ return fmt.Sprintf("%.1f h ago", elapsed.Hours())
153153 }
internal/tui/app.go+54−13
@@ -89,8 +89,9 @@ type Model struct {
8989 }
9090
9191 const (
92- providerErrorWindow = 10 * time.Minute
93- maxConversationEntries = 200 // Maximum conversation log entries to load for performance
92+ providerErrorWindow = 10 * time.Minute
93+ maxConversationEntries = 500 // Maximum conversation log entries to load for performance
94+ MaxConversationMessages = 500 // Maximum conversation messages to display in focus view
9495 )
9596
9697 // SwarmMessage represents a broadcast message for display.
@@ -181,14 +182,33 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
181182 m.height = msg.Height
182183 m.input.SetWidth(msg.Width - 4)
183184
184- // Update viewport size (account for header, info panel, title, footer)
185- headerHeight := 7 // 2 for header + 3 for info panel + 1 for conversation title + 1 margin
186- footerHeight := 2
187- vpHeight := msg.Height - headerHeight - footerHeight - 3
185+ // Update viewport size (account for all UI chrome)
186+ // Layout in RenderFocusViewWithViewport:
187+ // - Header: 2 lines (mysis name + ID/created)
188+ // - Info panel: 3 lines (top border + content + bottom border)
189+ // - Title row: 1 line (GAME STATE + CONVERSATION LOG titles)
190+ // - Content: max(sidebar_lines, vp.Height) lines (sidebar + conversation side-by-side)
191+ // - Bottom border: 1 line
192+ // - Footer: 1 line (hints)
193+ // Added in View():
194+ // - Newline: 1 line (before message bar)
195+ // - Message bar: 1 line
196+ // - Newline: 1 line (before status bar)
197+ // - Status bar: 1 line
198+ // Total: (2+3+1+1+1) + vp.Height + (1+1+1+1) = 12 + vp.Height
199+ // Therefore: vp.Height = msg.Height - 12
200+ vpHeight := msg.Height - 12
188201 if vpHeight < 5 {
189202 vpHeight = 5
190203 }
191- m.viewport.Width = msg.Width - 4 // -2 for borders, -2 for scrollbar (space + char)
204+ // Viewport width must match the conversation log width calculation in focus.go
205+ // Two-column layout: Sidebar (24) + Gap (2) + Conversation
206+ // Conversation width = total - 24 - 2 = total - 26
207+ // Viewport content width = conversation - 2 (for scrollbar)
208+ const sidebarWidth = 24
209+ const columnGap = 2
210+ conversationWidth := msg.Width - sidebarWidth - columnGap
211+ m.viewport.Width = conversationWidth - 2 // -2 for scrollbar
192212 m.viewport.Height = vpHeight
193213
194214 // Re-render content if in focus view
@@ -325,7 +345,18 @@ func (m Model) View() string {
325345 content = RenderHelp(m.width, contentHeight)
326346 } else if m.view == ViewFocus {
327347 focusIndex, totalMyses := m.focusPosition(m.focusID)
328- content = RenderFocusViewWithViewport(m.mysisByID(m.focusID), m.viewport, m.width, isLoading, m.spinner.View(), m.verboseJSON, m.viewportTotalLines, focusIndex, totalMyses, m.currentTick, m.err)
348+
349+ // Get game state snapshots for focused mysis
350+ var gameStateSnapshots []*store.GameStateSnapshot
351+ focusMysis := m.mysisByID(m.focusID)
352+ if focusMysis.AccountUsername != "" {
353+ snapshots, err := m.store.GetAllGameStateSnapshots(focusMysis.AccountUsername)
354+ if err == nil {
355+ gameStateSnapshots = snapshots
356+ }
357+ }
358+
359+ content = RenderFocusViewWithViewport(focusMysis, m.viewport, m.width, isLoading, m.spinner.View(), m.verboseJSON, m.viewportTotalLines, focusIndex, totalMyses, m.currentTick, gameStateSnapshots, m.err)
329360 } else {
330361 // Convert swarm messages for display (reversed so most recent is first)
331362 swarmInfos := make([]SwarmMessageInfo, len(m.swarmMessages))
@@ -882,7 +913,7 @@ func (m *Model) loadMysisLogs() {
882913 return
883914 }
884915
885- memories, err := m.store.GetRecentMemories(m.focusID, maxConversationEntries)
916+ memories, err := m.store.GetRecentMemories(m.focusID, MaxConversationMessages)
886917 if err != nil {
887918 m.err = err
888919 return
@@ -898,6 +929,12 @@ func (m *Model) loadMysisLogs() {
898929 senderName := m.mysisNameByID(mem.SenderID)
899930 filteredLogs = append(filteredLogs, LogEntryFromMemory(mem, m.focusID, senderName))
900931 }
932+
933+ // Limit to MaxConversationMessages
934+ if len(filteredLogs) > MaxConversationMessages {
935+ filteredLogs = filteredLogs[len(filteredLogs)-MaxConversationMessages:]
936+ }
937+
901938 m.logs = filteredLogs
902939
903940 m.updateViewportContent()
@@ -914,10 +951,14 @@ func (m *Model) updateViewportContent() {
914951 // Remember if user was at bottom before updating content
915952 wasAtBottom := m.viewport.AtBottom()
916953
917- // Log entries must fill the panel content area exactly.
918- // Panel is rendered with logStyle.Width(m.width - 2) without padding (commit d023227)
919- // Content width = m.width - 2 (borders), minus 2 (scrollbar) = m.width - 4
920- panelContentWidth := m.width - 4 // -2 for borders, -2 for scrollbar
954+ // Two-column layout: Game State Sidebar (24 chars) | Conversation Log
955+ const sidebarWidth = 24
956+ const columnGap = 2
957+ conversationWidth := m.width - sidebarWidth - columnGap
958+
959+ // Content width for conversation log (accounting for scrollbar)
960+ // No borders on conversation log, just scrollbar
961+ panelContentWidth := conversationWidth - 2 // -2 for scrollbar
921962
922963 var lines []string
923964 for _, entry := range m.logs {
internal/tui/error_display_test.go+1−0
@@ -69,6 +69,7 @@ func TestErrorDisplayInFocusView(t *testing.T) {
6969 1,
7070 1,
7171 0,
72+ nil, // gameStateSnapshots
7273 testErr,
7374 )
7475
internal/tui/focus.go+329−108
@@ -166,7 +166,7 @@ func RenderFocusView(mysis MysisInfo, logs []LogEntry, width, height int, isLoad
166166 }
167167
168168 // RenderFocusViewWithViewport renders the detailed mysis view using a scrollable viewport.
169-func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int, isLoading bool, spinnerView string, verbose bool, totalLines int, focusIndex, totalMyses int, currentTick int64, err error) string {
169+func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int, isLoading bool, spinnerView string, verbose bool, totalLines int, focusIndex, totalMyses int, currentTick int64, gameStateSnapshots []*store.GameStateSnapshot, err error) string {
170170 var sections []string
171171
172172 // Header with mysis name - spans full width (2 lines)
@@ -195,7 +195,12 @@ func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int,
195195 infoPanel := panelStyle.Width(width - 2).Render(infoContent)
196196 sections = append(sections, infoPanel)
197197
198- // Conversation title with scroll indicator - spans full width
198+ // Two-column layout: Game State Sidebar | Conversation Log
199+ const sidebarWidth = 24 // Fixed width for game state sidebar (total including border)
200+ const columnGap = 2 // Gap between columns
201+ conversationWidth := width - sidebarWidth - columnGap
202+
203+ // Conversation title with scroll indicator
199204 scrollInfo := ""
200205 if !vp.AtBottom() && totalLines > 0 {
201206 currentLine := vp.YOffset + 1
@@ -204,10 +209,27 @@ func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int,
204209 }
205210 scrollInfo = fmt.Sprintf(" LINE %d/%d", currentLine, totalLines)
206211 }
207- logTitle := renderSectionTitleWithSuffix("CONVERSATION LOG", scrollInfo, width)
208- sections = append(sections, logTitle)
212+ logTitle := renderSectionTitleWithSuffix("CONVERSATION LOG", scrollInfo, conversationWidth)
213+
214+ // Game state title
215+ gameStateTitle := renderSectionTitle("GAME STATE", sidebarWidth)
216+
217+ // Render game state sidebar content (returns lines without border)
218+ gameStateSidebarContent := renderGameStateSidebar(gameStateSnapshots, currentTick, sidebarWidth)
219+
220+ // Render sidebar with border using lipgloss
221+ // Width() sets CONTENT width, padding is added on top, border is INCLUDED in width
222+ // So: content_width + padding(2) = sidebarWidth
223+ // Therefore: content_width = sidebarWidth - 2
224+ sidebarStyle := lipgloss.NewStyle().
225+ Border(lipgloss.RoundedBorder()).
226+ BorderForeground(colorBorder).
227+ Width(sidebarWidth-2). // -2 for padding (border is included in width)
228+ Padding(0, 1) // 1 space padding on left/right
229+
230+ sidebarRendered := sidebarStyle.Render(strings.Join(gameStateSidebarContent, "\n"))
231+ gameStateSidebarLines := strings.Split(sidebarRendered, "\n")
209232
210- // Viewport content (scrollable) with scrollbar
211233 // Render scrollbar based on viewport state
212234 scrollOffset := vp.YOffset
213235 scrollbarStr := renderScrollbar(vp.Height, totalLines, scrollOffset)
@@ -216,8 +238,8 @@ func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int,
216238 // Get viewport content lines
217239 vpContentLines := strings.Split(vp.View(), "\n")
218240
219- // Combine each line with scrollbar
220- combinedLines := make([]string, vp.Height)
241+ // Combine viewport content with scrollbar
242+ conversationLines := make([]string, vp.Height)
221243 for i := 0; i < vp.Height; i++ {
222244 var contentLine string
223245 if i < len(vpContentLines) {
@@ -229,16 +251,55 @@ func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int,
229251 } else {
230252 scrollLine = " " // Empty if no scrollbar line
231253 }
232- combinedLines[i] = contentLine + scrollLine
254+ conversationLines[i] = contentLine + scrollLine
233255 }
234256
235- combinedContent := strings.Join(combinedLines, "\n")
236- vpView := logStyle.Width(width - 2).Render(combinedContent)
237- sections = append(sections, vpView)
257+ // Render conversation log (no border, just content)
258+ // The conversation log doesn't have a border, so we use the full conversationWidth
259+ conversationContent := strings.Join(conversationLines, "\n")
260+ conversationView := logStyle.Width(conversationWidth).Render(conversationContent)
261+ conversationViewLines := strings.Split(conversationView, "\n")
262+
263+ // Combine titles
264+ titleRow := lipgloss.JoinHorizontal(lipgloss.Top,
265+ gameStateTitle,
266+ strings.Repeat(" ", columnGap),
267+ logTitle,
268+ )
269+ sections = append(sections, titleRow)
270+
271+ // Combine sidebar and conversation content side by side
272+ maxLines := len(gameStateSidebarLines)
273+ if len(conversationViewLines) > maxLines {
274+ maxLines = len(conversationViewLines)
275+ }
276+
277+ for i := 0; i < maxLines; i++ {
278+ var leftLine, rightLine string
279+
280+ if i < len(gameStateSidebarLines) {
281+ leftLine = gameStateSidebarLines[i]
282+ } else {
283+ leftLine = strings.Repeat(" ", sidebarWidth)
284+ }
285+
286+ if i < len(conversationViewLines) {
287+ rightLine = conversationViewLines[i]
288+ } else {
289+ rightLine = strings.Repeat(" ", conversationWidth)
290+ }
291+
292+ combinedLine := lipgloss.JoinHorizontal(lipgloss.Top,
293+ leftLine,
294+ strings.Repeat(" ", columnGap),
295+ rightLine,
296+ )
297+ sections = append(sections, combinedLine)
298+ }
238299
239300 // Bottom border for conversation log - matches top border style
240- logBottomBorder := renderSectionTitle("", width)
241- sections = append(sections, logBottomBorder)
301+ logBottomBorder := renderSectionTitle("", conversationWidth)
302+ sections = append(sections, strings.Repeat(" ", sidebarWidth)+strings.Repeat(" ", columnGap)+logBottomBorder)
242303
243304 // Footer with scroll hints, verbose toggle, and error status
244305 verboseHint := ""
@@ -254,106 +315,141 @@ func RenderFocusViewWithViewport(mysis MysisInfo, vp viewport.Model, width int,
254315 return lipgloss.JoinVertical(lipgloss.Left, sections...)
255316 }
256317
257-// renderToolCallsEntry formats tool calls with special visual treatment.
258-// Format: ⚡ Calling tools: with bulleted list of tool names and arguments.
259-func renderToolCallsEntry(content string, contentWidth int, verbose bool) []string {
318+// renderToolCallsCompact formats tool calls in compact format.
319+// Format: ⚙ tool_name(args...) - truncated, no huge JSON
320+func renderToolCallsCompact(content string, contentWidth int) []string {
260321 // Parse tool calls from storage format
261322 stored := strings.TrimPrefix(content, constants.ToolCallStoragePrefix)
262323 if stored == "" {
263- return []string{"⚠️ Empty tool call record"}
324+ return []string{dimmedStyle.Render("⚠ Empty tool call")}
264325 }
265326
266327 var result []string
267- toolCallStyle := lipgloss.NewStyle().Foreground(colorTool).Bold(true)
328+ toolIconStyle := lipgloss.NewStyle().Foreground(colorTool)
268329 toolNameStyle := lipgloss.NewStyle().Foreground(colorTool).Bold(true)
269- toolArgStyle := lipgloss.NewStyle().Foreground(colorTool)
270- dimmedStyle := lipgloss.NewStyle().Foreground(colorMuted)
271-
272- // Header line
273- header := toolCallStyle.Render("⚡ Calling tools:")
274- result = append(result, header)
330+ toolArgStyle := lipgloss.NewStyle().Foreground(colorMuted)
275331
276332 // Parse each tool call record
277333 parts := strings.Split(stored, constants.ToolCallStorageRecordDelimiter)
278334 for _, part := range parts {
279335 fields := strings.SplitN(part, constants.ToolCallStorageFieldDelimiter, constants.ToolCallStorageFieldCount)
280336 if len(fields) < constants.ToolCallStorageFieldCount {
281- // Malformed: skip or show warning
282337 continue
283338 }
284339
285340 toolName := fields[1]
286341 argsJSON := fields[2]
287342
288- // Simplified argument format for non-verbose mode
289- if !verbose || argsJSON == "{}" {
290- // Show as: • tool_name() or • tool_name(arg: value)
291- var argsDisplay string
292- if argsJSON == "{}" {
293- argsDisplay = "()"
294- } else {
295- // Parse JSON and create simplified inline format
296- var args map[string]interface{}
297- if err := json.Unmarshal([]byte(argsJSON), &args); err == nil && len(args) > 0 {
298- // Sort keys for deterministic output
299- var keys []string
300- for k := range args {
301- keys = append(keys, k)
302- }
303- // Use simple lexicographic sort
304- for i := 0; i < len(keys); i++ {
305- for j := i + 1; j < len(keys); j++ {
306- if keys[i] > keys[j] {
307- keys[i], keys[j] = keys[j], keys[i]
308- }
343+ // Format: ⚙ tool_name(args...)
344+ var argsDisplay string
345+ if argsJSON == "{}" {
346+ argsDisplay = "()"
347+ } else {
348+ // Parse JSON and create compact inline format
349+ var args map[string]interface{}
350+ if err := json.Unmarshal([]byte(argsJSON), &args); err == nil && len(args) > 0 {
351+ // Sort keys for deterministic output
352+ var keys []string
353+ for k := range args {
354+ keys = append(keys, k)
355+ }
356+ // Simple lexicographic sort
357+ for i := 0; i < len(keys); i++ {
358+ for j := i + 1; j < len(keys); j++ {
359+ if keys[i] > keys[j] {
360+ keys[i], keys[j] = keys[j], keys[i]
309361 }
310362 }
363+ }
311364
312- var argParts []string
313- for _, k := range keys {
314- v := args[k]
315- // Format value based on type
316- var valStr string
317- switch v := v.(type) {
318- case string:
365+ var argParts []string
366+ for _, k := range keys {
367+ v := args[k]
368+ // Format value based on type
369+ var valStr string
370+ switch v := v.(type) {
371+ case string:
372+ // Truncate long strings
373+ if len(v) > 20 {
374+ valStr = fmt.Sprintf("%q", v[:20]+"...")
375+ } else {
319376 valStr = fmt.Sprintf("%q", v)
320- case float64, int, bool:
321- valStr = fmt.Sprintf("%v", v)
322- default:
323- // Complex types: use ellipsis
324- valStr = "{...}"
325377 }
326- argParts = append(argParts, fmt.Sprintf("%s: %s", k, valStr))
378+ case float64, int, bool:
379+ valStr = fmt.Sprintf("%v", v)
380+ default:
381+ // Complex types: use ellipsis
382+ valStr = "{...}"
327383 }
328- argsDisplay = "(" + strings.Join(argParts, ", ") + ")"
329- } else {
330- argsDisplay = "(...)"
384+ argParts = append(argParts, fmt.Sprintf("%s=%s", k, valStr))
331385 }
386+ argsDisplay = "(" + strings.Join(argParts, ", ") + ")"
387+ } else {
388+ argsDisplay = "(...)"
332389 }
390+ }
333391
334- toolLine := " • " + toolNameStyle.Render(toolName) + toolArgStyle.Render(argsDisplay)
335- result = append(result, toolLine)
336- } else {
337- // Verbose mode: show tool name with JSON tree below
338- toolLine := " • " + toolNameStyle.Render(toolName)
339- result = append(result, toolLine)
340-
341- if argsJSON != "{}" {
342- // Render JSON as indented tree
343- var args map[string]interface{}
344- if err := json.Unmarshal([]byte(argsJSON), &args); err == nil {
345- // Simple indented JSON rendering
346- jsonBytes, _ := json.MarshalIndent(args, " ", " ")
347- jsonLines := strings.Split(string(jsonBytes), "\n")
348- for _, line := range jsonLines {
349- result = append(result, dimmedStyle.Render(" "+line))
392+ // Truncate if too long
393+ toolLine := toolIconStyle.Render("⚙") + " " + toolNameStyle.Render(toolName) + toolArgStyle.Render(argsDisplay)
394+ if lipgloss.Width(toolLine) > contentWidth {
395+ // Truncate args
396+ maxArgsWidth := contentWidth - lipgloss.Width(toolIconStyle.Render("⚙")+" "+toolName) - 5
397+ if maxArgsWidth < 5 {
398+ maxArgsWidth = 5
399+ }
400+ argsDisplay = truncateWithEllipsis(argsDisplay, maxArgsWidth)
401+ toolLine = toolIconStyle.Render("⚙") + " " + toolNameStyle.Render(toolName) + toolArgStyle.Render(argsDisplay)
402+ }
403+
404+ result = append(result, toolLine)
405+ }
406+
407+ return result
408+}
409+
410+// renderToolResultCompact formats tool results compactly.
411+// Success: just ✓ Success
412+// Error: ✗ Error: message
413+func renderToolResultCompact(content string, contentWidth int, verbose bool) []string {
414+ // Strip tool call ID prefix if present (format: "call_xxx:json")
415+ jsonContent := content
416+ if idx := strings.Index(jsonContent, ":"); idx > 0 && strings.HasPrefix(jsonContent, "call_") {
417+ jsonContent = jsonContent[idx+1:]
418+ }
419+
420+ successStyle := lipgloss.NewStyle().Foreground(colorSuccess)
421+ errorStyle := lipgloss.NewStyle().Foreground(colorError)
422+
423+ // Check if it's an error
424+ if strings.Contains(jsonContent, "\"error\"") || strings.Contains(jsonContent, "\"isError\"") {
425+ // Parse error message
426+ var data map[string]interface{}
427+ if err := json.Unmarshal([]byte(jsonContent), &data); err == nil {
428+ if errMsg, ok := data["error"].(string); ok {
429+ // Show error message
430+ errorLine := errorStyle.Render("✗") + " " + errorStyle.Render("Error: "+errMsg)
431+ if verbose {
432+ // In verbose mode, show full error
433+ return wrapText(errorLine, contentWidth)
434+ }
435+ // Truncate error message
436+ if lipgloss.Width(errorLine) > contentWidth {
437+ maxErrWidth := contentWidth - 10
438+ if maxErrWidth < 10 {
439+ maxErrWidth = 10
350440 }
441+ errMsg = truncateWithEllipsis(errMsg, maxErrWidth)
442+ errorLine = errorStyle.Render("✗") + " " + errorStyle.Render("Error: "+errMsg)
351443 }
444+ return []string{errorLine}
352445 }
353446 }
447+ // Fallback: generic error
448+ return []string{errorStyle.Render("✗ Error")}
354449 }
355450
356- return result
451+ // Success: just show checkmark
452+ return []string{successStyle.Render("✓ Success")}
357453 }
358454
359455 func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool, currentTick int64) []string {
@@ -403,10 +499,10 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool, currentTick
403499 // Inside padding: 1 space on left and right of all content
404500 const padLeft = 1
405501 const padRight = 1
502+ const contentIndent = 4 // 4 spaces indent for content below header
406503
407- // Calculate content width (accounting for prefix, padding, and gap after prefix)
408- prefixWidth := lipgloss.Width(prefix) + 1 // +1 for space after prefix
409- contentWidth := maxWidth - prefixWidth - padLeft - padRight
504+ // Calculate content width (accounting for indent and padding)
505+ contentWidth := maxWidth - contentIndent - padLeft - padRight
410506 if contentWidth < 20 {
411507 contentWidth = 20
412508 }
@@ -416,26 +512,13 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool, currentTick
416512
417513 // Check for tool calls (assistant messages with [TOOL_CALLS] prefix)
418514 if entry.Role == "assistant" && strings.HasPrefix(entry.Content, constants.ToolCallStoragePrefix) {
419- // Render tool calls with special visual treatment
420- wrappedLines = renderToolCallsEntry(entry.Content, contentWidth, verbose)
421- } else if entry.Role == "tool" && isJSON(entry.Content) {
422- // Extract JSON content (strip tool call ID prefix if present)
423- jsonContent := entry.Content
424- if idx := strings.Index(jsonContent, ":"); idx > 0 && strings.HasPrefix(jsonContent, "call_") {
425- jsonContent = jsonContent[idx+1:]
426- }
427-
428- // Render JSON as tree structure with width constraint
429- treeStr, err := renderJSONTree(jsonContent, verbose, contentWidth)
430- if err == nil {
431- // Tree rendering succeeded
432- wrappedLines = strings.Split(treeStr, "\n")
433- } else {
434- // Fall back to normal wrapping if JSON parsing fails
435- wrappedLines = wrapText(entry.Content, contentWidth)
436- }
515+ // Render tool calls with compact format
516+ wrappedLines = renderToolCallsCompact(entry.Content, contentWidth)
517+ } else if entry.Role == "tool" {
518+ // Tool results: only show errors, success is just a checkmark
519+ wrappedLines = renderToolResultCompact(entry.Content, contentWidth, verbose)
437520 } else {
438- // Normal text wrapping
521+ // Normal text wrapping (user messages, assistant replies)
439522 wrappedLines = wrapText(entry.Content, contentWidth)
440523 }
441524
@@ -466,21 +549,22 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool, currentTick
466549 headerLine := leftPad + styledPrefix + styledSeparator + headerPadding
467550 result = append(result, headerLine)
468551
469- // Render content lines (start at left margin, no indentation)
552+ // Render content lines (4 spaces indented below header)
470553 for _, line := range wrappedLines {
471554 // Pad the line content to fill remaining width
472555 lineLen := lipgloss.Width(line)
473- remainingWidth := maxWidth - padLeft - lineLen - padRight
556+ remainingWidth := maxWidth - padLeft - contentIndent - lineLen - padRight
474557 if remainingWidth < 0 {
475558 remainingWidth = 0
476559 }
477560 paddedLine := line + strings.Repeat(" ", remainingWidth)
478561
479- // All content lines: left pad + content (no indent)
562+ // All content lines: left pad + 4 space indent + content
480563 contentLeftPad := contentStyle.Render(strings.Repeat(" ", padLeft))
564+ indent := contentStyle.Render(strings.Repeat(" ", contentIndent))
481565 styledContent := contentStyle.Render(paddedLine)
482566 rightPad := contentStyle.Render(strings.Repeat(" ", padRight))
483- result = append(result, contentLeftPad+styledContent+rightPad)
567+ result = append(result, contentLeftPad+indent+styledContent+rightPad)
484568 }
485569
486570 // Render reasoning if present
@@ -567,16 +651,18 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool, currentTick
567651 truncPaddedLine := truncMsg + strings.Repeat(" ", truncRemainingWidth)
568652
569653 contentLeftPad := contentStyle.Render(strings.Repeat(" ", padLeft))
654+ indent := contentStyle.Render(strings.Repeat(" ", contentIndent))
570655 styledTrunc := dimmedStyle.Render(truncPaddedLine)
571656 rightPad := contentStyle.Render(strings.Repeat(" ", padRight))
572- result = append(result, contentLeftPad+styledTrunc+rightPad)
657+ result = append(result, contentLeftPad+indent+styledTrunc+rightPad)
573658 }
574659
575- // All lines: left pad + content (no indent, matches main message rendering)
660+ // All lines: left pad + 4 space indent + content (matches main message rendering)
576661 contentLeftPad := contentStyle.Render(strings.Repeat(" ", padLeft))
662+ indent := contentStyle.Render(strings.Repeat(" ", contentIndent))
577663 styledContent := reasoningStyle.Render(paddedLine)
578664 rightPad := contentStyle.Render(strings.Repeat(" ", padRight))
579- result = append(result, contentLeftPad+styledContent+rightPad)
665+ result = append(result, contentLeftPad+indent+styledContent+rightPad)
580666 }
581667 }
582668
@@ -657,3 +743,138 @@ func isJSON(s string) bool {
657743 return (strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}")) ||
658744 (strings.HasPrefix(s, "[") && strings.HasSuffix(s, "]"))
659745 }
746+
747+// renderGameStateSidebar renders the game state sidebar showing all snapshots.
748+func renderGameStateSidebar(snapshots []*store.GameStateSnapshot, currentTick int64, width int) []string {
749+ var lines []string
750+
751+ if len(snapshots) == 0 {
752+ lines = append(lines, dimmedStyle.Render("No game state"))
753+ lines = append(lines, dimmedStyle.Render("available"))
754+ return lines
755+ }
756+
757+ // Group snapshots by category (same as buildGameStateSummary)
758+ statusTools := []string{"get_status", "get_player"}
759+ shipTools := []string{"get_ship", "get_cargo"}
760+ locationTools := []string{"get_system", "get_location", "get_poi"}
761+
762+ // Helper to render a snapshot group
763+ renderGroup := func(toolNames []string) {
764+ for _, snapshot := range snapshots {
765+ for _, toolName := range toolNames {
766+ if snapshot.ToolName == toolName {
767+ // Tool name with recency
768+ recency := snapshot.RecencyMessage(currentTick)
769+ toolHeader := labelStyle.Render(toolName)
770+ recencyText := dimmedStyle.Render(fmt.Sprintf(" (%s)", recency))
771+ lines = append(lines, toolHeader+recencyText)
772+
773+ // Extract and show compact info
774+ compactInfo := extractCompactInfoForTUI(snapshot.Content, toolName, width-4)
775+ lines = append(lines, compactInfo...)
776+ lines = append(lines, "") // Empty line between groups
777+ }
778+ }
779+ }
780+ }
781+
782+ renderGroup(statusTools)
783+ renderGroup(shipTools)
784+ renderGroup(locationTools)
785+
786+ // Remove trailing empty line if present
787+ if len(lines) > 0 && lines[len(lines)-1] == "" {
788+ lines = lines[:len(lines)-1]
789+ }
790+
791+ return lines
792+}
793+
794+// extractCompactInfoForTUI extracts key info from snapshot for TUI display.
795+func extractCompactInfoForTUI(content, toolName string, maxWidth int) []string {
796+ var lines []string
797+
798+ // Parse JSON content
799+ var data map[string]interface{}
800+ if err := json.Unmarshal([]byte(content), &data); err != nil {
801+ return lines
802+ }
803+
804+ switch toolName {
805+ case "get_status", "get_player":
806+ // Extract player data
807+ if player, ok := data["player"].(map[string]interface{}); ok {
808+ if credits, ok := player["credits"].(float64); ok {
809+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Credits: %d", int(credits))))
810+ }
811+ if location, ok := player["current_system"].(string); ok {
812+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" System: %s", truncateWithEllipsis(location, maxWidth-10))))
813+ }
814+ }
815+ // Extract ship data from get_status
816+ if ship, ok := data["ship"].(map[string]interface{}); ok {
817+ if name, ok := ship["name"].(string); ok {
818+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Ship: %s", truncateWithEllipsis(name, maxWidth-8))))
819+ }
820+ if fuel, ok := ship["fuel"].(float64); ok {
821+ if maxFuel, ok := ship["max_fuel"].(float64); ok {
822+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Fuel: %d/%d", int(fuel), int(maxFuel))))
823+ }
824+ }
825+ if hull, ok := ship["hull"].(float64); ok {
826+ if maxHull, ok := ship["max_hull"].(float64); ok {
827+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Hull: %d/%d", int(hull), int(maxHull))))
828+ }
829+ }
830+ }
831+
832+ case "get_ship":
833+ if cargoUsed, ok := data["cargo_used"].(float64); ok {
834+ if cargoMax, ok := data["cargo_max"].(float64); ok {
835+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Cargo: %d/%d", int(cargoUsed), int(cargoMax))))
836+ }
837+ }
838+ if class, ok := data["class"].(map[string]interface{}); ok {
839+ if className, ok := class["name"].(string); ok {
840+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Class: %s", truncateWithEllipsis(className, maxWidth-9))))
841+ }
842+ }
843+
844+ case "get_cargo":
845+ if cargo, ok := data["cargo"].([]interface{}); ok {
846+ cargoUsed := 0
847+ for _, item := range cargo {
848+ if itemMap, ok := item.(map[string]interface{}); ok {
849+ name, _ := itemMap["name"].(string)
850+ qty, _ := itemMap["quantity"].(float64)
851+ if name != "" {
852+ cargoUsed += int(qty)
853+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" • %s x%d", truncateWithEllipsis(name, maxWidth-10), int(qty))))
854+ }
855+ }
856+ }
857+ if capacity, ok := data["capacity"].(float64); ok {
858+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Total: %d/%d", cargoUsed, int(capacity))))
859+ }
860+ }
861+
862+ case "get_system":
863+ if pois, ok := data["pois"].([]interface{}); ok {
864+ poiCount := len(pois)
865+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" POIs: %d", poiCount)))
866+ }
867+
868+ case "get_poi":
869+ if poi, ok := data["poi"].(map[string]interface{}); ok {
870+ if name, ok := poi["name"].(string); ok {
871+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" %s", truncateWithEllipsis(name, maxWidth-2))))
872+ }
873+ if poiType, ok := poi["type"].(string); ok {
874+ lines = append(lines, dimmedStyle.Render(fmt.Sprintf(" Type: %s", poiType)))
875+ }
876+ }
877+ }
878+
879+ return lines
880+}
internal/tui/focus_header_test.go+1−1
@@ -73,7 +73,7 @@ func TestFocusViewHeaderPresence(t *testing.T) {
7373 vp.GotoTop()
7474
7575 // Render focus view
76- output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, len(contentLines), 1, 1, 0, nil)
76+ output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, len(contentLines), 1, 1, 0, nil, nil)
7777
7878 // Split into lines
7979 lines := strings.Split(output, "\n")
internal/tui/focus_test.go+1−1
@@ -265,7 +265,7 @@ func TestRenderFocusViewWithScrollbar(t *testing.T) {
265265
266266 width := 100
267267 totalLines := 50
268- output := RenderFocusViewWithViewport(mysis, vp, width, false, "⬡", false, totalLines, 1, 1, 0, nil)
268+ output := RenderFocusViewWithViewport(mysis, vp, width, false, "⬡", false, totalLines, 1, 1, 0, nil, nil)
269269
270270 // Should contain scrollbar characters
271271 if !strings.Contains(output, "█") && !strings.Contains(output, "│") {
internal/tui/golden_test.go+1−1
@@ -473,7 +473,7 @@ func TestFocusViewWithViewport(t *testing.T) {
473473 vp.SetContent(strings.Join(contentLines, "\n"))
474474 vp.GotoTop()
475475
476- output := RenderFocusViewWithViewport(tt.mysis, vp, tt.width, false, "⠋", false, tt.totalLines, 1, 1, 0, nil)
476+ output := RenderFocusViewWithViewport(tt.mysis, vp, tt.width, false, "⠋", false, tt.totalLines, 1, 1, 0, nil, nil)
477477
478478 t.Run("ANSI", func(t *testing.T) {
479479 golden.RequireEqual(t, []byte(output))
internal/tui/layout_test.go+1−1
@@ -206,7 +206,7 @@ func TestFocusViewLayoutCalculations(t *testing.T) {
206206 }()
207207
208208 // Render focus view
209- output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, tt.numLogs, 1, 1, 0, nil)
209+ output := RenderFocusViewWithViewport(mysis, vp, tt.termWidth, false, "⬡", false, tt.numLogs, 1, 1, 0, nil, nil)
210210
211211 // Basic validations
212212 if output == "" {