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
fix(console): target group chat controls per agent; read Codex Switch tool names
raullopez-sandboxd58da12d098a
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/activity-join.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/activity-join.tsindex c51965453..941b6c056 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/activity-join.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/activity-join.ts@@ -5,6 +5,7 @@ import {} from '@shared/core/chats/activity';import { type ChatMessage, isSessionStartingNotice, turnEndNotice } from '@shared/core/chats/chats';import { isControlAck } from './stop-rows';+import { switchTool } from './tool-presentation';/*** Joining an agent's turns, as Switch's activity feed stores them, to the@@ -251,9 +252,10 @@ export function toolState(item: Pick<ChatActivityItem, 'status'>, turn: TurnStat/** Tool calls whose only output is the room message the user already sees. */export function isHiddenTool(item: Pick<ChatActivityItem, 'title'>): boolean {+ const tool = switchTool(item.title);return (- /^mcp__switch__post_message(\s|$)/.test(item.title) ||- /^mcp__switch__send_targeted_message(\s|$)/.test(item.title) ||+ tool === 'post_message' ||+ tool === 'send_targeted_message' ||/^ToolSearch(\s|$)/.test(item.title));}diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsxindex d419138a7..070c9d331 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-composer.tsx@@ -205,7 +205,7 @@ export const ChatComposer = observer(function ChatComposer({agents,people,groupName,- activity,+ activities,replyTo,onClearReply,disabled,@@ -217,7 +217,8 @@ export const ChatComposer = observer(function ChatComposer({people: (MentionPerson & { email: string | null })[];/** The chat's name when it is a group, which is who a message goes to; null in a direct chat. */groupName: string | null;- activity: AgentActivity | null;+ /** One per agent in the chat. */+ activities: AgentActivity[];replyTo: ChatMessage | null;onClearReply: () => void;disabled: string | null;@@ -307,7 +308,11 @@ export const ChatComposer = observer(function ChatComposer({setDraft(next);};const [files, setFiles] = useState<{ id: string; file: File }[]>([]);- const [confirmReset, setConfirmReset] = useState(false);+ /** A Reset or Compact being set up: in a group its agents are picked first (null), then a Reset is confirmed. */+ const [contextStep, setContextStep] = useState<{+ command: 'reset' | 'compact';+ targets: AgentActivity[] | null;+ } | null>(null);const [contextOpen, setContextOpen] = useState(false);const picker = useRef<HTMLInputElement>(null);const input = useRef<HTMLTextAreaElement>(null);@@ -389,7 +394,12 @@ export const ChatComposer = observer(function ChatComposer({}, []);const agent = agents[0] ?? null;const recipient = groupName ?? (agent ? chatAgentLabel(agent) : 'the agent');- const stopActivity = activity?.runningTurn ? activity : null;+ const labelOf = (activity: AgentActivity) => {+ const owner = agents.find((each) => each.id === activity.agentId);+ return owner ? chatAgentLabel(owner) : 'the agent';+ };+ const group = activities.length > 1;+ const stopActivities = activities.filter((activity) => activity.runningTurn);const addFiles = (list: File[]) => {if (!list.length) return;@@ -503,23 +513,41 @@ export const ChatComposer = observer(function ChatComposer({onClearReply();};- const showStop = Boolean(stopActivity) && !draft.trim() && !files.length;- const stopping = stopActivity?.pendingControl?.command === 'interrupt';+ const showStop = stopActivities.length > 0 && !draft.trim() && !files.length;+ const stopping = stopActivities.some(+ (activity) => activity.pendingControl?.command === 'interrupt'+ );const status = stopping ? 'sending' : showStop ? 'running' : 'idle';// Not blocked while working: a turn whose host died stays running in the feed, and Reset is the way out.- const contextBlocked = activity?.pendingControl+ const contextBlocked = activities.some((activity) => activity.pendingControl)? 'Waiting for the previous command to be sent.': null;+ const runContext = (command: 'reset' | 'compact', targets: AgentActivity[]) => {+ setContextOpen(false);+ setContextStep(null);+ for (const activity of targets) void activity.control(command);+ };+ const pickContext = (command: 'reset' | 'compact') => {+ if (group) setContextStep({ command, targets: null });+ else if (command === 'reset') setContextStep({ command, targets: activities });+ else runContext(command, activities);+ };+ const choose = (targets: AgentActivity[]) => {+ if (contextStep?.command === 'reset') setContextStep({ command: 'reset', targets });+ else runContext('compact', targets);+ };+ const resetTargets = contextStep?.command === 'reset' ? contextStep.targets : null;return (<div className="mx-auto w-full max-w-[860px] px-5 pb-1.5">- {activity && (+ {activities.map((activity) => (<ControlStatus+ key={activity.agentId}activity={activity}timeline={timeline}- who={agent ? chatAgentLabel(agent) : 'the agent'}+ who={labelOf(activity)}/>- )}+ ))}{replyTo && (<div className="mb-2 flex items-center gap-2 rounded-md border border-border px-3 py-1.5 text-xs text-foreground-muted"><span className="min-w-0 flex-1 truncate">@@ -700,19 +728,23 @@ export const ChatComposer = observer(function ChatComposer({<PromptInputSubmitstatus={status}className="h-8 min-w-8"- onStop={() => void stopActivity?.control('interrupt')}- stopDisabledReason={stopActivity?.pendingControl ? 'Sending…' : null}+ onStop={() => {+ for (const activity of stopActivities) void activity.control('interrupt');+ }}+ stopDisabledReason={+ stopActivities.some((activity) => activity.pendingControl) ? 'Sending…' : null+ }disabled={disabled !== null || (!showStop && !draft.trim() && !files.length)}/></div></PromptInput><div className="mt-1.5 flex min-h-7 items-center justify-end gap-1 px-2">- {activity && (+ {activities.length > 0 && (<Popoveropen={contextOpen}onOpenChange={(open) => {setContextOpen(open);- setConfirmReset(false);+ setContextStep(null);}}><PopoverTrigger@@ -729,45 +761,80 @@ export const ChatComposer = observer(function ChatComposer({className="w-80 max-w-[calc(100vw-2rem)] gap-2 p-3"><PopoverTitle>- {confirmReset ? 'Start a fresh conversation?' : 'Conversation context'}+ {resetTargets+ ? group+ ? `Start a fresh conversation for ${resetTargets.length === 1 ? labelOf(resetTargets[0]!) : 'all agents'}?`+ : 'Start a fresh conversation?'+ : contextStep+ ? `${contextStep.command === 'reset' ? 'Reset' : 'Compact'} which agent?`+ : 'Conversation context'}</PopoverTitle>- {confirmReset ? (+ {resetTargets ? (<><p className="text-xs text-foreground-muted">- The agent starts with a fresh context. Earlier messages stay in the transcript- as history.+ {resetTargets.length === 1 ? 'The agent starts' : 'Each agent starts'} with a+ fresh context. Earlier messages stay in the transcript as history.</p><div className="flex justify-end gap-2 pt-2">- <Button size="sm" variant="ghost" onClick={() => setConfirmReset(false)}>+ <Button size="sm" variant="ghost" onClick={() => setContextStep(null)}>Cancel</Button><Buttonsize="sm"disabled={contextBlocked !== null}- onClick={() => {- setContextOpen(false);- setConfirmReset(false);- void activity.control('reset');- }}+ onClick={() => runContext('reset', resetTargets)}>Start fresh</Button></div></>+ ) : contextStep ? (+ <>+ <Button+ variant="ghost"+ disabled={contextBlocked !== null}+ className="justify-start px-2"+ onClick={() => choose(activities)}+ >+ All agents+ </Button>+ {activities.map((activity) => {+ const owner = agents.find((each) => each.id === activity.agentId);+ return (+ <Button+ key={activity.agentId}+ variant="ghost"+ disabled={contextBlocked !== null}+ className="justify-start gap-2 px-2"+ onClick={() => choose([activity])}+ >+ {owner && (+ <AgentAvatar+ name={owner.name}+ iconUrl={owner.iconUrl}+ serverId={serverId}+ size={20}+ />+ )}+ <span className="truncate">{labelOf(activity)}</span>+ </Button>+ );+ })}+ {contextBlocked && (+ <p className="text-xs text-foreground-muted">{contextBlocked}</p>+ )}+ </>) : (<><Buttonvariant="ghost"disabled={contextBlocked !== null}className="h-auto justify-start gap-3 px-2 py-2 text-left"- onClick={() => {- setContextOpen(false);- void activity.control('compact');- }}+ onClick={() => pickContext('compact')}><Minimize2 className="size-4 shrink-0" /><span>- <span className="block">Compact context</span>+ <span className="block">Compact context{group ? '...' : ''}</span><span className="block text-xs font-normal text-foreground-muted">Free up space in this conversation</span>@@ -777,7 +844,7 @@ export const ChatComposer = observer(function ChatComposer({variant="ghost"disabled={contextBlocked !== null}className="h-auto justify-start gap-3 px-2 py-2 text-left"- onClick={() => setConfirmReset(true)}+ onClick={() => pickContext('reset')}><RotateCcw className="size-4 shrink-0" /><span>diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsxindex d6766d578..f9216ee58 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-panel.tsx@@ -207,7 +207,7 @@ export const ChatPanel = observer(function ChatPanel({// Everyone but the viewer can be mentioned from here.people={people.members.filter((person) => person.userId !== chatsStore.userId)}groupName={chat && chat.channelType !== 'direct' ? chat.name : null}- activity={activities[0] ?? null}+ activities={activities}replyTo={replyTo}onClearReply={() => setReplyTo(null)}disabled={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 125767a7d..45464dc6d 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@@ -62,8 +62,17 @@ const WEB = new Set(['WebSearch', 'WebFetch', 'websearch', 'webfetch', 'web_searconst AGENT = new Set(['Task', 'Agent', 'task']);const TODO = new Set(['TodoWrite', 'TodoRead', 'todowrite', 'todoread']);-/** Tool names the Switch MCP server's tools carry, as Claude Code reports them. */-export const SWITCH_TOOL_PREFIX = 'mcp__switch__';+/**+ * A Switch tool's name as each provider titles it: Claude Code+ * `mcp__switch__post_message`, Codex `switch.post_message`, OpenCode+ * `switch_post_message`.+ */+const SWITCH_TOOL = /^(?:mcp__switch__|switch[._])(\w+)(?:\s|$)/;++/** The Switch tool a name or title calls (`post_message`), or null when it is not one. */+export function switchTool(name: string): string | null {+ return SWITCH_TOOL.exec(name)?.[1] ?? null;+}const SWITCH_LABELS: Record<string, string> = {connect_to_room: 'Connected to the room',@@ -87,7 +96,6 @@ function field(input: Record<string, unknown>, ...keys: string[]): string | null}function kindOf(name: string, type: string | null): ToolKind {- if (name.startsWith(SWITCH_TOOL_PREFIX)) return 'switch';if (SHELL.has(name) || type === 'command_execution') return 'shell';if (READ.has(name)) return 'read';if (EDIT.has(name) || type === 'file_change') return 'edit';@@ -222,7 +230,8 @@ export function presentTool(item: ToolItem, detail: ToolDetail | null): ToolPresconst running = item.status === 'in-progress';const titled = fromTitle(item.title);const name = detail?.toolName ?? titled.name;- const kind = kindOf(name, detail?.type ?? null);+ const tool = switchTool(name) ?? switchTool(item.title);+ const kind = tool ? 'switch' : kindOf(name, detail?.type ?? null);const input = isRecord(detail?.input) ? detail.input : {};const output = nonEmpty(detail?.output) ?? nonEmpty(item.text);const truncated = detail?.truncated ?? false;@@ -311,12 +320,11 @@ export function presentTool(item: ToolItem, detail: ToolDetail | null): ToolPrescase 'mcp':case 'other': {const mcp = mcpParts(name);- const label =- kind === 'switch'- ? (SWITCH_LABELS[mcp?.tool ?? ''] ?? `Switch: ${humanize(mcp?.tool ?? name)}`)- : mcp- ? `${humanize(mcp.server)}: ${humanize(mcp.tool)}`- : item.title || name;+ const label = tool+ ? (SWITCH_LABELS[tool] ?? `Switch: ${humanize(tool)}`)+ : mcp+ ? `${humanize(mcp.server)}: ${humanize(mcp.tool)}`+ : item.title || name;const shown = pretty(detail?.input);return {...base,diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-commands.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-commands.test.tsxindex 5b703b00a..8e9210bff 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-commands.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-commands.test.tsx@@ -52,7 +52,7 @@ async function render(): Promise<HTMLTextAreaElement> {agents={[]}people={[]}groupName="Ship review"- activity={null}+ activities={[]}replyTo={null}onClearReply={() => {}}disabled={null}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-group-controls.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-group-controls.test.tsxnew file mode 100644index 000000000..b94298dec--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-group-controls.test.tsx@@ -0,0 +1,157 @@+/**+ * In a group chat Stop reaches whichever agent is working, and Reset or+ * Compact goes to the agent picked, or to all of them.+ */+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';++vi.mock('@renderer/lib/ipc', () => ({+ events: { on: () => () => {} },+ rpc: { chats: { commands: async () => [] } },+}));+vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({+ useFeatureFlags: () => ({ group_chats: true }),+}));++import { ChatComposer } from '@renderer/features/chats/components/chat-composer';+import {+ type ActivityApi,+ AgentActivities,+} from '@renderer/features/chats/stores/chat-activity-store';+import {+ ChatTimeline,+ type TimelineApi,+} from '@renderer/features/chats/stores/chat-timeline-store';+import type { ChatActivityItem } from '@shared/core/chats/activity';+import type { ChatAgent } from '@shared/core/chats/chats';++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;+});++const agent = (id: string, name: string): ChatAgent => ({+ id,+ name,+ displayName: null,+ iconUrl: null,+ provider: null,+ alias: null,+ ownerName: null,+ ownedByViewer: false,+});++const runningTurn: ChatActivityItem = {+ agentId: 'agent-b',+ sessionId: 's1',+ turnId: 't1',+ itemId: 'turn',+ kind: 'turn',+ revision: 1,+ status: 'running',+ title: '',+ text: '',+ commandId: null,+ roomId: 'room-1',+ threadId: null,+ messageId: 'm1',+ occurredAt: '2026-01-01T00:00:00Z',+ createdAt: '2026-01-01T00:00:00Z',+ updatedAt: '2026-01-01T00:00:00Z',+};++async function render() {+ const control = vi.fn<ActivityApi['control']>(async (input) => `cmd-${input.requestId}`);+ const api: ActivityApi = {+ resolve: async () => ({ kind: 'none' }) as never,+ reasoning: async () => null,+ watchPlacements: () => () => {},+ roomActivity: async () => ({ items: [runningTurn], approvals: [] }),+ roomMessages: () => [],+ control,+ retrySupport: async () => 'unknown',+ answerApproval: async () => {+ throw new Error('unused');+ },+ };+ const store = new AgentActivities(api, {+ getItem: () => null,+ setItem: () => {},+ });+ const activities = ['agent-a', 'agent-b'].map((id) => store.acquire('s', 'tenant', 'room-1', id));+ await vi.waitFor(() => expect(activities[1]!.runningTurn).not.toBeNull());+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ await act(async () =>+ root!.render(+ <QueryClientProvider client={new QueryClient()}>+ <ChatComposer+ serverId="s"+ timeline={new ChatTimeline('room-1', {} as TimelineApi)}+ agents={[agent('agent-a', 'Alpha'), agent('agent-b', 'Beta')]}+ people={[]}+ groupName="Ship review"+ activities={activities}+ replyTo={null}+ onClearReply={() => {}}+ disabled={null}+ />+ </QueryClientProvider>+ )+ );+ return control;+}++const button = (label: string | RegExp) =>+ [...document.body.querySelectorAll('button')].find((each) =>+ typeof label === 'string'+ ? each.getAttribute('aria-label') === label || each.textContent?.trim() === label+ : label.test(each.textContent ?? '')+ );++const click = (label: string | RegExp) =>+ act(async () => {+ const found = button(label);+ if (!found) throw new Error(`no button ${label}`);+ found.click();+ });++const sent = (control: ReturnType<typeof vi.fn>) =>+ control.mock.calls.map(([input]) => [input.agentId, input.command]);++it('shows Stop when only the second agent is working, and stops that agent', async () => {+ const control = await render();+ expect(button('Stop reply')).toBeDefined();+ await click('Stop reply');+ expect(sent(control)).toEqual([['agent-b', 'interrupt']]);+});++it('resets only the agent picked, naming it before it is sent', async () => {+ const control = await render();+ await click('Context actions');+ await click(/^Reset context/);+ expect(document.body.textContent).toContain('Reset which agent?');+ await click(/Beta$/);+ expect(document.body.textContent).toContain('Start a fresh conversation for Beta?');+ await click('Start fresh');+ expect(sent(control)).toEqual([['agent-b', 'reset']]);+});++it('compacts every agent when all are picked', async () => {+ const control = await render();+ await click('Context actions');+ await click(/^Compact context/);+ await click('All agents');+ expect(sent(control)).toEqual([+ ['agent-a', 'compact'],+ ['agent-b', 'compact'],+ ]);+});diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsxindex bd8406159..e7d698d73 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-composer-mentions.test.tsx@@ -60,7 +60,7 @@ describe('ChatComposer mention badges', () => {agents={[agent]}people={[]}groupName="Ship review"- activity={null}+ activities={[]}replyTo={null}onClearReply={() => {}}disabled={null}@@ -118,7 +118,7 @@ describe('ChatComposer picked mentions', () => {agents={[sharer]}people={[{ userId: 'u1', name: 'Bob Member', email: '[email protected]' }]}groupName="Ship review"- activity={null}+ activities={[]}replyTo={null}onClearReply={() => {}}disabled={null}@@ -168,7 +168,7 @@ describe('ChatComposer on a server without group chats', () => {agents={[one, agent]}people={[{ userId: 'u1', name: 'Bob Member', email: null }]}groupName="Ship review"- activity={null}+ activities={[]}replyTo={null}onClearReply={() => {}}disabled={null}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsxindex b0a87ea1a..5aa330370 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-drafts.test.tsx@@ -80,7 +80,7 @@ async function mount(timeline: ChatTimeline): Promise<HTMLTextAreaElement> {agents={[agent]}people={[]}groupName="Ship review"- activity={null}+ activities={[]}replyTo={null}onClearReply={() => {}}disabled={null}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-activity.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-activity.test.tsindex 142898c3c..fd8dd1171 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-activity.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-activity.test.ts@@ -465,6 +465,18 @@ describe('bindTurns', () => {]);});+ it('hides Codex and OpenCode posts as it hides Claude Code ones', () => {+ const turn = turnOf(+ [+ row('t1', 'a', { title: 'switch.post_message' }),+ row('t1', 'b', { title: 'switch_send_targeted_message' }),+ row('t1', 'c', { title: 'switch.read_context' }),+ ],+ 'completed'+ );+ expect(turnTools(turn).map((each) => each.title)).toEqual(['switch.read_context']);+ });+it('shows an unfinished tool of an interrupted turn as failed', () => {const tool = row('t', 'tool', { status: 'in-progress' });expect(toolState(tool, 'running')).toBe('running');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 870073e61..090ac49a5 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@@ -159,6 +159,25 @@ describe('presentTool', () => {});});+it('reads Codex and OpenCode names for Switch tools as Claude Code ones', () => {+ for (const title of ['switch.post_message', 'switch_post_message'])+ expect(presentTool(item(title), null)).toMatchObject({+ kind: 'switch',+ verb: 'Posted to the room',+ });+ expect(+ presentTool(+ item('switch.read_context'),+ detail({ type: 'mcp_tool_call', toolName: 'read_context' })+ )+ ).toMatchObject({ kind: 'switch', verb: 'Read the room' });+ expect(presentTool(item('switch.list_bridges'), null)).toMatchObject({+ kind: 'switch',+ verb: 'Switch: list bridges',+ });+ expect(presentTool(item('switchboard'), null)).toMatchObject({ kind: 'other' });+});+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');