Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix after #627: workflow 卡在内嵌宿主里不再是死键
Lizi175d5e7d34c7
diff --git a/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.ts b/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.tsindex 3ffb384cfd..1fe5ec65bb 100644--- a/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.ts+++ b/apps/desktop/src/renderer/__tests__/AgentTaskCard.test.ts@@ -47,6 +47,19 @@ vi.mock('@/lib/makerTransport', () => ({}));import { AgentTaskCard } from '@/components/chat/AgentTaskCard';+import { SessionNavigationModeProvider } from '@/features/cc-agent/embeddedSessionNavigation';++/**+ * 面板入口的 affordance 判据是「本会话的右栏 bucket 此刻可见」,由路由主实例经+ * SessionNavigationModeProvider 声明(见 useSidebarPanelReachable)。默认 fail+ * closed:没声明 = 打不开 = 不给假入口,所以断言面板入口的用例要显式声明宿主。+ */+const withPanelHost = (hostSessionId: string, element: React.ReactElement) =>+ React.createElement(SessionNavigationModeProvider, {+ mode: 'route-owner' as const,+ sidebarPanelHostSessionId: hostSessionId,+ children: element,+ });describe('AgentTaskCard', () => {it('renders the full expanded task result instead of truncating it', () => {@@ -215,16 +228,19 @@ describe('AgentTaskCard', () => {it('opens the background tasks panel focused on the task when a workflow card is clicked', () => {openBackgroundTasksTabMock.mockClear();const { container } = render(- React.createElement(AgentTaskCard, {- sessionId: 'session-1',- update: {- provider: 'claude-code',- taskId: 'wf-1',- status: 'running',- taskType: 'local_workflow',- workflowName: 'Release pipeline',- },- }),+ withPanelHost(+ 'session-1',+ React.createElement(AgentTaskCard, {+ sessionId: 'session-1',+ update: {+ provider: 'claude-code',+ taskId: 'wf-1',+ status: 'running',+ taskType: 'local_workflow',+ workflowName: 'Release pipeline',+ },+ }),+ ),);const btn = headerButton(container);expect(btn).not.toBeNull();@@ -298,18 +314,21 @@ describe('AgentTaskCard', () => {// 面板入口(与面板 listSessionTasks 的提取同源,focusTaskId 才配得上)。openBackgroundTasksTabMock.mockClear();const { container } = render(- React.createElement(AgentTaskCard, {- sessionId: 'session-1',- toolCall: {- clientId: 'wf-call-1',- role: 'tool_use',- content: '',- toolUseId: 'tu-wf-1',- toolName: 'Workflow',- toolInput: { script: 'export const meta = {}' },- },- result: 'Workflow launched in background. Task ID: wf_restored42',- }),+ withPanelHost(+ 'session-1',+ React.createElement(AgentTaskCard, {+ sessionId: 'session-1',+ toolCall: {+ clientId: 'wf-call-1',+ role: 'tool_use',+ content: '',+ toolUseId: 'tu-wf-1',+ toolName: 'Workflow',+ toolInput: { script: 'export const meta = {}' },+ },+ result: 'Workflow launched in background. Task ID: wf_restored42',+ }),+ ),);const btn = headerButton(container);expect(btn).not.toBeNull();@@ -323,18 +342,21 @@ describe('AgentTaskCard', () => {it('renders no inline expand region for workflow cards', () => {const { container } = render(- React.createElement(AgentTaskCard, {- sessionId: 'session-1',- update: {- provider: 'claude-code',- taskId: 'wf-1',- status: 'completed',- taskType: 'local_workflow',- workflowName: 'Release pipeline',- description: 'WORKFLOW_DESCRIPTION_HIDDEN',- summary: 'WORKFLOW_SUMMARY_HIDDEN',- },- }),+ withPanelHost(+ 'session-1',+ React.createElement(AgentTaskCard, {+ sessionId: 'session-1',+ update: {+ provider: 'claude-code',+ taskId: 'wf-1',+ status: 'completed',+ taskType: 'local_workflow',+ workflowName: 'Release pipeline',+ description: 'WORKFLOW_DESCRIPTION_HIDDEN',+ summary: 'WORKFLOW_SUMMARY_HIDDEN',+ },+ }),+ ),);// useExpandedBlockMemory mock 恒为 expanded=true,仍不得渲染展开区内容。expect(container.textContent).not.toContain('WORKFLOW_DESCRIPTION_HIDDEN');@@ -342,6 +364,37 @@ describe('AgentTaskCard', () => {expect(container.querySelector('[aria-expanded]')).toBeNull();});+ it('falls back to the expand toggle in embedded hosts where the panel bucket is invisible', () => {+ // 协同 worker 面板 / workdir-browse 窄 rail:右栏显示的是别的会话(这里 lead),+ // 往本会话 bucket 写 tab 用户看不到 —— 必须退回展开区,不给「点了没反应」的+ // 假入口,也不能因为面板入口化就在这些宿主里彻底没有详情可读。+ openBackgroundTasksTabMock.mockClear();+ const { container } = render(+ withPanelHost(+ 'lead-session',+ React.createElement(AgentTaskCard, {+ sessionId: 'worker-session',+ update: {+ provider: 'claude-code',+ taskId: 'wf-1',+ status: 'running',+ taskType: 'local_workflow',+ workflowName: 'Release pipeline',+ summary: 'WORKFLOW_SUMMARY_IN_EMBEDDED_HOST',+ },+ }),+ ),+ );+ expect(headerButton(container)).toBeNull();+ const toggleBtn = container.querySelector<HTMLButtonElement>('button[aria-expanded]');+ expect(toggleBtn).not.toBeNull();+ act(() => {+ toggleBtn!.click();+ });+ expect(openBackgroundTasksTabMock).not.toHaveBeenCalled();+ expect(container.textContent).toContain('WORKFLOW_SUMMARY_IN_EMBEDDED_HOST');+ });+const progressLine = (container: HTMLElement) =>container.querySelector('[data-workflow-progress-line="true"]');diff --git a/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsx b/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsxindex ac612789e9..5b1e0cd3fa 100644--- a/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsx+++ b/apps/desktop/src/renderer/components/chat/AgentTaskCard.tsx@@ -25,6 +25,7 @@ import {fileStatusToTaskStatus,workflowAgentVisualState,} from '@/features/right-sidebar/plugins/background-tasks/workflowProgressModel';+import { useSidebarPanelReachable } from '@/features/cc-agent/embeddedSessionNavigation';import { cn } from '@/lib/utils';import { formatModelShortLabel } from '@/lib/modelShortLabel';@@ -225,9 +226,14 @@ export function AgentTaskCard({ toolCall, update, result, subagentModel, session}, [sessionId, update?.taskId]);// workflow 卡整卡点击 → 打开右栏后台任务面板并定位本任务(workflowTaskId 在- // 组件顶部与状态修正共用同一次推导)。两者都提不到才退回传统展开交互,让+ // 组件顶部与状态修正共用同一次推导)。三者缺一就退回传统展开交互,让// description/summary 就地可读,不做「点了没反应」的假入口。- const canOpenInPanel = Boolean(sessionId) && Boolean(workflowTaskId);+ //+ // panelReachable:内嵌宿主(协同 worker 面板 / workdir-browse 窄 rail / Orca+ // split)里右栏显示的是别的会话(或压根没在场),往本会话 bucket 写 tab 用户看+ // 不到 —— 那里必须退回展开区,否则卡片既点不动、又因面板入口化丢掉了展开区。+ const panelReachable = useSidebarPanelReachable(sessionId);+ const canOpenInPanel = Boolean(sessionId) && Boolean(workflowTaskId) && panelReachable;const openInPanel = useCallback(() => {if (!sessionId || !workflowTaskId) return;void openBackgroundTasksTab(sessionId, { focusTaskId: workflowTaskId });diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex c0c11a6106..50efc78a98 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -3499,6 +3499,10 @@ export function CCAgentSessionView({<SessionNavigationModeProvidermode={navigationMode}sidebarTargetSessionId={sidebarTargetSessionId}+ // 只有声明右栏在场的路由主实例(ownsRoute)才是面板宿主:右栏当前显示的+ // 就是它的 bucket。内嵌实例(worker 面板 / 文件浏览窄 rail / Orca split)+ // 传 undefined → 面板类入口自行降级,见 useSidebarPanelReachable。+ sidebarPanelHostSessionId={ownsRoute ? sessionId : undefined}><ChatDisplaySnapshotProvider value={chatDisplaySnapshot}><TopRightChipStackProvider>{content}</TopRightChipStackProvider>diff --git a/apps/desktop/src/renderer/features/cc-agent/embeddedSessionNavigation.tsx b/apps/desktop/src/renderer/features/cc-agent/embeddedSessionNavigation.tsxindex 6e7222d7d9..71394d6aed 100644--- a/apps/desktop/src/renderer/features/cc-agent/embeddedSessionNavigation.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/embeddedSessionNavigation.tsx@@ -5,21 +5,30 @@ export type SessionNavigationMode = 'route-owner' | 'sidebar-embedded';const SessionNavigationModeContext = createContext<SessionNavigationMode>('route-owner');const SidebarTargetSessionIdContext = createContext<string | null>(null);+const SidebarPanelHostSessionIdContext = createContext<string | null>(null);export function SessionNavigationModeProvider({mode,sidebarTargetSessionId,+ sidebarPanelHostSessionId,children,}: {mode: SessionNavigationMode;/** 内嵌内容触发 RSB 动作时使用的可见 bucket;不传则沿用内容 session。 */sidebarTargetSessionId?: string;+ /**+ * 右栏面板此刻真正显示的那个会话(= 声明了右栏在场的聊天实例的 session)。+ * 只有它的 bucket 打开后用户看得见;内嵌实例不传,表示「本视图里打不开面板」。+ */+ sidebarPanelHostSessionId?: string;children: ReactNode;}) {return (<SessionNavigationModeContext.Provider value={mode}><SidebarTargetSessionIdContext.Provider value={sidebarTargetSessionId ?? null}>- {children}+ <SidebarPanelHostSessionIdContext.Provider value={sidebarPanelHostSessionId ?? null}>+ {children}+ </SidebarPanelHostSessionIdContext.Provider></SidebarTargetSessionIdContext.Provider></SessionNavigationModeContext.Provider>);@@ -38,3 +47,19 @@ export function useSidebarTargetSessionId(contentSessionId?: string): string | uif (!contentSessionId) return undefined;return sidebarTargetSessionId ?? contentSessionId;}++/**+ * 「该会话自己的右栏面板此刻打开后用户看得见吗」——面板类入口(后台任务面板等)+ * 的 affordance 判据。+ *+ * 面板按 session 分桶,而右栏一次只显示一个桶:显示哪个桶由「声明了右栏在场的+ * 那个聊天实例」决定(CCAgentSessionView 的 ownsRoute)。内嵌实例(协同 worker+ * 面板、workdir-browse 窄 rail、Orca split 双栏)都不声明在场,往它们自己的桶里+ * 写 tab 只会写进一个用户到不了的桶,点击必然无响应 —— 不给假 affordance+ * (与 BackgroundTasksBody 里非 workflow 行的 isSidebarWindow 守卫同款口径)。+ */+export function useSidebarPanelReachable(contentSessionId?: string): boolean {+ const panelHostSessionId = useContext(SidebarPanelHostSessionIdContext);+ if (!contentSessionId) return false;+ return panelHostSessionId === contentSessionId;+}