Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(chat): fold runs of tool calls into collapsed blocks in the ⌘M chat view

Paul Robertsonfc8712415fc1
diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.ts
index 7b302fce0..047f3062e 100644
--- a/src/core/transcript-reader.ts
+++ b/src/core/transcript-reader.ts
@@ -10,7 +10,7 @@ import { linkedClaudeConfigDirFor } from './claude-config-dir'
import { platform } from './platform'
import { toolBody } from './chat-tool-body'
import { ASK_USER_QUESTION_TOOL, readQuestions } from '../shared/agents/permission-answer'
-import { BASH_COMMAND_TOOL, CHAT_TOOL_ARG_MAX } from '../shared/chat-command'
+import { BASH_COMMAND_TOOL, CHAT_TOOL_ARG_MAX, COMMAND_OUTPUT_TOOL } from '../shared/chat-command'
import {
AGENT_MESSAGE_TOOL,
BACKGROUND_TASK_TOOL,
@@ -184,8 +184,7 @@ export function classifyLocalCommand(content: string): LocalCommandRecord | null
return null
}
-/** The name an output record's tool part gets when there is no command to attach it to. */
-export const COMMAND_OUTPUT_TOOL = 'command output'
+export { COMMAND_OUTPUT_TOOL }
// ── System-injected user records ─────────────────────────────────────────────────────────────────
// Claude Code writes several things that are NOT the user's words as `type:"user"` records. Measured
diff --git a/src/renderer/lib/chatToolGroups.test.ts b/src/renderer/lib/chatToolGroups.test.ts
new file mode 100644
index 000000000..f220e940d
--- /dev/null
+++ b/src/renderer/lib/chatToolGroups.test.ts
@@ -0,0 +1,125 @@
+import { describe, expect, it } from 'vitest'
+import type { ChatMessage, ChatPart } from '@shared/types'
+import { BACKGROUND_TASK_TOOL } from '@shared/chat-system-records'
+import { COMMAND_OUTPUT_TOOL } from '@shared/chat-command'
+import { groupToolCalls, partPosition, toolGroupSummary } from './chatToolGroups'
+
+const tool = (name: string, extra: Partial<Extract<ChatPart, { kind: 'tool' }>> = {}): ChatPart => ({
+ kind: 'tool',
+ name,
+ arg: '',
+ ...extra
+})
+const call = (name: string, key?: number): ChatMessage => ({ role: 'assistant', parts: [tool(name)], key })
+const say = (text: string): ChatMessage => ({ role: 'assistant', parts: [{ kind: 'text', text }] })
+const think = (text: string): ChatMessage => ({ role: 'assistant', parts: [{ kind: 'thinking', text }] })
+const user = (text: string): ChatMessage => ({ role: 'user', parts: [{ kind: 'text', text }] })
+
+/** Each group as the positions of its members, in thread order. */
+function runs(messages: ChatMessage[]): string[][] {
+ const layout = groupToolCalls(messages)
+ return [...layout.groupAt.values()].map((g) => g.members.map((m) => partPosition(m.message, m.part)))
+}
+
+describe('groupToolCalls', () => {
+ it('folds consecutive tool calls across messages, one call per transcript line', () => {
+ const messages = [user('go'), call('Bash'), call('Read'), call('Bash')]
+
+ const layout = groupToolCalls(messages)
+
+ expect(runs(messages)).toEqual([['1:0', '2:0', '3:0']])
+ expect([...layout.absorbed]).toEqual(['2:0', '3:0'])
+ })
+
+ it('leaves a single tool call as a plain chip', () => {
+ const messages = [say('looking'), call('Read'), say('found it')]
+
+ const layout = groupToolCalls(messages)
+
+ expect(layout.groupAt.size).toBe(0)
+ expect(layout.absorbed.size).toBe(0)
+ })
+
+ it('starts a new block after text and after a thinking summary, like the TUI', () => {
+ const messages = [call('Bash'), call('Bash'), think('so the test is flaky'), call('Read'), call('Edit'), say('done'), call('Bash'), call('Bash')]
+
+ const result = runs(messages)
+
+ expect(result).toEqual([
+ ['0:0', '1:0'],
+ ['3:0', '4:0'],
+ ['6:0', '7:0']
+ ])
+ })
+
+ it('folds several tool parts inside one message, and stops at a text part between them', () => {
+ const messages: ChatMessage[] = [
+ { role: 'assistant', parts: [tool('Read'), tool('Grep'), { kind: 'text', text: 'hmm' }, tool('Bash')] },
+ call('Bash')
+ ]
+
+ const result = runs(messages)
+
+ expect(result).toEqual([
+ ['0:0', '0:1'],
+ ['0:3', '1:0']
+ ])
+ })
+
+ it('never folds a plan or question card, the user turn, a system record, or a local command', () => {
+ const messages: ChatMessage[] = [
+ call('Bash'),
+ { role: 'assistant', parts: [tool('ExitPlanMode', { body: '# plan' })] },
+ call('Bash'),
+ user('ok'),
+ call('Bash'),
+ { role: 'assistant', parts: [tool(BACKGROUND_TASK_TOOL)] },
+ call('Bash'),
+ { role: 'assistant', parts: [tool('/model')] },
+ { role: 'assistant', parts: [tool('!')] },
+ { role: 'assistant', parts: [tool(COMMAND_OUTPUT_TOOL)] },
+ call('Bash')
+ ]
+
+ const layout = groupToolCalls(messages)
+
+ expect(layout.groupAt.size).toBe(0)
+ })
+
+ it('keys a group by its first line offset, so it keeps its key while the run grows', () => {
+ const before = groupToolCalls([user('go'), call('Bash', 100), call('Read', 200)])
+ const after = groupToolCalls([user('go'), call('Bash', 100), call('Read', 200), call('Edit', 300)])
+
+ const keyBefore = before.groupAt.get('1:0')?.key
+ const keyAfter = after.groupAt.get('1:0')?.key
+
+ expect(keyBefore).toBe('k100:0')
+ expect(keyAfter).toBe(keyBefore)
+ })
+
+ it('keys an unpaged thread by position', () => {
+ const layout = groupToolCalls([user('go'), call('Bash'), call('Read')])
+
+ expect(layout.groupAt.get('1:0')?.key).toBe('i1:0')
+ })
+})
+
+describe('toolGroupSummary', () => {
+ it('counts the calls and lists the tools, most-used first', () => {
+ const messages = [call('Read'), call('Bash'), call('Bash'), call('Edit'), call('Bash')]
+ const group = [...groupToolCalls(messages).groupAt.values()][0]
+
+ const summary = toolGroupSummary(messages, group)
+
+ expect(summary).toEqual({ count: '5 tool calls', names: 'Bash ×3, Read, Edit' })
+ })
+
+ it('names at most three tools and counts the rest', () => {
+ const messages = ['A', 'B', 'C', 'D', 'E'].map((n) => call(n))
+ const group = [...groupToolCalls(messages).groupAt.values()][0]
+
+ const summary = toolGroupSummary(messages, group)
+
+ expect(summary.names).toBe('A, B, C +2 more')
+ })
+})
diff --git a/src/renderer/lib/chatToolGroups.ts b/src/renderer/lib/chatToolGroups.ts
new file mode 100644
index 000000000..71274d350
--- /dev/null
+++ b/src/renderer/lib/chatToolGroups.ts
@@ -0,0 +1,109 @@
+// Which tool calls the ⌘M thread folds into one collapsed block (ChatPanel). No React — see
+// ChatPanel.tsx for the glue and chatToolGroups.test.ts for the pins.
+//
+// The agent's TUI collapses a run of tool calls into one line ("ran 3 shell commands") and prints
+// its thinking-out-loud lines between those runs. The thread used to show every call as its own
+// chip, so a busy turn read as a wall of `Bash` / `Read` with the text that explains it buried in
+// between. A run is folded into one block, closed by default, that opens to the same chips.
+import type { ChatMessage, ChatPart } from '@shared/types'
+import { isSystemRecordMessage } from '@shared/chat-system-records'
+import { isLocalCommandTool } from '@shared/chat-command'
+
+/** Fewer calls than this stay as plain chips: a block holding one chip only adds a click. */
+export const TOOL_GROUP_MIN = 2
+
+/** How many tool names the closed block lists before "+N more". */
+export const TOOL_GROUP_NAMES_SHOWN = 3
+
+export interface ToolGroupMember {
+ message: number
+ part: number
+}
+
+export interface ToolGroup {
+ /** Stable while the run grows: the first member's line offset (paged reads) or position. */
+ key: string
+ members: ToolGroupMember[]
+}
+
+export interface ToolGroupLayout {
+ /** `${message}:${part}` of a group's FIRST member → the group, drawn in that member's place. */
+ groupAt: Map<string, ToolGroup>
+ /** Every other member: drawn inside its group, not at its own place. */
+ absorbed: Set<string>
+}
+
+export const partPosition = (message: number, part: number): string => `${message}:${part}`
+
+/**
+ * A tool call the agent made, shown as a chip. Not one:
+ * - a plan / question card (`body`): that IS the content, never folded away;
+ * - the user's own `/command`, `!` line or command output: the person did that, not the agent;
+ * - a system record (a background task finishing, another agent's message): it is not the agent's
+ * work either, and the thread already treats it as a turn boundary.
+ */
+function isFoldableTool(p: ChatPart): boolean {
+ return p.kind === 'tool' && p.body === undefined && !isLocalCommandTool(p.name)
+}
+
+/**
+ * The runs of consecutive tool calls, across message boundaries: a transcript writes each call as
+ * its own line, so the thread holds one message per call. A run ends at anything else in the thread
+ * — text, a thinking summary, a card, a user message, a system record — exactly where the TUI starts
+ * a new line. Runs shorter than `TOOL_GROUP_MIN` stay as chips.
+ */
+export function groupToolCalls(messages: readonly ChatMessage[]): ToolGroupLayout {
+ const groupAt = new Map<string, ToolGroup>()
+ const absorbed = new Set<string>()
+ let run: ToolGroupMember[] = []
+ const flush = (): void => {
+ if (run.length >= TOOL_GROUP_MIN) {
+ const first = run[0]
+ const key = messages[first.message].key
+ groupAt.set(partPosition(first.message, first.part), {
+ key: key !== undefined ? `k${key}:${first.part}` : `i${first.message}:${first.part}`,
+ members: run
+ })
+ for (const m of run.slice(1)) absorbed.add(partPosition(m.message, m.part))
+ }
+ run = []
+ }
+ messages.forEach((m, i) => {
+ if (m.role !== 'assistant' || isSystemRecordMessage(m)) {
+ flush()
+ return
+ }
+ m.parts.forEach((p, j) => {
+ if (isFoldableTool(p)) run.push({ message: i, part: j })
+ else flush()
+ })
+ })
+ flush()
+ return { groupAt, absorbed }
+}
+
+/**
+ * The closed block's one line: how many calls, then which tools, most-used first (ties in the order
+ * they ran), e.g. `5 tool calls` / `Bash ×3, Read, Edit`. The names are the agent's own tool names,
+ * not verbs, so the line reads the same for every agent.
+ */
+export function toolGroupSummary(
+ messages: readonly ChatMessage[],
+ group: ToolGroup
+): { count: string; names: string } {
+ const counts = new Map<string, number>()
+ for (const { message, part } of group.members) {
+ const p = messages[message]?.parts[part]
+ if (p?.kind !== 'tool') continue
+ counts.set(p.name, (counts.get(p.name) ?? 0) + 1)
+ }
+ // `Map` keeps first-run order, and `sort` is stable, so ties keep it.
+ const ranked = [...counts].sort((a, b) => b[1] - a[1])
+ const shown = ranked.slice(0, TOOL_GROUP_NAMES_SHOWN).map(([name, n]) => (n > 1 ? `${name} ×${n}` : name))
+ const hidden = ranked.length - shown.length
+ const n = group.members.length
+ return {
+ count: `${n} tool call${n === 1 ? '' : 's'}`,
+ names: hidden > 0 ? `${shown.join(', ')} +${hidden} more` : shown.join(', ')
+ }
+}
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index 04b4053d7..e1dec6cc3 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -14,7 +14,7 @@ import {
screenBlockedSentence,
type ScreenBlock
} from '../lib/chatSendGate'
-import type { ChatMessage } from '@shared/types'
+import type { ChatMessage, ChatPart } from '@shared/types'
import { chatPaneRefusal, chatPaneRefusalToast } from '../lib/chatPaneGate'
import { chatAgentLabel, isNearBottom, shouldFollowOnLoad, toolCardTitle, unseenAfter } from '../lib/chatPanel'
import { useSettings } from '../state/settings'
@@ -56,6 +56,8 @@ import { ChatComposer } from './ChatComposer'
import { ChatTurnActions } from './ChatTurnActions'
import { useCodeBlockCopy } from './CodeBlockCopy'
import { assistantTurnEnds } from '../lib/chatThread'
+import { groupToolCalls, partPosition } from '../lib/chatToolGroups'
+import { ChatToolGroup } from './ChatToolGroup'
import { FALLBACK_SESSION_NOTE, transcriptReadCwd } from '../lib/transcriptSession'
import { chatPageDirection, pageChatThread } from '../lib/chatPageKeys'
@@ -966,6 +968,8 @@ export function ChatPanel({
// the turn's last message. `now` is ONE clock for every row's relative time, ticked once a minute
// (a per-row timer would be a timer per turn for a label that changes once a minute).
const turnEnds = useMemo(() => assistantTurnEnds(messages), [messages])
+ // Runs of consecutive tool calls, folded into one closed block each (lib/chatToolGroups.ts).
+ const toolGroups = useMemo(() => groupToolCalls(messages), [messages])
// The last key IS the latest turn end: `assistantTurnEnds` inserts in thread order.
const latestTurnEnd = useMemo(() => {
let last = -1
@@ -978,6 +982,58 @@ export function ChatPanel({
return () => clearInterval(t)
}, [])
+ // One part of a message, as the thread draws it. Also used for the members of a folded tool block,
+ // which are drawn inside the block instead of at their own place (lib/chatToolGroups.ts).
+ const renderPart = (p: ChatPart, i: number, j: number, key: string | number = j): JSX.Element =>
+ p.kind === 'text' ? (
+ <MarkdownText key={key} text={p.text} />
+ ) : p.kind === 'thinking' ? (
+ // Claude's thinking summary — the "thinking out loud" line its TUI prints between
+ // tool calls. Shown inline like the TUI does, dimmed so it never reads as the answer.
+ <div key={key} className="term-chat__thinking">
+ <MarkdownText text={p.text} />
+ </div>
+ ) : p.body ? (
+ // A plan / question is the content itself, not plumbing: shown expanded, in full,
+ // flowing with the thread (no inner scroll box). The answer stays under it.
+ <div key={key} className="term-chat__tool-card">
+ <div className="term-chat__tool-card-title">{toolCardTitle(p.name)}</div>
+ <MarkdownText text={p.body} />
+ {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}
+ {answerCard && answerCard.card.message === i && answerCard.card.part === j && (
+ // Keyed by the BOUND ticket: a new hold on the same card starts from a clean
+ // state, and every answer names the request this card was drawn for.
+ p.name === 'AskUserQuestion' && p.questions ? (
+ <QuestionAnswerControls
+ key={answerCard.pendingId}
+ questions={p.questions}
+ agentLabel={agentLabel}
+ chip={mdChip}
+ onSubmit={(a) => answerHeld(answerCard.pendingId, a)}
+ />
+ ) : (
+ <PlanAnswerControls
+ key={answerCard.pendingId}
+ agentLabel={agentLabel}
+ chip={mdChip}
+ onSubmit={(a) => answerHeld(answerCard.pendingId, a)}
+ />
+ )
+ )}
+ {updatingCard && updatingCard.message === i && updatingCard.part === j && (
+ <AnswerControlsUpdating chip={mdChip} />
+ )}
+ </div>
+ ) : (
+ <details key={key} className="term-chat__tool">
+ <summary>
+ <span className="term-chat__tool-name">{p.name}</span>
+ {p.arg && <span className="term-chat__tool-arg">{p.arg}</span>}
+ </summary>
+ {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}
+ </details>
+ )
+
// A tail that yielded no message but has history behind it (all-metadata records, or a window a
// single huge record filled) is STILL LOADING — the panel pages back by itself from here. Saying
// "No conversation yet." there, until the older page landed, told the user a session with a
@@ -1049,77 +1105,40 @@ export function ChatPanel({
)}
</div>
)}
- {messages.map((m, i) => (
- // Keyed by the source line's byte offset: a prepended page does not re-key (and so does
- // not re-render) a single existing bubble. Unkeyed ones (grok, the optimistic sent
- // bubble) fall back to their position.
- <div
- key={m.key !== undefined ? `k${m.key}` : `i${i}`}
- className={`term-chat__msg term-chat__msg--${m.role}${m.role === 'user' ? ' term-chat__bubble' : ''}${
- queuedRef.current.has(m) ? ' term-chat__msg--queued' : ''
- }`}
- >
- {m.parts.map((p, j) =>
- p.kind === 'text' ? (
- <MarkdownText key={j} text={p.text} />
- ) : p.kind === 'thinking' ? (
- // Claude's thinking summary — the "thinking out loud" line its TUI prints between
- // tool calls. Shown inline like the TUI does, dimmed so it never reads as the answer.
- <div key={j} className="term-chat__thinking">
- <MarkdownText text={p.text} />
- </div>
- ) : p.body ? (
- // A plan / question is the content itself, not plumbing: shown expanded, in full,
- // flowing with the thread (no inner scroll box). The answer stays under it.
- <div key={j} className="term-chat__tool-card">
- <div className="term-chat__tool-card-title">{toolCardTitle(p.name)}</div>
- <MarkdownText text={p.body} />
- {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}
- {answerCard && answerCard.card.message === i && answerCard.card.part === j && (
- // Keyed by the BOUND ticket: a new hold on the same card starts from a clean
- // state, and every answer names the request this card was drawn for.
- p.name === 'AskUserQuestion' && p.questions ? (
- <QuestionAnswerControls
- key={answerCard.pendingId}
- questions={p.questions}
- agentLabel={agentLabel}
- chip={mdChip}
- onSubmit={(a) => answerHeld(answerCard.pendingId, a)}
- />
- ) : (
- <PlanAnswerControls
- key={answerCard.pendingId}
- agentLabel={agentLabel}
- chip={mdChip}
- onSubmit={(a) => answerHeld(answerCard.pendingId, a)}
- />
- )
- )}
- {updatingCard && updatingCard.message === i && updatingCard.part === j && (
- <AnswerControlsUpdating chip={mdChip} />
- )}
- </div>
- ) : (
- <details key={j} className="term-chat__tool">
- <summary>
- <span className="term-chat__tool-name">{p.name}</span>
- {p.arg && <span className="term-chat__tool-arg">{p.arg}</span>}
- </summary>
- {p.result && <pre className="term-chat__tool-result">{p.result}</pre>}
- </details>
- )
- )}
- {queuedRef.current.has(m) && <div className="term-chat__queued-label">Queued</div>}
- {turnEnds.has(i) && (
- <ChatTurnActions
- copyText={turnEnds.get(i)!.copyText}
- at={turnEnds.get(i)!.at}
- now={now}
- latest={i === latestTurnEnd}
- />
- )}
- </div>
- ))}
+ {messages.map((m, i) => {
+ // A message whose every part is drawn inside an earlier message's tool block has nothing of
+ // its own to draw, unless it ends a turn (its action row) or is queued.
+ const folded = m.parts.length > 0 && m.parts.every((_, j) => toolGroups.absorbed.has(partPosition(i, j)))
+ if (folded && !turnEnds.has(i) && !queuedRef.current.has(m)) return null
+ return (
+ // Keyed by the source line's byte offset: a prepended page does not re-key (and so does
+ // not re-render) a single existing bubble. Unkeyed ones (grok, the optimistic sent
+ // bubble) fall back to their position.
+ <div
+ key={m.key !== undefined ? `k${m.key}` : `i${i}`}
+ className={`term-chat__msg term-chat__msg--${m.role}${m.role === 'user' ? ' term-chat__bubble' : ''}${
+ queuedRef.current.has(m) ? ' term-chat__msg--queued' : ''
+ }`}
+ >
+ {m.parts.map((p, j) => {
+ const at = partPosition(i, j)
+ const group = toolGroups.groupAt.get(at)
+ if (group) return <ChatToolGroup key={group.key} messages={messages} group={group} renderPart={renderPart} />
+ if (toolGroups.absorbed.has(at)) return null
+ return renderPart(p, i, j)
+ })}
+ {queuedRef.current.has(m) && <div className="term-chat__queued-label">Queued</div>}
+ {turnEnds.has(i) && (
+ <ChatTurnActions
+ copyText={turnEnds.get(i)!.copyText}
+ at={turnEnds.get(i)!.at}
+ now={now}
+ latest={i === latestTurnEnd}
+ />
+ )}
+ </div>
+ )
+ })}
{screenBlock && (
<div className="term-chat__screen-block" role="status" aria-live="polite">
<div className="term-chat__screen-block-title">
diff --git a/src/renderer/nodes/ChatPanel.ux.test.tsx b/src/renderer/nodes/ChatPanel.ux.test.tsx
index b97884178..62cfbd476 100644
--- a/src/renderer/nodes/ChatPanel.ux.test.tsx
+++ b/src/renderer/nodes/ChatPanel.ux.test.tsx
@@ -198,6 +198,34 @@ describe('ChatPanel rendering', () => {
expect(answers).toEqual(['answer'])
})
+ it('folds a run of tool calls into one closed block that holds every call', async () => {
+ await render()
+ const call = (name: string, arg: string): ChatMessage => ({ role: 'assistant', parts: [{ kind: 'tool', name, arg }] })
+
+ await resolveAt(0, [
+ { role: 'user', parts: [{ kind: 'text', text: 'go' }] },
+ call('Bash', 'ls'),
+ call('Read', 'a.ts'),
+ call('Bash', 'pwd'),
+ { role: 'assistant', parts: [{ kind: 'thinking', text: 'now the fix' }] },
+ call('Edit', 'a.ts'),
+ { role: 'assistant', parts: [{ kind: 'text', text: 'done' }] }
+ ])
+
+ const groups = host.querySelectorAll('details.term-chat__tool-group')
+ expect(groups).toHaveLength(1)
+ const group = groups[0] as HTMLDetailsElement
+ expect(group.open).toBe(false)
+ expect(group.querySelector('summary')?.textContent).toBe('3 tool callsBash ×2, Read')
+ const inside = [...group.querySelectorAll('.term-chat__tool-arg')].map((e) => e.textContent)
+ expect(inside).toEqual(['ls', 'a.ts', 'pwd'])
+ // The lone Edit after the thinking line stays a plain chip, outside any block.
+ const loose = [...host.querySelectorAll('details.term-chat__tool')].filter((e) => !e.closest('.term-chat__tool-group'))
+ expect(loose.map((e) => e.querySelector('.term-chat__tool-name')?.textContent)).toEqual(['Edit'])
+ // The folded calls' own messages draw nothing of their own.
+ expect(host.querySelectorAll('.term-chat__msg')).toHaveLength(5)
+ })
+
it('asks for thinking summaries on the tail read', async () => {
await render()
diff --git a/src/renderer/nodes/ChatToolGroup.tsx b/src/renderer/nodes/ChatToolGroup.tsx
new file mode 100644
index 000000000..17954b899
--- /dev/null
+++ b/src/renderer/nodes/ChatToolGroup.tsx
@@ -0,0 +1,34 @@
+import type { ChatMessage, ChatPart } from '@shared/types'
+import { partPosition, toolGroupSummary, type ToolGroup } from '../lib/chatToolGroups'
+
+export interface ChatToolGroupProps {
+ messages: readonly ChatMessage[]
+ group: ToolGroup
+ /** ChatPanel's own part renderer, so a call inside the block is the same chip it is outside. */
+ renderPart(p: ChatPart, message: number, part: number, key: string): JSX.Element
+}
+
+/**
+ * A run of consecutive tool calls in the ⌘M thread, folded into one block that is closed by
+ * default and opens to the individual chips (lib/chatToolGroups.ts decides the runs).
+ *
+ * A native `<details>`, uncontrolled: ChatPanel keys it by the run's first line, so it stays the
+ * same element while the run grows and keeps whatever the user opened or closed.
+ */
+export function ChatToolGroup({ messages, group, renderPart }: ChatToolGroupProps): JSX.Element {
+ const { count, names } = toolGroupSummary(messages, group)
+ return (
+ <details className="term-chat__tool-group">
+ <summary>
+ <span className="term-chat__tool-group-count">{count}</span>
+ <span className="term-chat__tool-group-names">{names}</span>
+ </summary>
+ <div className="term-chat__tool-group-body">
+ {group.members.map(({ message, part }) => {
+ const p = messages[message]?.parts[part]
+ return p ? renderPart(p, message, part, partPosition(message, part)) : null
+ })}
+ </div>
+ </details>
+ )
+}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 38ae37982..97ae34567 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -3648,6 +3648,64 @@ body,
font-size: 11px;
opacity: 0.85;
}
+/* A run of consecutive tool calls folded into one block (nodes/ChatToolGroup.tsx), closed by
+ default. Closed, it is one chip-sized line: a chevron, the count, the tools used. Open, the same
+ chips follow, indented under a hairline so they read as belonging to the line above. */
+.term-chat__tool-group {
+ margin: 4px 0;
+ font-size: 12px;
+}
+.term-chat__tool-group > summary {
+ display: flex;
+ gap: 6px;
+ align-items: baseline;
+ padding: 4px 8px;
+ cursor: pointer;
+ list-style: none;
+ background: rgba(var(--tint-rgb), 0.04);
+ border: 1px solid rgba(var(--tint-rgb), 0.08);
+ border-radius: 8px;
+}
+.term-chat__tool-group > summary::-webkit-details-marker {
+ display: none;
+}
+/* The chevron is drawn, not a glyph: '▸' at this size renders as a dot. */
+.term-chat__tool-group > summary::before {
+ content: '';
+ flex: 0 0 auto;
+ align-self: center;
+ width: 5px;
+ height: 5px;
+ margin: 0 2px 0 1px;
+ border-right: 1.5px solid var(--muted);
+ border-bottom: 1.5px solid var(--muted);
+ transform: rotate(-45deg);
+ transition: transform 0.12s ease;
+}
+.term-chat__tool-group[open] > summary::before {
+ transform: rotate(45deg);
+}
+/* Same sizing rule as the chip's name/argument pair: the count never wraps, the names take the rest
+ and ellipsize. */
+.term-chat__tool-group-count {
+ flex: 0 0 auto;
+ white-space: nowrap;
+ font-weight: 600;
+ color: var(--accent);
+}
+.term-chat__tool-group-names {
+ flex: 1 1 auto;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ color: var(--muted);
+}
+.term-chat__tool-group-body {
+ margin: 4px 0 0 10px;
+ padding-left: 8px;
+ border-left: 1px solid rgba(var(--tint-rgb), 0.12);
+}
/* The agent's OWN dialog is on the pane's screen (ChatPanel's `screenBlock`): the sentence saying
where to answer it, then the dialog's lines as the terminal shows them. Shaped like a tool card
so it reads as part of the thread; monospace because the options are laid out in columns. */
diff --git a/src/shared/chat-command.ts b/src/shared/chat-command.ts
index 978fca0bb..6b5f02a36 100644
--- a/src/shared/chat-command.ts
+++ b/src/shared/chat-command.ts
@@ -10,6 +10,18 @@ export const CHAT_TOOL_ARG_MAX = 200
/** The tool-part name the reader gives a `!` bash-mode command. */
export const BASH_COMMAND_TOOL = '!'
+/** The name an output record's tool part gets when there is no command to attach it to. */
+export const COMMAND_OUTPUT_TOOL = 'command output'
+
+/**
+ * Whether a tool part is the USER's own local command (a `/slash` command, a `!` bash-mode line, or
+ * the output of one) rather than a tool the agent called. The reader writes both as assistant tool
+ * parts, so the thread can only tell them apart by name; agent tool names never start with `/`.
+ */
+export function isLocalCommandTool(name: string): boolean {
+ return name.startsWith('/') || name === BASH_COMMAND_TOOL || name === COMMAND_OUTPUT_TOOL
+}
+
/**
* The command a SENT text would become, or null when it is not one: `/name args` → `{name:"/name",
* arg}`, `!cmd` → `{name:"!", arg:"cmd"}`. Text is trimmed first (JS `trim`); `arg` is trimmed and