Skip to content

feat(tui): add focus view to collapse multi-step turns - #41264

Open
liush2yuxjtu wants to merge 3 commits into
anomalyco:devfrom
liush2yuxjtu:focus-turn-collapse
Open

feat(tui): add focus view to collapse multi-step turns#41264
liush2yuxjtu wants to merge 3 commits into
anomalyco:devfrom
liush2yuxjtu:focus-turn-collapse

Conversation

@liush2yuxjtu

@liush2yuxjtu liush2yuxjtu commented Aug 8, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #37003

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an opt-in TUI "focus view" toggle that collapses each multi-step assistant turn into one compact block: the turn's final text, a one-line summary of every tool call across the turn, and a hidden-message count. New messages update the block in place instead of appending more messages.

Why it works: a single prompt often produces several assistant messages (a tool-calls round, then a final text round), so the transcript floods with full tool output. Focus view groups messages by parentID into turns and only renders the last message of each turn as a collapsed block while enabled.

Toggle via command palette ("Enter/Exit focus view"), a /focus slash command, or a focus_view keybind (default none, configurable in tui.json). State persists across sessions. Disabled by default so existing behavior is unchanged.

This is an implementation of the collapse behavior requested in #37003, delivered as opt-in rather than default-on.

Design

A turn is the set of assistant messages sharing the same parentID (the user message). A multi-step reply emits a tool-calls round (finish="tool-calls") followed by a final text round (finish="stop").

Demo 1 · Turn structure — click a message card to highlight its timeline row (interactive):

https://github.com/liush2yuxjtu/opencode/releases/download/focus-demo-v1/fig1-highlight.webm

Demo 2 · Focus OFF vs ON — click either side to toggle full/collapsed view (interactive):

https://github.com/liush2yuxjtu/opencode/releases/download/focus-demo-v1/fig2-toggle.webm

Demo 3 · Message flow — the display block updates in place as new messages arrive (interactive):

https://github.com/liush2yuxjtu/opencode/releases/download/focus-demo-v1/fig3-flow.webm

Render rule

function renderTurn(turn, focusView) {
  if (!focusView) return turn.messages.map(renderMessage)
  const last = turn.messages.at(-1)            // final assistant message of the turn
  const tools = turn.messages.flatMap(toolsOf) // all tool calls across the turn
  if (!last.time.completed) return <StreamingTurn summary={toolsSummary(tools)} />
  return <CollapsedTurn text={last.textParts} summary={toolsSummary(tools)} hidden={tools.length} />
}

How did you verify your code works?

  • bun run typecheck (packages/tui) passes.
  • Ran a local bun dev session and verified:
    • Focus ON: a hello-world turn collapsed to ↳ 1 write, 1 bash · 3 messages hidden + final text, with a single turn footer (no duplicate lines from hidden intermediate messages).
    • Focus OFF: full tool output (Write diff, shell output) restored.

Screenshots / recordings

Focus ON (collapsed):

↳ 1 write, 1 bash · 3 messages hidden (toggle /focus to show)
Wrote /tmp/hello.ts and ran it with bun — output: Hello, world!

Focus OFF (full):

# Wrote /tmp/hello.ts
  1 console.log("Hello, world!")
$ bun /tmp/hello.ts
Hello, world!
Wrote /tmp/hello.ts and ran it with bun — output: Hello, world!

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 8, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@liushiyu052333-gif

liushiyu052333-gif commented Aug 8, 2026

Copy link
Copy Markdown
fig2-toggle.webm
fig3-flow.webm
fig1-highlight.webm

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.

[FEATURE]: Clean Output Mode: Collapse AI Work by Default

2 participants