Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
feat(console): group earlier tool calls in a chat turn
raullopez-sandbox62ea06150b88
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-activity-block.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-activity-block.tsxindex 15cd9e3f0..55743b77b 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-activity-block.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-activity-block.tsx@@ -8,15 +8,11 @@ import type { ChatActivityItem, ChatApproval } from '@shared/core/chats/activityimport { reasoningLabel } from '@shared/core/sessions/reasoning';import { isThinking, toolState, type TurnActivity, turnTools } from '../activity-join';import type { AgentActivity } from '../stores/chat-activity-store';-import { presentTool, summarizeTools } from '../tool-presentation';import { Reasoning } from '../ui/reasoning';import { FailedIcon, ThinkingIcon, ToolKindIcon, WorkLogDetails, WorkLogRow } from '../ui/work-log';import { ChatApprovalCard } from './chat-approval-card';import { ToolRow } from './tool-row';-/** A settled turn with at least this many tool calls folds them behind one summary line. */-const GROUP_AT = 2;-function ToolRows({items,turn,@@ -41,9 +37,9 @@ function ToolRows({}/**- * A finished turn's tool calls as one line ("Ran 2 commands and read 3- * files"), opening to the calls themselves. A failure is named on the line so- * it is not hidden by the fold.+ * The turn's earlier tool calls as one line ("12 tool calls"), opening to the+ * calls themselves. A failure is named on the line so it is not hidden by the+ * fold.*/function ToolGroup({items,@@ -55,17 +51,14 @@ function ToolGroup({activity: AgentActivity;}) {const [open, setOpen] = useState(false);- const summary = summarizeTools(- items.map((item) => presentTool(item, activity.toolDetails.get(item.itemId) ?? null).kind)- );const failed = items.filter((item) => toolState(item, turn.status) === 'failed').length;return (<WorkLogRow- icon={<ToolKindIcon kind={summary.kind} />}- label={summary.label}+ icon={<ToolKindIcon kind="other" />}+ label={`${items.length} ${items.length === 1 ? 'tool call' : 'tool calls'}`}trailing={failed > 0 ? (- <span className="shrink-0 text-xs text-foreground-destructive">{failed} failed</span>+ <span className="shrink-0 text-xs text-foreground-destructive">· {failed} failed</span>) : null}open={open}@@ -199,11 +192,9 @@ export const ChatActivityBlock = observer(function ChatActivityBlock({text={reasoning?.text ?? ''}/>)}- {!running && work.length >= GROUP_AT ? (- <ToolGroup items={work} turn={turn} activity={activity} />- ) : (- <ToolRows items={work} turn={turn} activity={activity} />- )}+ {/* Only the latest call gets a full line; the ones before it fold into one. */}+ {work.length > 1 && <ToolGroup items={work.slice(0, -1)} turn={turn} activity={activity} />}+ <ToolRows items={work.slice(-1)} turn={turn} activity={activity} />{turnWarnings(turn).map((notice) => (<WorkLogRowkey={notice.itemId}diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/tool-presentation.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/tool-presentation.tsindex 79c6c14a9..125767a7d 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/tool-presentation.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/tool-presentation.ts@@ -334,35 +334,3 @@ export function shortPath(path: string): string {const parts = path.split('/').filter(Boolean);return parts.length > 3 ? `…/${parts.slice(-3).join('/')}` : path;}--const COUNTED: Record<Exclude<ToolKind, 'switch'>, (count: number) => string> = {- shell: (n) => `Ran ${n} ${n === 1 ? 'command' : 'commands'}`,- read: (n) => `Read ${n} ${n === 1 ? 'file' : 'files'}`,- edit: (n) => `Edited ${n} ${n === 1 ? 'file' : 'files'}`,- search: (n) => `Searched ${n} ${n === 1 ? 'time' : 'times'}`,- web: (n) => `Searched the web ${n} ${n === 1 ? 'time' : 'times'}`,- agent: (n) => `Ran ${n} ${n === 1 ? 'agent' : 'agents'}`,- todo: (n) => `Updated the to-do list${n === 1 ? '' : ` ${n} times`}`,- mcp: (n) => `Called ${n} ${n === 1 ? 'tool' : 'tools'}`,- other: (n) => `Used ${n} ${n === 1 ? 'tool' : 'tools'}`,-};--/**- * One line for a run of tool calls, by kind in the order each first appears:- * "Ran 2 commands, read 3 files and edited 1 file". The kind is the icon's- * when every call shares it, and null when they are mixed.- */-export function summarizeTools(kinds: ToolKind[]): { label: string; kind: ToolKind | null } {- const counts = new Map<Exclude<ToolKind, 'switch'>, number>();- for (const kind of kinds) {- const counted = kind === 'switch' ? 'other' : kind;- counts.set(counted, (counts.get(counted) ?? 0) + 1);- }- const parts = [...counts].map(([kind, count], index) => {- const text = COUNTED[kind](count);- return index === 0 ? text : text.charAt(0).toLowerCase() + text.slice(1);- });- const label =- parts.length < 2 ? (parts[0] ?? '') : `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)}`;- return { label, kind: counts.size === 1 ? kinds[0]! : null };-}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-tool-group.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-tool-group.test.tsxnew file mode 100644index 000000000..687faed40--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-tool-group.test.tsx@@ -0,0 +1,118 @@+/**+ * A turn's tool calls: only the latest gets a full line, the ones before it+ * fold into one "N tool calls" line that names failures and opens in place.+ */+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, expect, it, vi } from 'vitest';+import { ChatActivityBlock } from '@renderer/features/chats/components/chat-activity-block';+import {+ type ActivityApi,+ AgentActivities,+} from '@renderer/features/chats/stores/chat-activity-store';+import type { ChatActivityItem } from '@shared/core/chats/activity';++let container: HTMLDivElement | null = null;+let root: Root | null = null;++afterEach(async () => {+ if (root) await act(async () => root!.unmount());+ container?.remove();+ container = null;+ root = null;+});++function item(itemId: string, status: string, title = ''): ChatActivityItem {+ return {+ agentId: 'agent-a',+ sessionId: 's1',+ turnId: 't1',+ itemId,+ kind: itemId === 'turn' ? 'turn' : 'tool-activity',+ revision: 1,+ status,+ title,+ text: '',+ commandId: null,+ roomId: 'room-1',+ threadId: null,+ messageId: 'm1',+ occurredAt: `2026-01-01T00:00:0${itemId.replace(/\D/g, '') || 0}Z`,+ createdAt: '2026-01-01T00:00:00Z',+ updatedAt: '2026-01-01T00:00:00Z',+ } as ChatActivityItem;+}++async function render(items: ChatActivityItem[]): Promise<HTMLDivElement> {+ const api: ActivityApi = {+ resolve: async () => ({+ kind: 'session',+ target: { kind: 'local' } as never,+ hostAgentKey: 'agent-local',+ sessionId: 's1',+ }),+ reasoning: async () => null,+ watchPlacements: () => () => {},+ roomActivity: async () => ({ items, approvals: [] }),+ roomMessages: () => [],+ control: vi.fn(),+ retrySupport: async () => 'no',+ answerApproval: async () => {+ throw new Error('unused');+ },+ };+ const activities = new AgentActivities(api, { getItem: () => null, setItem: () => {} });+ const activity = activities.acquire('server', 'tenant', 'room-1', 'agent-a');+ await vi.waitFor(() => expect(activity.turns().size).toBe(1));+ const turn = activity.turns().get('m1')!;+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ await act(async () =>+ root!.render(+ <QueryClientProvider client={new QueryClient()}>+ <ChatActivityBlock+ activity={activity}+ turn={turn}+ agent={{ name: 'helper', iconUrl: null }}+ head+ endReason={null}+ serverId="server"+ />+ </QueryClientProvider>+ )+ );+ return container;+}++const rows = (el: HTMLElement) =>+ [...el.querySelectorAll('[data-slot="work-log-row"]')].map((r) => r.textContent ?? '');++it('folds the earlier calls of a running turn and keeps the latest on its own line', async () => {+ const el = await render([+ item('turn', 'running'),+ item('tool1', 'completed', 'Bash git status'),+ item('tool2', 'failed', 'Bash git push'),+ item('tool3', 'completed', 'Bash git log'),+ item('tool4', 'in_progress', 'Bash git remote -v'),+ ]);+ const group = [...el.querySelectorAll('button')].find((b) =>+ b.textContent?.startsWith('3 tool calls')+ )!;+ expect(group.textContent).toContain('· 1 failed');+ expect(group.getAttribute('aria-expanded')).toBe('false');+ expect(rows(el).filter((r) => r.includes('git remote -v'))).toHaveLength(1);+ expect(el.textContent).not.toContain('git status');++ await act(async () => group.click());+ expect(group.getAttribute('aria-expanded')).toBe('true');+ expect(el.textContent).toContain('git status');+ expect(el.textContent).toContain('git push');+});++it('shows a single call with no group line', async () => {+ const el = await render([item('turn', 'completed'), item('tool1', 'completed', 'Bash ls')]);+ expect(el.textContent).not.toMatch(/tool calls?/);+ expect(el.textContent).toContain('ls');+});diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-tool-presentation.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-tool-presentation.test.tsindex 167a0abe5..870073e61 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-tool-presentation.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-tool-presentation.test.ts@@ -1,6 +1,6 @@import type { Item } from '@switch-console/shared/session-v1';import { describe, expect, it } from 'vitest';-import { presentTool, shortPath, summarizeTools } from '@renderer/features/chats/tool-presentation';+import { presentTool, shortPath } from '@renderer/features/chats/tool-presentation';import type { ToolDetail } from '@shared/core/sessions/reasoning';function item(title: string, status: Item['status'] = 'completed'): Item {@@ -159,20 +159,6 @@ describe('presentTool', () => {});});-describe('summarizeTools', () => {- it('counts each kind in the order it first appears', () => {- expect(summarizeTools(['shell', 'read', 'read', 'edit'])).toEqual({- label: 'Ran 1 command, read 2 files and edited 1 file',- kind: null,- });- expect(summarizeTools(['read', 'read'])).toEqual({ label: 'Read 2 files', kind: 'read' });- expect(summarizeTools(['switch', 'switch', 'shell'])).toEqual({- label: 'Used 2 tools and ran 1 command',- kind: null,- });- });-});-it('keeps the end of a long path, which is the part a reader looks for', () => {expect(shortPath('/Users/me/repo/src/stores/chat.ts')).toBe('…/src/stores/chat.ts');expect(shortPath('src/a.ts')).toBe('src/a.ts');