Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 还原子代理在对话流里的原有交互 (#2406)
Chris Zhangb86007f0a4bb
diff --git a/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.ts b/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.tsindex 9b3ca9fdcf..56c2f14e6b 100644--- a/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.ts+++ b/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.ts@@ -31,16 +31,12 @@ vi.mock('@/hooks/useExpandedBlockMemory', () => ({}),}));-const { openBackgroundTasksTabMock, openSubagentsTabMock } = vi.hoisted(() => ({+const { openBackgroundTasksTabMock } = vi.hoisted(() => ({openBackgroundTasksTabMock: vi.fn().mockResolvedValue(undefined),- openSubagentsTabMock: vi.fn().mockResolvedValue(undefined),}));vi.mock('@/features/right-sidebar/lib/openBackgroundTasksTab', () => ({openBackgroundTasksTab: openBackgroundTasksTabMock,}));-vi.mock('@/features/right-sidebar/lib/openSubagentsTab', () => ({- openSubagentsTab: openSubagentsTabMock,-}));const { getWorkflowProgressForMock } = vi.hoisted(() => ({getWorkflowProgressForMock: vi.fn().mockResolvedValue(null),@@ -519,9 +515,8 @@ describe('AgentTaskCard', () => {expect(progressLine(container)?.textContent).toBe('2/2 Agent');});- it('renders no workflow progress line and opens ordinary Subagents in their durable panel', () => {+ it('renders no progress line when workflowProgress is absent, and keeps non-workflow cards off the panel entry', () => {openBackgroundTasksTabMock.mockClear();- openSubagentsTabMock.mockClear();const workflow = render(React.createElement(AgentTaskCard, {sessionId: 'session-1',@@ -536,59 +531,23 @@ describe('AgentTaskCard', () => {expect(progressLine(workflow.container)).toBeNull();const normal = render(- withPanelHost(- 'session-1',- React.createElement(AgentTaskCard, {- sessionId: 'session-1',- update: {- provider: 'claude-code',- taskId: 'task-1',- status: 'running',- title: 'Inspect files',- },- }),- ),+ React.createElement(AgentTaskCard, {+ sessionId: 'session-1',+ update: {+ provider: 'claude-code',+ taskId: 'task-1',+ status: 'running',+ title: 'Inspect files',+ },+ }),);- const subagentButton = headerButton(normal.container);- expect(subagentButton).not.toBeNull();+ // 普通卡头部仍是展开 toggle,不触发面板。+ const toggleBtn = normal.container.querySelector<HTMLButtonElement>('button[aria-expanded]');+ expect(toggleBtn).not.toBeNull();act(() => {- subagentButton!.click();+ toggleBtn!.click();});expect(openBackgroundTasksTabMock).not.toHaveBeenCalled();- expect(openSubagentsTabMock).toHaveBeenCalledWith('session-1', {- focusRunId: 'task-1',- focusProvider: 'claude-code',- });expect(progressLine(normal.container)).toBeNull();});-- it('keeps Codex control cards expandable instead of opening a nonexistent Subagent run', () => {- openSubagentsTabMock.mockClear();- const { container } = render(- withPanelHost(- 'session-1',- React.createElement(AgentTaskCard, {- sessionId: 'session-1',- toolCall: {- clientId: 'wait-1',- role: 'tool_use',- content: '',- toolName: 'collab:wait',- toolUseId: 'wait-1',- },- update: {- provider: 'codex',- taskId: 'wait-1',- status: 'completed',- title: 'wait',- },- }),- ),- );-- const toggleButton = container.querySelector<HTMLButtonElement>('button[aria-expanded]');- expect(toggleButton).not.toBeNull();- act(() => toggleButton!.click());- expect(openSubagentsTabMock).not.toHaveBeenCalled();- });});diff --git a/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsx b/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsxindex 1bd22c6d3d..0fcdb5b738 100644--- a/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsx+++ b/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsx@@ -20,7 +20,6 @@ import { Spinner } from '@/components/ui/spinner';import type { AgentTaskUpdate, ChatMessage } from '@/hooks/useCCAgentChat';import { getWorkflowProgressFor, isRemoteSessionSticky } from '@/lib/makerTransport';import { openBackgroundTasksTab } from '@/features/right-sidebar/lib/openBackgroundTasksTab';-import { openSubagentsTab } from '@/features/right-sidebar/lib/openSubagentsTab';import { extractWorkflowTaskId } from '@/features/right-sidebar/plugins/background-tasks/listSessionTasks';import { WorkflowAgentStrip } from '@/features/right-sidebar/plugins/background-tasks/WorkflowAgentStrip';import {@@ -32,7 +31,6 @@ import { cn } from '@/lib/utils';import { formatModelShortLabel } from '@/lib/modelShortLabel';import { CODEX_SUBAGENT_EFFORTS } from '../../../shared/subagentModelSettings';import {- isSubagentSpawnToolName,PI_SUBAGENT_TOOL_NAME,subagentSpawnReceiptName,subagentSpawnResultIndicatesRunning,@@ -222,10 +220,6 @@ export function AgentTaskCard({ toolCall, update, result, subagentModel, session// 是「后台命令」—— 终端图标 + shell provider 标签,避免用户把跑测试的 bash// 误读成一个子 Agent。const isBash = update?.taskType === 'local_bash';- const isSubagent =- !isWorkflow &&- !isBash &&- (!toolCall?.toolName || isSubagentSpawnToolName(toolCall.toolName));const AvatarIcon = isWorkflow ? Workflow : isBash ? SquareTerminal : Bot;const title = compactText((isWorkflow ? update?.workflowName : undefined) ??@@ -293,39 +287,19 @@ export function AgentTaskCard({ toolCall, update, result, subagentModel, session.finally(() => setStopping(false));}, [sessionId, update?.taskId]);- // workflow / Subagent 卡整卡点击 → 打开对应 Cindy 右栏工作区并定位本任务。- // Subagent 使用 Cindy 逻辑 id、父 toolUseId 等任一已知别名;工作区会把别名- // 解析成持久 run id,因此三种 harness 不需要共享原生 thread/session 形态。- // 定位信息不全时退回传统展开交互,让 description/summary 就地可读,不做- // 「点了没反应」的假入口。+ // workflow 卡整卡点击 → 打开右栏后台任务面板并定位本任务(workflowTaskId 在+ // 组件顶部与状态修正共用同一次推导)。三者缺一就退回传统展开交互,让+ // description/summary 就地可读,不做「点了没反应」的假入口。//// panelReachable:内嵌宿主(协同 worker 面板 / workdir-browse 窄 rail / Orca// split)里右栏显示的是别的会话(或压根没在场),往本会话 bucket 写 tab 用户看// 不到 —— 那里必须退回展开区,否则卡片既点不动、又因面板入口化丢掉了展开区。const panelReachable = useSidebarPanelReachable(sessionId);- const subagentFocusId =- update?.taskId ?? update?.parentToolUseId ?? toolCall?.toolUseId ?? toolCall?.clientId;- const canOpenWorkflowPanel =- isWorkflow && Boolean(sessionId) && Boolean(workflowTaskId) && panelReachable;- const canOpenSubagentPanel =- isSubagent && Boolean(sessionId) && Boolean(subagentFocusId) && panelReachable;- const canOpenInPanel = canOpenWorkflowPanel || canOpenSubagentPanel;- const openWorkflowPanel = useCallback(() => {+ const canOpenInPanel = Boolean(sessionId) && Boolean(workflowTaskId) && panelReachable;+ const openInPanel = useCallback(() => {if (!sessionId || !workflowTaskId) return;void openBackgroundTasksTab(sessionId, { focusTaskId: workflowTaskId });}, [sessionId, workflowTaskId]);- const openSubagentPanel = useCallback(() => {- if (!sessionId || !subagentFocusId) return;- void openSubagentsTab(sessionId, {- focusRunId: subagentFocusId,- focusProvider: provider,- });- }, [provider, sessionId, subagentFocusId]);- const handleHeaderClick = canOpenWorkflowPanel- ? openWorkflowPanel- : canOpenSubagentPanel- ? openSubagentPanel- : toggle;// workflow 摘要行:当前运行中 agent 的 phaseTitle + 已收口/总数。收口判定走// workflowAgentVisualState 归一(与方块条 / 面板同一词表源,done 与 failed 都算收口)。@@ -384,14 +358,14 @@ export function AgentTaskCard({ toolCall, update, result, subagentModel, session{...(toolCall?.clientId ? { 'data-message-client-id': toolCall.clientId } : {})}><div className="w-full rounded-[12px] border border-[var(--border-default)] bg-[var(--surface-elevated)] px-3 py-2">- {/* 头部按钮:可达的 workflow/Subagent 卡 = 右栏详情入口;其余 = 展开 toggle。+ {/* 头部按钮:普通卡 = 展开 toggle;workflow 卡 = 打开后台任务面板入口。button 不能嵌套,停止按钮以兄弟节点挂在右侧(仅 running 时出现)。 */}<div className="flex w-full items-start gap-2"><buttontype="button"- onClick={handleHeaderClick}+ onClick={isWorkflow && canOpenInPanel ? openInPanel : toggle}className="flex min-w-0 flex-1 items-start gap-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"- {...(canOpenInPanel+ {...(isWorkflow && canOpenInPanel? { 'aria-label': t('chat.agentTask.openInPanel') }: {'aria-expanded': expanded,@@ -458,7 +432,7 @@ export function AgentTaskCard({ toolCall, update, result, subagentModel, session</span>)}</span>- {canOpenInPanel ? (+ {isWorkflow && canOpenInPanel ? (<PanelRightsize={14}className="mt-1 shrink-0 text-[var(--text-tertiary)]"@@ -496,9 +470,9 @@ export function AgentTaskCard({ toolCall, update, result, subagentModel, session)}</div>- {/* 能进入右栏的 workflow/Subagent 卡不再重复渲染就地展开区;- 不可达的嵌入宿主/历史降级路径仍保留 description/summary。 */}- {!canOpenInPanel && (+ {/* live workflow 卡不渲染展开区(详情在后台任务面板);历史 workflow 卡+ (无 live taskId,面板无数据)保留展开区兜底展示 description/summary。 */}+ {!(isWorkflow && canOpenInPanel) && (<Collapse open={expanded}><div className="mt-2 border-l-2 border-[var(--agent-actions-rail)] pl-3 text-13 leading-5 text-[var(--text-secondary)]">{description && <p className="mb-1">{description}</p>}diff --git a/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardModelChip.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardModelChip.test.tsxindex 1f05766a51..44226bf505 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardModelChip.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardModelChip.test.tsx@@ -21,10 +21,6 @@ vi.mock('@/features/right-sidebar/lib/openBackgroundTasksTab', () => ({openBackgroundTasksTab: vi.fn(),}));-vi.mock('@/features/right-sidebar/lib/openSubagentsTab', () => ({- openSubagentsTab: vi.fn(),-}));-vi.mock('@/features/right-sidebar/plugins/background-tasks/listSessionTasks', () => ({extractWorkflowTaskId: () => undefined,}));diff --git a/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardSubagentLive.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardSubagentLive.test.tsxindex c052802523..a8b1d5ba2d 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardSubagentLive.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/AgentTaskCardSubagentLive.test.tsx@@ -30,10 +30,6 @@ vi.mock('@/features/right-sidebar/lib/openBackgroundTasksTab', () => ({openBackgroundTasksTab: vi.fn(),}));-vi.mock('@/features/right-sidebar/lib/openSubagentsTab', () => ({- openSubagentsTab: vi.fn(),-}));-vi.mock('@/features/right-sidebar/plugins/background-tasks/listSessionTasks', () => ({extractWorkflowTaskId: () => undefined,}));@@ -105,7 +101,7 @@ describe('AgentTaskCard codex subagent live state', () => {});it('keeps the localized receipt for history replay (no live update)', () => {- // 聊天卡的历史回放不重建 live update;持久详情在独立 Subagent 面板。+ // 历史回放拿不到 live update(agent_task_update 不落库),回执是唯一可读摘要。const { container } = render(<AgentTaskCard toolCall={spawnToolCall()} result="/root/scout" />);expect(container.textContent ?? '').toContain('chat.agentTask.subagentStarted');});diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex eacb115350..50a430ce73 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -282,6 +282,19 @@ import {} from '../../../shared/conversationSearchJump';const log = createLogger('CCAgentSessionView');+/**+ * 子代理页签只登记、不抢占。+ *+ * 子代理在对话流里已经有自己的卡片,右栏再自动弹出会把同一件事讲两遍,还会抢走+ * 用户当时正在看的东西。入口保持可发现即可,展开留给用户点卡片或点右栏开关。+ * 两条登记路径(历史挂载 / 首个实时子代理)共用这一份参数,避免其中一条被单独改回+ * 自动展开。+ */+const SUBAGENT_TAB_REGISTER_ONLY = {+ focusTab: false,+ revealSidebar: false,+ userInitiated: false,+} as const;// perf-baseline(与 MessageStream / sidebar 的 perf/session-switch 探针同通道):// stream:profile 记录 MessageStream 子树每次 ≥50ms 的 React commit(phase +// actualDuration),与 perf/interaction 的 longtask 时长对齐即可判定长任务@@ -549,9 +562,9 @@ export function CCAgentSessionView({});}, [navigate, sessionId, viewVisible]);- // A task that has Subagents owns one durable Subagent tab. On history mount- // we silently ensure the tab exists; the first live child also reveals the- // sidebar, without stealing OS focus or replacing an already-active tab.+ // A task that has Subagents owns one durable Subagent tab. Both on history+ // mount and on the first live child we only ensure the tab exists — never+ // stealing OS focus, replacing an already-active tab, or opening the sidebar.useEffect(() => {if (!ownsWindowRoute || !viewVisible || !sessionId) return;let disposed = false;@@ -567,11 +580,7 @@ export function CCAgentSessionView({) {return;}- return openSubagentsTab(sessionId, {- focusTab: false,- revealSidebar: false,- userInitiated: false,- });+ return openSubagentsTab(sessionId, SUBAGENT_TAB_REGISTER_ONLY);}).catch(() => undefined);const unsubscribe = window.electronAPI.localDb.subagentRuns.onChanged(@@ -584,11 +593,7 @@ export function CCAgentSessionView({) {return;}- void openSubagentsTab(sessionId, {- focusTab: false,- revealSidebar: payload.created && payload.firstForSession,- userInitiated: false,- }).catch(() => undefined);+ void openSubagentsTab(sessionId, SUBAGENT_TAB_REGISTER_ONLY).catch(() => undefined);},);return () => {