Skip to content

feat(tui): fold tool runs and thinking into a compact view (ctrl+d) - #804

Merged
huichen merged 1 commit into
mainfrom
feat/tui-compact
Sep 23, 2026
Merged

huichen merged 1 commit into
mainfrom
feat/tui-compact

Conversation

@huichen

@huichen huichen commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

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 in packages/thread-projection/src/group.ts does 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+d toggles 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).

▸ thinking ×2
▸ read 3 files
▸ $ 4 commands
▸ mcp_thing ×3
  • What a run is: an uninterrupted stretch of the same kind — completed calls to one tool, or thinking-only assistant blocks. Folded rows carry the fold marker, the tool and the tally.
  • What breaks a run: a text answer, a user turn, a still-running call, a failed call. A fold therefore never hides work in progress or a failure reason, and a ▸ row is always homogeneous.
  • Counting matches the desktop/mobile rule (group.ts): file tools count distinct files (a burst that read the same file four times says read 1 file), shell counts every call, an unknown tool counts calls. A call whose arguments the fold cannot read is still counted.
  • Interaction with the other view keys: 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.

How

ChatArea::compact_heads derives 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:

  • appending a message that renders its own rows keeps the fast path (every earlier message's rows are untouched);
  • a fold appearing — a running call completing into the run above it, which rewrites an earlier message's row — rebuilds the transcript;
  • re-rendering a message whose rows live in a run's summary is skipped (nothing about it is on screen individually).

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_end carrying error (or a non-zero exit_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 replayed isError path already worked, with the agent's is_soft_fail respected so a bare grep/diff exiting 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+g disabling folds, ctrl+o hiding the marker, and the incremental-vs-fresh layout invariant.
  • tui/src/app.rs — ctrl+d through 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 workspace streams 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.md and tui.zh-CN.md; the /help card and the /keymap panel list ctrl+d, so it is rebindable like every other action.

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.
@huichen
huichen enabled auto-merge (squash) September 23, 2026 13:30
@huichen
huichen merged commit d00101d into main Sep 23, 2026
12 checks passed
@huichen
huichen deleted the feat/tui-compact branch September 23, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant