Repository navigation
feat(tui): fold tool runs and thinking into a compact view (ctrl+d) - #804
Merged
Merged
Conversation
A long agent run is mostly calls and reasoning, and on the desktop and mobile those collapse into one summary row per uninterrupted burst. The TUI rendered every call as its own row, so a twenty-call run cost twenty rows of a terminal that has far fewer. `ctrl+d` now folds the transcript the same way, and leaves it off by default — the transcript renders exactly as it always did until the key is pressed. - A run is an *uninterrupted* stretch of the same kind: completed calls to one tool, or thinking-only assistant blocks. It folds into a single row (`▸ read 3 files`, `▸ $ 4 commands`, `▸ thinking ×2`). A text answer, a user turn, a still-running call or a failed one breaks the run, so a fold can never hide work in progress or a failure reason. - Counting matches the shared projection the desktop and mobile use (`packages/thread-projection/src/group.ts`): file tools count distinct files, shell counts every call, unknown tools count calls. - `ctrl+g` (expand every tool body) turns folding off — asking for the bodies and hiding the calls cannot both win — and `ctrl+o` still hides thinking entirely, marker included. - `ChatArea::compact_heads` derives the layout (which message renders the rows of which run) as a pure function, and the incremental render paths compare it against the layout the lines were built with: appending a standalone message keeps the fast path, while a fold appearing — a running call completing into the run above it — rebuilds the transcript. New tests assert the invariant directly: after any mutation, the incrementally rendered transcript equals a from-scratch layout, and the per-message line ranges stay non-overlapping. Also fixes a live-run bug the fold depends on: a `tool_end` with an `error` (or a non-zero `exit_code` that is not a soft fail) marked the call *completed*, so a failed shell command looked successful, kept no body, and — with the compact view on — was folded away. The status now comes from the event's own structured result, like the replayed `isError` already did. Tests: 15 new chat_area tests (fold/expand round-trips, per-kind labels, distinct-file counting, interleaved think/tool runs, failure handling, folding across prepended history, and the incremental-vs-fresh layout invariant), an app-level `ctrl+d` toggle test through the keybinding path, and `tool_end` failure classification. The tmux harness gained a burst scenario (`scan the workspace` makes the mock stream three reads): three call rows, one folded row, three rows again, asserted on the real rendered screen. Docs: the shortcut table and a "Compact view" section in `docs/guide/tui.md` / `tui.zh-CN.md`; the `/help` card and the `/keymap` panel list the new binding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On the desktop and mobile, an uninterrupted burst of tool calls collapses into one summary row (
Ran 4 commands,Edited 3 files), and the reasoning sits on one line — the shared projection inpackages/thread-projection/src/group.tsdoes the folding for both. The TUI rendered every call as its own row, so a twenty-call run cost twenty rows of a terminal that has far fewer.The user asked for the same thing in the TUI: keep the current rendering by default, and offer a shortcut that folds for vertical space.
What
ctrl+dtoggles a compact view. Off by default; the transcript renders exactly as it always did until the key is pressed, and toggling back restores it byte for byte (asserted).▸row is always homogeneous.group.ts): file tools count distinct files (a burst that read the same file four times saysread 1 file), shell counts every call, an unknown tool counts calls. A call whose arguments the fold cannot read is still counted.ctrl+g(expand every tool body) turns folding off — asking for the bodies and hiding the calls cannot both win — andctrl+ostill hides thinking entirely, marker included.How
ChatArea::compact_headsderives the layout — for each message, the index of the message that renders its rows — as a pure function of the transcript. The incremental render paths (rerender_message,append_last_message) compare that against the layout the rendered lines were built with:The new tests assert that invariant directly rather than trusting each path: after any sequence of mutations the incrementally rendered transcript must equal a from-scratch layout, and the per-message line ranges must stay non-overlapping and consistent. That is what catches a fold that a splice would have silently duplicated or dropped.
A live-run bug this surfaced
A
tool_endcarryingerror(or a non-zeroexit_code) marked the call completed, so a failed shell command looked successful, kept no body, and — with the compact view on — was folded away entirely. The status now comes from the event's own structured result, exactly as the replayedisErrorpath already worked, with the agent'sis_soft_failrespected so a baregrep/diffexiting 1 stays a completed call.Tests
tui/src/components/chat_area.rs— 15 new tests: fold/expand round-trip, per-kind labels, distinct-file counting, runs built one call at a time (as a live run builds them), interleaved think/tool runs, "never folds across an answer", failed calls keep their row and body, folds across prepended history,ctrl+gdisabling folds,ctrl+ohiding the marker, and the incremental-vs-fresh layout invariant.tui/src/app.rs—ctrl+dthrough the real key path (keybinding closure →KeyAction→ chat), the live failure classification, and a live event-stream test that a failed call is marked and not folded.tui/tests/tmux-diff.sh+ the mock — a new burst scenario (scan the workspacestreams three completed reads): the three call rows, the single folded row, and the three rows again, asserted on the real rendered screen with real keystrokes. All other goldens are unchanged apart from the two help screens, which is the check that nothing else moved.cargo test -p future-tui(2086),cargo fmt --check,cargo clippy --all-targets --no-deps -D warnings,tui/tests/tmux-diff.sh(57 passed).Docs
Shortcut table + a "Compact view" section in
docs/guide/tui.mdandtui.zh-CN.md; the/helpcard and the/keymappanel listctrl+d, so it is rebindable like every other action.