Skip to content

[FEATURE] Tool call formatter visual overhaul: native lipgloss v2 cards (tree/table/list) #864

Description

@edenreich

Summary

The tool-call formatter is visually inconsistent and lacks hierarchy. Tool status lines, collapsed results, expanded trees, and approval summaries each build strings with bare fmt.Sprintf and basic color wrappers (plain text, indentation-based hierarchy, no borders or cards). The Charm stack is already in go.mod (charm.land/lipgloss/v2 v2.0.5, bubbles/v2, x/ansi) and ships the pieces we need natively but are not using: lipgloss/tree, lipgloss/table, lipgloss/list, and the layout helpers Place / PlaceHorizontal. This feature uses them consistently to produce a polished, card-based layout across all tool-call surfaces, and collapses four divergent implementations into one.

Current pain points

  1. No card framing. Collapsed results are indented text lines with no container. Expanded trees use hand-written ├─/└─ runes rather than a real tree renderer.
  2. Connectors are hand-rolled at the source. The ├─/└─ lines come from tool.FormatResult(...): BaseFormatter.FormatExpandedHeader / FormatDataSection / FormatExpandedFooter in internal/domain/formatter.go, plus every tool's own FormatResult in internal/agent/tools/*.go (20+ tools). The formatter service only re-themes the finished string line by line (themeTreeLines in internal/services/tool_result_view.go).
  3. Four divergent implementations of the same thing. statusLine (tool_formatter.go), renderTool (tool_call_renderer.go), the approval renderSummary (approval_box_view.go), and formatToolCallsPreview (queue_box_view.go) each format icon Name(args) status differently. Truncation is width-aware (formatting.TruncateText) in the service but a naive byte cut (args[:47]) in the renderer.
  4. No tool-type differentiation. Bash output, Edit diff, Write preview, A2A indicators, and generic calls all use the same flat text.
  5. Expand/collapse hints are bare dim text with no visual relationship to the content they govern.
  6. No argument styling. Arguments render as key="value" (or collapsed "...") with no distinction between keys and values.
  7. Toggling expand/collapse jumps the scroll position. ToggleToolResultExpansion / ToggleAllToolResultsExpansion re-render without preserving the viewport offset, so the content the user was reading jumps off screen.

What Charm gives us natively (grounding)

All of this is already in go.mod. No new dependencies.

Need Native API Notes
Tree connectors lipgloss/tree (tree.New().Enumerator(tree.RoundedEnumerator), EnumeratorStyle, ItemStyleFunc) Replaces hand-written ├─/└─. RoundedEnumerator renders ├── / ╰──.
Key/value field lists lipgloss/table (table.New().Border(lipgloss.HiddenBorder()).BorderColumn(false).Rows(...)) Already used in cmd/table.go, help_view.go.
Output-preview lists lipgloss/list Optional, for multi-line previews.
Bottom-right status inside a card lipgloss.PlaceHorizontal(w, lipgloss.Right, s) / lipgloss.Place(w, h, lipgloss.Right, lipgloss.Bottom, s) No manual padding math.
Card border styles.Provider.RenderBorderedBox (rounded) Already exists.
Titled border label reuse spliceBranchIntoTopBorder + truncateBorderLabel (provider.go:251/:292) lipgloss v2 has no native border title. The RenderInputField splice is the existing mechanism; generalize it.
Spinner in running card bubbles/v2/spinner via GetSpinnerStyle / RenderSpinner Already available.
ANSI-aware truncate/width charm.land/x/ansi (Truncate, StringWidth, Wrap) via formatting.TruncateText Already wrapped.

Architectural constraint: UI components must not import lipgloss directly (see the doc comment in provider.go). New tree / table / card rendering lives behind styles.Provider methods (for UI) or the formatter service, not scattered in component files.

Acceptance criteria

1. One shared tool-card / summary renderer

  • Add a single renderer (on styles.Provider, plus a summary helper feeding it) that produces icon Name(args) status identically for all four call sites: statusLine (tool_formatter.go), renderTool (tool_call_renderer.go), approval renderSummary (approval_box_view.go), formatToolCallsPreview (queue_box_view.go).
  • All four use width-aware truncation via formatting.TruncateText. Remove the naive args[:47] cut in tool_call_renderer.go:formatArgsPreview.
  • The card is a rounded-border box (RenderBorderedBox) with the tool name spliced into the top border via a generalized RenderTitledCard built on the existing spliceBranchIntoTopBorder mechanism.

2. Live tool previews (ToolCallRenderer.RenderPreviews)

  • Each running tool renders in a titled card. The bubbles/v2 spinner replaces the status icon inside the card.
  • Status and elapsed line sit at the bottom-right of the card via lipgloss.PlaceHorizontal(cardWidth, lipgloss.Right, ...).
  • Bash tools show their rolling 7-line output inside the card, separated from the header by a dim ─ line.

3. Collapsed tool results (FormatToolResultForUI)

  • Titled card: header line (status icon + name + arg preview), a dim ─ separator, the 5-line dim output preview (reuse previewLines from tool_result_view.go), then a footer "N more lines, ctrl+o to expand" right-aligned via PlaceHorizontal.
  • Failure: full body inside the card, no truncation.
  • Rejected: Rejected badge in error color inside the card header.

4. Expanded tool results, native lipgloss/tree at the source

  • Replace the hand-written ├─/└─ box-drawing with lipgloss/tree (RoundedEnumerator) where the tree is built: BaseFormatter / CustomFormatter in internal/domain/formatter.go and each tool's FormatResult in internal/agent/tools/*.go.
  • Introduce a shared tree-builder helper in internal/domain/formatter.go so tools feed structured fields (label/value pairs, sections) instead of drawing glyphs. Each per-tool change is then mechanical: pass fields, delete the fmt.Fprintf("├─ ...") lines. This is a large but mechanical migration; the shared helper keeps each tool's diff tiny.
  • Field labels styled accent + bold via EnumeratorStyle / ItemStyleFunc; values in normal weight. Key/value blocks may use lipgloss/table with HiddenBorder.
  • The expanded tree wraps in the same titled card.
  • Retire the line-by-line re-theming (themeTreeLines / wrapTreeLines in tool_result_view.go) once the tree renders natively.

5. Keep LLM / headless output plain (FormatterType gating)

  • FormatResult is shared by UI, LLM, and headless (FormatterUI / FormatterLLM / FormatterShort, interfaces.go:891). Apply the lipgloss/tree structure for all types, but gate color styling (EnumeratorStyle / ItemStyle, card borders) on FormatterUI only.
  • FormatterLLM / FormatterShort output stays plain, un-colored text (no ANSI). Verify headless infer agent output is unchanged in substance (a glyph width change from ├─ to ├── is acceptable; if not, keep a custom plain enumerator matching the current 2-dash form).

6. Preserve scroll position on expand/collapse

  • Toggling a single result (ToggleToolResultExpansion) or all results (ToggleAllToolResultsExpansion) in conversation_view.go must keep the toggled entry anchored at its current screen position rather than jumping.
  • Capture Viewport.YOffset() before updateViewportContentFull(), measure the height delta introduced above the anchor, and re-apply the adjusted offset after re-render. Apply the same anchoring to the thinking-block toggle for consistency.

7. Argument rendering

  • Keys in accent color, values in default color (string values highlighted green). Long values truncated with … in accent color. File paths via shortenPathInValue (tool_formatter.go) with a folder-icon prefix. Collapsible args (content=, new_string=) render as content="…" in dim italic. Single implementation, shared across call sites (see AC 1).

8. Tool-type differentiation (no emoji)

  • Differentiate Bash / Edit / Write / A2A / generic tools by the accent color of the titled border label plus the tool name already shown there. No emoji badges, no new icon glyphs.

9. Queue box previews

  • Adopt the shared card style for queued calls instead of bare dim text, and show arguments (currently formatToolCallsPreview shows only Name(...) or N tools).

10. Tests

  • Update UI tests (tool_formatter_test.go, tool_call_renderer_test.go, approval_box_view_test.go) to the new card output.
  • Tool FormatResult tests that assert exact ├─/└─ strings will change with the native tree glyphs; update those expectations. LLM-facing assertions must confirm output stays plain (no ANSI).
  • No new test dependencies.
  • Validate rendered output with the tmux-driven TUI recipe in AGENTS.md.

Implementation notes

  • No new dependencies. lipgloss/v2/tree, /table, /list are subpackages of the lipgloss/v2 already in go.mod. bubbles/v2/spinner and charm.land/x/ansi are present.
  • Reuse, do not reinvent. Card: RenderBorderedBox. Titled border: spliceBranchIntoTopBorder / truncateBorderLabel (provider.go:251/:292). Previews: previewLines, capLines, contentWidth, pluralizeLines, formatDurationShort, collapsedFooter, collapseHintLine (all in internal/services/tool_result_view.go). Truncation: formatting.TruncateText. Args: formatArgsPreview, argsPreviewBudget, shortenPathInValue (tool_formatter.go).
  • Keep the public interface. The ToolFormatter interface in internal/domain/interfaces.go stays unchanged. Only rendered strings change.
  • Components go through styles.Provider, never import lipgloss directly.

Affected files

File Role
internal/ui/styles/provider.go Add RenderTitledCard + shared tool-card/summary renderer; generalize the border-title splice
internal/services/tool_formatter.go Route statusLine / FormatToolResultForUI / FormatToolResultExpanded / formatArgsPreview through the shared renderer
internal/services/tool_result_view.go Retire themeTreeLines / wrapTreeLines once the native tree renders
internal/domain/formatter.go Adopt lipgloss/tree in BaseFormatter / CustomFormatter; add shared tree-builder helper; gate styling on FormatterUI
internal/agent/tools/*.go Migrate each tool's FormatResult from ├─/└─ strings to the tree helper (20+ files, mechanical)
internal/ui/components/tool_call_renderer.go Live previews via shared card; remove naive arg truncation
internal/ui/components/approval_box_view.go Approval summary via shared card (keep DiffRenderer for Edit/MultiEdit/Write)
internal/ui/components/queue_box_view.go Queue preview via shared card; show args
internal/ui/components/conversation_view.go Anchor viewport offset across expand/collapse toggles

Out of scope

  • Markdown rendering in the conversation view (separate concern).
  • Keybinding / shortcut refactors.
  • Changing the ToolFormatter interface.
  • New external dependencies.
  • Colors, cards, and spinners are TUI-only. The shared tree structure is adopted at the source formatter, but LLM / headless output stays plain, un-colored text (styles gated on FormatterUI).
  • Inline background-task indicators (A2A, subagent trees) remain distinct components.

Activity

  1. added
    enhancement
    on Jul 11, 2026
  2. changed the title [-][FEATURE] Tool calls formatter visual overhaul — card-based layout with lipgloss v2[/-] [+][FEATURE] Tool calls formatter visual overhaul - card-based layout with lipgloss v2[/+] on Jul 11, 2026
  3. moved this to Todo in 2026on Jul 11, 2026
  4. changed the title [-][FEATURE] Tool calls formatter visual overhaul - card-based layout with lipgloss v2[/-] [+][FEATURE] Tool call formatter visual overhaul: native lipgloss v2 cards (tree/table/list)[/+] on Jul 11, 2026
  5. moved this from Todo to In progress in 2026on Jul 11, 2026
  6. moved this from In progress to QA in 2026on Jul 11, 2026
  7. moved this from QA to Done in 2026on Jul 12, 2026
  8. inference-gateway-releaser commented on Jul 12, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.143.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions