Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 回归 review 修复——bash 卡误杀/平铺三路径/面板孤儿洞/start 态一致
Kafeifei75b0ad086b4c
diff --git a/apps/desktop/src/renderer/__tests__/workflowCardStreamPlacement.test.ts b/apps/desktop/src/renderer/__tests__/workflowCardStreamPlacement.test.tsindex 6823263cf3..d5e220b97a 100644--- a/apps/desktop/src/renderer/__tests__/workflowCardStreamPlacement.test.ts+++ b/apps/desktop/src/renderer/__tests__/workflowCardStreamPlacement.test.ts@@ -129,7 +129,9 @@ describe('孤儿 local_bash 不进聊天流', () => {expect(items.some((it) => it.type === 'agent_task')).toBe(true);});- it('有 toolCall 配对的父会话后台 Bash 照常出卡', () => {+ it('父会话自己的后台 Bash(parentToolUseId 命中消息里的 Bash 调用)必须出「后台命令」卡', () => {+ // #247 存量功能:该卡的唯一渲染来源是孤儿循环(Bash toolCall 走 tool_segment,+ // 不进 agent_task 配对),过滤收窄必须放行它 —— 严格断言 agent_task 卡存在。const bashCall: ChatMessage = {clientId: 'b1',role: 'tool_use',@@ -143,13 +145,33 @@ describe('孤儿 local_bash 不进聊天流', () => {['tu-b1', { ...mkBashUpdate('bash-b1', 'running'), parentToolUseId: 'tu-b1' }],]);const { items } = buildRenderItems(messages, taskUpdates);- // 后台 Bash 走 tool_segment 或 agent_task 皆算可见;这里断言它没有被整体吞掉。- const visible = items.some(- (it) =>- (it.type === 'agent_task' &&- (it.toolCall?.clientId === 'b1' || it.update?.taskId === 'bash-b1')) ||- (it.type === 'tool_segment' && it.toolCalls.some((c) => c.clientId === 'b1')),+ const card = items.find(+ (it) => it.type === 'agent_task' && it.update?.taskId === 'bash-b1',);- expect(visible).toBe(true);+ expect(card).toBeTruthy();+ });++ it('workflow 内部 agent 的后台 Bash(parentToolUseId 不在父会话消息里)不出聊天卡', () => {+ const messages: ChatMessage[] = [mkUser('u1'), mkAssistant('a1', '在跑了。')];+ const taskUpdates = new Map<string, AgentTaskUpdate>([+ ['bash-sub', { ...mkBashUpdate('bash-sub', 'running'), parentToolUseId: 'tu-inside-subagent' }],+ ]);+ const { items } = buildRenderItems(messages, taskUpdates);+ expect(items.some((it) => it.type === 'agent_task')).toBe(false);+ });++ it('无最终正文的 turn(legacy 分组路径)里,stopped workflow 卡同样平铺', () => {+ // 场景:workflow 被用户 Stop,turn 没有 sealed 正文 → groupAnsweredTurnItems+ // handled:false 回落 groupLegacyWorkRuns —— 三条分组路径必须同语义。+ const messages: ChatMessage[] = [+ mkUser('u1'),+ mkWorkflowCall('wf1'),+ mkResult('r1', 'tu-wf1'),+ ];+ const taskUpdates = new Map<string, AgentTaskUpdate>([+ ['tu-wf1', mkWorkflowUpdate('task-wf-1', 'stopped', 'tu-wf1')],+ ]);+ const items = groupWorkRuns(buildRenderItems(messages, taskUpdates).items, false);+ expect(isFoldedIntoWorkGroup(items, 'wf1')).toBe(false);});});diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsxindex 70db46004f..5219b52309 100644--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx@@ -1152,13 +1152,30 @@ export function buildRenderItems(flushSegment();if (taskUpdates) {+ // 父会话自己的 Bash 调用集合:local_bash 任务卡(#247 的「后台命令」卡,含+ // 停止按钮)的**唯一**渲染来源就是本孤儿循环(Bash toolCall 走 tool_segment,+ // 不进 agent_task 配对分支),必须按 parentToolUseId 命中保留;命不中的才是+ // workflow / 子 agent 内部启动的后台命令 —— 只进后台任务面板,不进聊天流刷屏+ // (对齐官方:聊天流只呈现父会话自己的调用)。+ const parentBashToolUseIds = new Set<string>();+ for (const m of messages) {+ if (+ m.role === 'tool_use' &&+ m.toolName === 'Bash' &&+ typeof m.toolUseId === 'string' &&+ m.toolUseId.length > 0+ ) {+ parentBashToolUseIds.add(m.toolUseId);+ }+ }const seenTaskIds = new Set<string>();for (const update of taskUpdates.values()) {- // 孤儿 local_bash(只有任务事件、消息里无对应 toolCall)= workflow/子 agent- // 内部启动的后台命令:进后台任务面板,不进聊天流刷屏(对齐官方——聊天流只- // 呈现父会话自己的调用)。父会话自己的后台 Bash 有 toolCall,走上方配对卡,- // 不受此过滤影响。- if (update.taskType === 'local_bash') continue;+ if (+ update.taskType === 'local_bash' &&+ !(update.parentToolUseId && parentBashToolUseIds.has(update.parentToolUseId))+ ) {+ continue;+ }const primaryKey = update.parentToolUseId ?? update.taskId;if (seenTaskIds.has(update.taskId) ||@@ -1233,6 +1250,8 @@ function isWorkflowTaskItem(it: RenderItem): boolean {function isWorkActivityItem(it: RenderItem): it is WorkChildItem {return (!isRunningAgentTask(it) &&+ // workflow 卡三条分组路径(answered/legacy/active)统一平铺,见 isWorkflowTaskItem。+ !isWorkflowTaskItem(it) &&(it.type === 'tool_segment' ||it.type === 'agent_task' ||(it.type === 'message' && it.message.role === 'thinking'))diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/WorkflowProgressTree.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/WorkflowProgressTree.tsxindex fc4513d1d7..e6b1c92d04 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/WorkflowProgressTree.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/WorkflowProgressTree.tsx@@ -43,13 +43,15 @@ function agentStateIcon(state: string) {return CircleStop;case 'queued':case 'pending':+ case 'start':return CircleDashed;default:- return LoaderCircle; // running / start / progress / 未知 → 转圈+ return LoaderCircle; // running / progress / 未知 → 转圈}}-/** 非终态且非等待态(running/start/progress/未知)才转圈。 */+/** 非终态且非等待态(running/progress/未知)才转圈。'start' 对齐官方 CLI 与+ * 方块条:已入队未跑,不转圈(避免同屏「树行转圈 vs 方块灰」自相矛盾)。 */function isSpinning(state: string): boolean {switch (state) {case 'done':@@ -60,6 +62,7 @@ function isSpinning(state: string): boolean {case 'killed':case 'queued':case 'pending':+ case 'start':return false;default:return true;diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/__tests__/listSessionTasks.test.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/__tests__/listSessionTasks.test.tsindex 0be1aac346..15c57e5fb5 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/__tests__/listSessionTasks.test.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/__tests__/listSessionTasks.test.ts@@ -205,15 +205,31 @@ describe('listSessionTasks 孤儿 gating', () => {expect(orphanItem!.orderIndex).toBeGreaterThan(running.find((it) => it.taskId !== 'orphan-1')!.orderIndex);});- it('isSessionStreaming=false:孤儿是陈旧残留,不列出', () => {+ it('isSessionStreaming=false:终态孤儿是陈旧残留,不列出', () => {+ const doneOrphan = makeUpdate({ taskId: 'orphan-done', status: 'completed' });const { running, completed } = listSessionTasks({messages: [],- taskUpdates: new Map([['orphan-1', orphan]]),+ taskUpdates: new Map([['orphan-done', doneOrphan]]),isSessionStreaming: false,});expect(running).toHaveLength(0);expect(completed).toHaveLength(0);});++ it('isSessionStreaming=false:running 孤儿仍列出(workflow 内部长命后台命令跨 turn 存活)', () => {+ const liveBash = makeUpdate({+ taskId: 'orphan-bash',+ taskType: 'local_bash',+ title: 'pnpm dev',+ });+ const { running } = listSessionTasks({+ messages: [],+ taskUpdates: new Map([['orphan-bash', liveBash]]),+ isSessionStreaming: false,+ });+ expect(running).toHaveLength(1);+ expect(running[0]).toMatchObject({ taskId: 'orphan-bash', kind: 'bash' });+ });});// ---------------------------------------------------------------------------diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/listSessionTasks.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/listSessionTasks.tsindex 809f4a1a85..25577d3068 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/listSessionTasks.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/background-tasks/listSessionTasks.ts@@ -264,12 +264,16 @@ export function listSessionTasks(input: {});}- // 孤儿 update:仅会话运行中列出(LIVE 占位;空闲态是陈旧残留,不复播)。- // map 按 taskId + parentToolUseId 多 key 存同一 update,按 taskId 去重。- if (isSessionStreaming && taskUpdates) {+ // 孤儿 update:运行中的始终列出(workflow / 子 agent 内部启动的长命后台命令+ // 可能跨 turn 存活,seed 快照持续证明其真实在跑 —— 空闲态从列表消失会与状态栏+ // 计数自相矛盾,且用户失去单停入口);终态孤儿仅会话运行中列出(LIVE 占位;+ // 空闲态是陈旧残留,不复播)。map 按 taskId + parentToolUseId 多 key 存同一+ // update,按 taskId 去重。+ if (taskUpdates) {const seenTaskIds = new Set<string>();let orphanOrder = messages.length;for (const update of taskUpdates.values()) {+ if (!isSessionStreaming && update.status !== 'running') continue;const primaryKey = update.parentToolUseId ?? update.taskId;if (seenTaskIds.has(update.taskId) ||