Skip to content

feat(tui): card-based tool-call formatter overhaul + scrollable approval review (#864) - #865

Merged
edenreich merged 12 commits into
mainfrom
feat/tool-formatter-cards-864
Jul 11, 2026
Merged

edenreich merged 12 commits into
mainfrom
feat/tool-formatter-cards-864

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Closes #864 — a card-based visual overhaul of the tool-call formatter, plus a set of approval-box review fixes surfaced during testing.

The four surfaces that render a tool call (statusLine, live renderTool, approval summary, queue preview) each built icon Name(args) status differently — one width-aware, another a naive args[:47] byte-cut that dumped raw JSON and broke multibyte runes. Collapsed/expanded results had no card framing, the expanded tree was hand-drawn ├─/└─ runes re-themed line-by-line, and toggling expand/collapse jumped the scroll position. This unifies all of it.

What changed (#864 acceptance criteria)

  • Shared summary renderer — one width-aware <icon> Name(args) <status> builder (ToolFormatter.RenderToolSummary); the status line, live preview, approval summary and queue preview all route through it. Killed the args[:47] byte-slice.
  • Live previews in cards — running tools render in a titled card (spinner as the status icon, bash output inside).
  • Collapsed results in cards — status line → dim separator → preview → right-aligned footer.
  • Native lipgloss/tree — expanded results build one real tree (RoundedEnumerator); all ~18 tools + the service fallback migrated; the hand-drawn connectors deleted.
  • LLM/headless stays plain — cards/colors gated to the UI methods; LLM output is ANSI-free with ├──/╰── glyphs.
  • Scroll preserved — rebuildPreservingScroll anchors the view across expand/collapse.
  • Tool-type differentiation without emoji — border-title accent color per type; removed todowrite's emoji header.
  • Argument rendering — width-aware, path-shortened, rune-safe.
  • Queue previews show arguments instead of a bare Name(...).

Approval-box review fixes (found while testing)

  • Scrollable ctrl+o expansion — the approval diff was capped to ~half the screen with no way to review the rest. ctrl+o now opens a scrollable full-diff window (↑/↓ scroll) that fills the screen while the Approve/Reject buttons stay pinned, so a file larger than the terminal is fully reviewable.
  • No double-cap — the new-file preview hard-capped at 50 lines with its own footer, shadowing the scroll window and showing a phantom … 1 more lines on an exactly-50-line file (trailing-newline off-by-one). The renderer now drops the empty trailing element and takes a configurable cap; the expanded box renders every line and is its own single height bound.
  • Expand-first toggle — global ctrl+o collapsed-first whenever anything was expanded, so a lone collapsed card (e.g. a rejected write next to a default-expanded Edit diff) ignored the first press. It now expands-first unless everything is already open.
  • esc-rejection routing — rejecting with esc clears the approval state without completing the form, leaving the box's local fields stale; IsActive() kept returning true and swallowed ctrl+o. It now consults the live StateManager, so a rejected result expands again.

Testing

  • task test (unit + integration), task test:e2e, and task lint all pass.
  • Cards, scrollable expansion, and all four approval fixes verified live in the chat TUI (tmux + mock gateway).
  • Headless/LLM expanded output confirmed plain (no ANSI, native ├──/╰──).

Notes

  • Public TUI surface (feat:) → a matching [DOCS] ticket for inference-gateway/docs will follow.
  • One known non-blocker: a rejected mutating tool's expanded view shows content: ... (the formatter elides the arg, same as a successful write, which has no result body when rejected). Can add a rejected-diff view as a follow-up if wanted.

edenreich added 10 commits July 11, 2026 22:01
…primitive

Add BaseFormatter/CustomFormatter.FormatExpanded building the expanded
result as one native lipgloss/tree (RoundedEnumerator), replacing the
hand-drawn tree that spanned FormatExpandedHeader/DataSection/Footer.
Add Provider.RenderTitledCard + ToolTitleColor for the tool-card overhaul.

Old trio methods retained until call sites migrate. Part of #864.
Route every structured tool's FormatForLLM plus the service LLM fallback
through domain.FormatExpanded (one native lipgloss/tree), and delete the
hand-drawn FormatExpandedHeader/FormatDataSection/FormatExpandedFooter trio
(+ CustomFormatter override) and todowrite's emoji header. Teach the UI
wrap/theme helpers the rounded '╰' glyph so the expanded view themes and
wraps the native tree. Edit/MultiEdit diffs and memory/write bodies now
feed the shared Result section. Part of #864.
…mmary

Add ToolFormatter.RenderToolSummary (one width-aware '<icon> Name(args)
<trailing>' builder) and route statusLine through it. Frame the collapsed
view (status, dim separator, preview, right-aligned footer) and the expanded
tree in a rounded titled card via Provider.RenderTitledCard, with the tool
name on the border coloured by type (AC8, no emoji). Regenerate mocks and
update the affected formatter tests. Part of #864.
Route the tool-result and thinking-block toggles through
rebuildPreservingScroll, which measures the pre-toggle line spans, applies
the state change, re-renders, and offsets the viewport by the height delta
of changed entries above the scroll position - so expanding an off-screen
entry no longer makes the view jump. Stays pinned to the bottom when the
user is following the tail. Part of #864.
Inject the shared ToolFormatter into ToolCallRenderer and QueueBoxView.
Live previews now render the width-aware '<icon> Name(args) <status>' summary
inside a titled card (spinner as the status icon, bash output inside),
replacing the byte-slice args[:47] preview that broke on multibyte runes and
dumped raw JSON. Queued tool calls show their argument preview instead of a
bare Name(...). Part of #864.
Add tests for FormatExpanded's native rounded-tree structure, the LLM path
staying card-free and plain, RenderTitledCard framing/width, the shared
RenderToolSummary (width-aware, rune-safe), and viewport scroll anchoring
across expand/collapse. Part of #864.
The approval box capped the diff preview to ~half the terminal with no way
to review the rest before approving. ctrl+o now toggles a scrollable
full-diff window (up/down scroll) that fills the screen while the action
buttons stay pinned, so a file larger than the terminal is fully reviewable
— consistent with expanding tool results in the conversation view.
The Write new-file preview hard-capped at 50 lines with its own
"… N more lines" footer, which shadowed the scrollable approval window
(the tail was already dropped before scrolling could reach it) and, on an
exactly-50-line file, showed a phantom "… 1 more lines" from the trailing
newline. The renderer now drops the empty trailing element and takes a
configurable cap via SetMaxLines; the expanded approval box renders every
line (SetMaxLines(-1)) and lets its own window be the single height bound.
ToggleAllToolResultsExpansion collapsed-first whenever *any* result was
expanded, so a lone collapsed card — e.g. a rejected Write — ignored the
first ctrl+o when a default-expanded Edit diff sat above it (the press just
collapsed the Edit). It now expands-first unless every result is already
expanded, so the collapsed card always opens on the first press; collapsing
only kicks in once everything is open.
Rejecting an approval with esc clears the StateManager's approval state
without completing the huh form, so ApprovalBoxView.active/form were never
reset. IsActive() trusted those stale fields and kept returning true, so
ctrl+o was routed to the (defunct) approval box and swallowed instead of
expanding the rejected result in the conversation. IsActive() now consults
the live StateManager — matching Render — so it reports false the moment the
approval is cleared by any path, and ctrl+o falls through to the conversation.
@edenreich
edenreich requested a review from a team as a code owner July 11, 2026 22:52
@edenreich edenreich added this to 2026 Jul 11, 2026
@edenreich edenreich moved this to QA in 2026 Jul 11, 2026
…domain

renderExpandedTree used FormatStatus, which emits a raw color escape, so the
Status node leaked ANSI into the FormatterLLM tree message sent to the model.
Use a plain glyph status instead (the UI re-themes the tree via themeTreeLines).

Also move the lipgloss/v2/tree dependency behind a leaf wrapper
(internal/ui/styles/tree), matching the colors/icons convention so the domain
layer no longer imports lipgloss directly. Guard the LLM path with an ANSI-free
assertion in TestFormatExpandedNativeTree (real renderExpandedTree path).
@edenreich
edenreich merged commit 915dea4 into main Jul 11, 2026
1 check passed
@edenreich
edenreich deleted the feat/tool-formatter-cards-864 branch July 11, 2026 23:35
edenreich added a commit that referenced this pull request Jul 11, 2026
)

## Summary

Add language-aware syntax highlighting using chroma (already a
transitive dependency via glamour) for diff content and file content
previews in the card-based tool-call formatter, keyed off file extension
with a plain fallback.

## Changes

- **`diffview/diffview.go`** — Add `WithChromaStyle` fluent setter on
`DiffView`. Nil/no-call preserves exact current behavior. Clears the
syntax cache on set.
- **`diff_renderer.go`** — Add private `chromaStyle()` method deriving
`github` (light) or `github-dark` from the active theme's brightness.
Wire it into `buildDiffView()` and `renderContentPreview()` (which now
takes a `filePath` parameter for lexer selection).
- **`diff_renderer_test.go`** — Three new tests: known language (.go),
unknown extension (.xyzabc), and nil style provider (no crash).

## Key Design Decisions

| Decision | Rationale |
|----------|-----------|
| Chroma style gated on `chromaStyle == nil` inside `highlightCode()` |
Existing guard — nil = no highlighting, no perf cost |
| `Highlight()` with `lineNumbers=false` for content previews | Custom
gutter is already rendered; `Highlight` handles tab expansion,
normalization, tokenisation |
| `contentPreviewLimit` cap applied after highlighting | Lexing only
processes the shown lines (default 50), no unbounded work |
| LLM format also gets chroma | Diff output already has ANSI backgrounds
from #865; chroma tokens are additive readability improvement |

## Testing

- `task precommit:run` — all hooks pass
- Existing `TestDiffRenderer_*` tests pass
- New `TestDiffRenderer_SyntaxHighlight_*` tests pass

Closes #866
@edenreich edenreich moved this from QA to Done in 2026 Jul 12, 2026
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.143.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

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

1 participant