xonecas.io
60255
Zn

Zoea-Nova / commit 1d35d7f

fix(tui): detect and render JSON in tool results with call ID prefix

- Update isJSON() to strip 'call_xxx:' prefix before checking
- Extract JSON content from prefixed tool results before rendering tree
- Add test for tool results with call ID prefix format
- Fixes unformatted JSON display for tool call results

xonecas2026-02-05 1d35d7f4f44d250a11ed70c8c4cc5e866569bcc7 parent 875670e

2 files changed

internal/tui/focus.go+16−2
@@ -293,8 +293,14 @@ func renderLogEntryImpl(entry LogEntry, maxWidth int, verbose bool) []string {
293293 // Detect JSON content in tool messages and render as tree
294294 var wrappedLines []string
295295 if entry.Role == "tool" && isJSON(entry.Content) {
296+ // Extract JSON content (strip tool call ID prefix if present)
297+ jsonContent := entry.Content
298+ if idx := strings.Index(jsonContent, ":"); idx > 0 && strings.HasPrefix(jsonContent, "call_") {
299+ jsonContent = jsonContent[idx+1:]
300+ }
301+
296302 // Render JSON as tree structure with width constraint
297- treeStr, err := renderJSONTree(entry.Content, verbose, contentWidth)
303+ treeStr, err := renderJSONTree(jsonContent, verbose, contentWidth)
298304 if err == nil {
299305 // Tree rendering succeeded
300306 wrappedLines = strings.Split(treeStr, "\n")
@@ -469,9 +475,17 @@ func renderFocusHeader(mysisName string, width int) string {
469475 return headerStyle.Width(width).Render(line)
470476 }
471477
472-// isJSON checks if a string appears to be JSON
478+// isJSON checks if a string appears to be JSON.
479+// Handles tool result format: "tool_call_id:json_content"
473480 func isJSON(s string) bool {
474481 s = strings.TrimSpace(s)
482+
483+ // Strip tool call ID prefix if present (format: "call_xxx:json")
484+ if idx := strings.Index(s, ":"); idx > 0 && strings.HasPrefix(s, "call_") {
485+ s = s[idx+1:]
486+ s = strings.TrimSpace(s)
487+ }
488+
475489 return (strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}")) ||
476490 (strings.HasPrefix(s, "[") && strings.HasSuffix(s, "]"))
477491 }
internal/tui/focus_test.go+35−0
@@ -231,6 +231,41 @@ func TestRenderLogEntryToolWithJSON(t *testing.T) {
231231 t.Error("Expected JSON field names in tree output")
232232 }
233233 }
234+
235+func TestRenderLogEntryToolWithPrefixedJSON(t *testing.T) {
236+ lipgloss.SetColorProfile(termenv.TrueColor)
237+ defer lipgloss.SetColorProfile(termenv.Ascii)
238+
239+ // Tool result with call ID prefix (format from database)
240+ toolResult := `call_59orhh05:{"max_myses": 16, "states": {"errored": 0, "idle": 0, "running": 1, "stopped": 0}, "total_myses": 1}`
241+
242+ entry := LogEntry{
243+ Role: "tool",
244+ Source: "tool",
245+ Content: toolResult,
246+ Timestamp: time.Now(),
247+ }
248+
249+ maxWidth := 80
250+ lines := renderLogEntryImpl(entry, maxWidth, false)
251+
252+ output := strings.Join(lines, "\n")
253+
254+ // Should have tree structure (JSON should be detected despite prefix)
255+ if !strings.Contains(output, "├─") && !strings.Contains(output, "└─") {
256+ t.Error("Expected tree box characters in prefixed tool JSON output")
257+ }
258+
259+ // Should contain field names from JSON
260+ if !strings.Contains(output, "max_myses") || !strings.Contains(output, "states") {
261+ t.Error("Expected JSON field names in tree output")
262+ }
263+
264+ // Should NOT contain the call ID prefix in the tree
265+ if strings.Contains(output, "call_59orhh05:") {
266+ t.Error("Tool call ID prefix should be stripped from JSON tree")
267+ }
268+}
234269 func TestRenderFocusViewWithScrollbar(t *testing.T) {
235270 lipgloss.SetColorProfile(termenv.TrueColor)
236271 defer lipgloss.SetColorProfile(termenv.Ascii)