Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 主聊天只显示后台任务补充消息状态 (#4321)
Chris Zhang9c0fc2f44b0a
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.tsindex 6c5ddf5779..da70efd71c 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts@@ -3291,7 +3291,7 @@ describe('Bot Session task end-to-end runtime', () => {* dispatchBotSessionMessage → sendToSessionInternal)。判据顺序刻意与真机一致:* 任何一条在真机上会挡住会话启动的门,这里也必须挡住。*/- const dispatch = async (params: {+ const dispatch = vi.fn(async (params: {targetSessionId: string;message: string;persistedContent?: string;@@ -3372,7 +3372,7 @@ describe('Bot Session task end-to-end runtime', () => {targetSessionId: params.targetSessionId,wakeKind: queuedBehindRunningTurn ? 'queued' as const : 'resumed' as const,};- };+ });const abortSession = vi.fn(async () => undefined);const delegation = createBotDelegationService({@@ -3431,6 +3431,7 @@ describe('Bot Session task end-to-end runtime', () => {return {delegation,+ dispatch,abortSession,started,changed,@@ -3866,14 +3867,37 @@ describe('Bot Session task end-to-end runtime', () => {expect(started.ok).toBe(true);if (!started.ok) return;+ const instruction = '补充:最后必须带风险清单。\n读取 /workspace/project/AGENTS.md 并核对执行授权。';await expect(runtime.delegation.messageSessionTask('session-1', started.delegationId, {kind: 'message',- text: '补充:最后必须带风险清单。',+ text: instruction,idempotencyKey: 'follow-up-1',}),).resolves.toMatchObject({ ok: true, queued: true, resumed: false });+ const childClientId = `bot-delegation-interject:${started.delegationId}:follow-up-1`;+ expect(runtime.dispatch).toHaveBeenCalledWith(expect.objectContaining({+ targetSessionId: started.childSessionId,+ clientId: childClientId,+ message: `[来自 发起方伙伴 的补充]\n\n${instruction}`,+ persistedContent: `[来自 发起方伙伴 的补充]\n\n${instruction}`,+ }));+ const readMessage = (sessionId: string, clientId: string) => h.sqlite!.prepare(+ 'SELECT role, content, agent_meta AS agentMeta FROM messages WHERE session_id = ? AND client_id = ?',+ ).get(sessionId, clientId) as { role: string; content: string; agentMeta: string };+ expect(readMessage(started.childSessionId, childClientId).content).toContain(instruction);+ const trace = readMessage('session-1', `bot-delegation-interject-mirror:${started.delegationId}:follow-up-1`);+ expect(trace).toMatchObject({ role: 'assistant', content: '' });+ expect(JSON.parse(trace.agentMeta).botCollaboration.role).toBe('interjection');+ expect(readMessage('session-1', `bot-delegation-request:${started.delegationId}`).content).toBe('');+ // Status queries return context to the caller without appending it to the timeline.+ const timelineBeforeCheck = h.sqlite!.prepare("SELECT * FROM messages WHERE session_id = 'session-1'").all();+ await expect(runtime.delegation.getSessionTask('session-1', started.delegationId)).resolves.toMatchObject({+ ok: true, task: { status: 'running', objective: '先整理一版方案。' },+ });+ expect(h.sqlite!.prepare("SELECT * FROM messages WHERE session_id = 'session-1'").all()).toEqual(timelineBeforeCheck);+await runtime.runPendingTurns();await expect(runtime.delegation.getSessionTask('session-1', started.delegationId),diff --git a/apps/desktop/src/main/maker-ipc/botDelegationService.ts b/apps/desktop/src/main/maker-ipc/botDelegationService.tsindex 7cc27f0711..cc883d6887 100644--- a/apps/desktop/src/main/maker-ipc/botDelegationService.ts+++ b/apps/desktop/src/main/maker-ipc/botDelegationService.ts@@ -2080,13 +2080,13 @@ export function createBotDelegationService(deps: BotDelegationServiceDeps) {message: dispatched?.message ?? '消息未能送达后台任务',};}- // 发起方视角的留痕:补过什么,重开会话仍在。写不进去不回滚投递- // ——话已经送到了,回滚只会让两边记账不一致。+ // 父任务只留发送状态;完整指令已经投递并保存在子任务,不再复制到主聊天。+ // 写不进去不回滚投递——话已经送到了,回滚只会让两边记账不一致。await persistTimelineMessage({sessionId: callerSessionId,clientId: BOT_DELEGATION_CLIENT_ID.interjectionMirror(delegationId, token),role: 'assistant',- content: trimmed,+ content: '',createdAt: now(),agentMeta: {botCollaboration: await collaborationMeta(row, 'interjection'),diff --git a/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.ts b/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.tsindex f545dadcbe..8ac8b2498f 100644--- a/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.ts+++ b/apps/desktop/src/renderer/__tests__/botCollaborationMessages.test.ts@@ -125,21 +125,33 @@ describe('mapServerMessages — Bot collaboration', () => {});});- it('derives the nudge trace and keeps the sentence that was actually sent', () => {- const [mapped] = makerChatStore.__mapServerMessagesForTest([- row({- clientId: 'bot-delegation-interject-mirror:delegation-1:n1',- content: '先别铺开,我只要三条。',- agentMeta: { botCollaboration: { ...META, role: 'interjection' } },- }),- ]);+ it('projects a legacy nudge as status only without rewriting its persisted instruction', () => {+ const legacy = row({+ clientId: 'bot-delegation-interject-mirror:delegation-1:n1',+ content: '先别铺开,我只要三条。',+ agentMeta: { botCollaboration: { ...META, role: 'interjection' } },+ });+ const [mapped] = makerChatStore.__mapServerMessagesForTest([legacy]);+ expect(legacy.content).toBe('先别铺开,我只要三条。');expect(mapped.systemCardType).toBe('bot-session-task-message');expect(mapped.systemCardData).toMatchObject({role: 'interjection',- text: '先别铺开,我只要三条。',+ text: '',});});+ it.each(['user', 'assistant'] as const)('preserves ordinary %s content that resembles an internal receipt', (role) => {+ const content = '已向后台任务发送消息:读取 /workspace/project/AGENTS.md';+ const [plain, invalid] = makerChatStore.__mapServerMessagesForTest([+ row({ clientId: 'plain', role, content }),+ row({ clientId: 'invalid', role, content, agentMeta: { botCollaboration: { ...META, v: 2 } } as unknown as Message['agentMeta'] }),+ ]);+ expect(plain.content).toBe(content);+ expect(invalid.content).toBe(content);+ expect(plain.systemCardType).toBeUndefined();+ expect(invalid.systemCardType).toBeUndefined();+ });+it('hides the delegation completion instruction from the visible stream', () => {// 完成回传是给模型的内部指令,不是给人的消息:可见终态由协作卡承载。// 它复用 synthetic-trigger 隐藏行判定,和「继续任务」那类合成指令同一条链。diff --git a/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsx b/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsxindex 96232c241e..4d00ff9f4f 100644--- a/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsx+++ b/apps/desktop/src/renderer/features/bots/BotCollaborationCard.tsx@@ -77,9 +77,6 @@ export function BotSessionTaskMessageTrace({ data }: Pick<Props, 'data'>) {<Megaphone size={13} className="mt-[3px] shrink-0" aria-hidden="true" /><span className="min-w-0">{t('bots.collab.messageSent')}- {parsed.text ? (- <span className="text-[var(--text-secondary)]">{`:${parsed.text}`}</span>- ) : null}</span></div>);diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsxindex 3e1d0842db..2b008213b4 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotCollaborationCard.test.tsx@@ -304,7 +304,7 @@ describe('BotSessionTaskCard', () => {/>,);expect(screen.getByText(/bots\.collab\.messageSent/)).toBeTruthy();- expect(screen.getByText(/先别铺开,我只要三条。/)).toBeTruthy();+ expect(screen.queryByText(/先别铺开,我只要三条。/)).toBeNull();expect(screen.queryByText('bots.collab.stopTask')).toBeNull();});diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex ac06f7b2fd..dc311b87f4 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -17417,8 +17417,8 @@ function mapServerMessages(serverMsgs: Message[]): ChatMessage[] {: ('bot-session-task' as const),systemCardData: {...collaboration,- // 插话卡要显示催的是哪句话;锚点卡正文为空。- text: typeof m.content === 'string' ? m.content : '',+ // 旧记录可能含完整执行指令;实时与历史都只投影任务状态,不修改原记录。+ text: '',},};}diff --git a/apps/mobile/src/__tests__/CompanionMessageCard.test.tsx b/apps/mobile/src/__tests__/CompanionMessageCard.test.tsxindex 08f5bb0c32..9c630ca79f 100644--- a/apps/mobile/src/__tests__/CompanionMessageCard.test.tsx+++ b/apps/mobile/src/__tests__/CompanionMessageCard.test.tsx@@ -461,3 +461,14 @@ it('limits the PR menu and status queries to the same three references as the taawait act(async () => choices[2].click());expect(h.openURL).toHaveBeenCalledWith('https://github.com/a/b/pull/3');});++it('shows only delivery status even when a legacy task trace contains full instructions', async () => {+ const trace = {+ ...message,+ body: '读取 /workspace/project/AGENTS.md 并核对执行授权。',+ companion: { kind: 'task', meta: { ...message.companion!.meta, role: 'interjection' } },+ } as NormalizedRemoteMessage;+ await act(async () => root.render(createElement(CompanionMessageCard, { message: trace })));+ expect(node.textContent).toBe('devices.companions.messageSent');+ expect(h.invoke).not.toHaveBeenCalled();+});diff --git a/apps/mobile/src/__tests__/messageNormalize.test.ts b/apps/mobile/src/__tests__/messageNormalize.test.tsindex 0162194d47..40c93ecfa7 100644--- a/apps/mobile/src/__tests__/messageNormalize.test.ts+++ b/apps/mobile/src/__tests__/messageNormalize.test.ts@@ -1347,6 +1347,23 @@ describe('normalizeRemoteMessages — /goal 持久记录与 plan_review 状态',describe('companion timeline', () => {+ it.each([false, true])('keeps task instructions out of live/history display (source order: %s)', (preserveSourceOrder) => {+ const content = '已向后台任务发送消息:读取 /workspace/project/AGENTS.md 并核对执行授权。';+ const task = { v: 1, role: 'interjection', delegationId: 'job', fromBotId: 'bot', fromBotName: 'Writer', toBotId: null, toBotName: 'Cindy', parentSessionId: 's1', childSessionId: 'child', objective: 'Write report' };+ const legacy = message({ id: 'trace', role: 'assistant', content, agentMeta: { botCollaboration: task } });+ const rows = normalizeRemoteMessages([+ legacy,+ message({ id: 'anchor', role: 'assistant', content, agentMeta: { botCollaboration: { ...task, role: 'delegation-request' } } }),+ message({ id: 'user', role: 'user', content }),+ message({ id: 'assistant', role: 'assistant', content }),+ message({ id: 'invalid', role: 'assistant', content, agentMeta: { botCollaboration: { ...task, v: 2 } } }),+ ], { preserveSourceOrder });+ expect(rows.find(row => row.source.id === 'trace')).toMatchObject({ body: '', companion: { kind: 'task' } });+ expect(rows.find(row => row.source.id === 'anchor')).toMatchObject({ body: '', companion: { kind: 'task' } });+ for (const id of ['user', 'assistant', 'invalid']) expect(rows.find(row => row.source.id === id)?.body).toBe(content);+ expect(legacy.content).toBe(content);+ });+it('preserves empty task anchors and private thread links for the mobile renderer', () => {const task = { v: 1, role: 'delegation-request', delegationId: 'job', fromBotId: 'bot', fromBotName: 'Writer', toBotId: null, toBotName: 'Cindy', parentSessionId: 's1', childSessionId: 'child', objective: 'Write report' };const direct = { v: 1, threadId: 'private', viewerBotId: 'bot', peerBotId: 'peer', peerBotName: 'Dash', direction: 'sent', sequence: 1, preview: 'Discuss report' };diff --git a/apps/mobile/src/session/CompanionMessageCard.tsx b/apps/mobile/src/session/CompanionMessageCard.tsxindex f5b61fb60f..73121f3bf0 100644--- a/apps/mobile/src/session/CompanionMessageCard.tsx+++ b/apps/mobile/src/session/CompanionMessageCard.tsx@@ -52,7 +52,6 @@ export function CompanionMessageCard({ message }: { message: NormalizedRemoteMesreturn (<Text style={styles.note}>{t('devices.companions.messageSent')}- {message.body ? ` · ${message.body}` : ''}</Text>);const meta = card.meta;diff --git a/apps/mobile/src/session/messageNormalize.ts b/apps/mobile/src/session/messageNormalize.tsindex becb60fa1e..418cb7ee57 100644--- a/apps/mobile/src/session/messageNormalize.ts+++ b/apps/mobile/src/session/messageNormalize.ts@@ -232,12 +232,14 @@ export function normalizeRemoteMessages(const task = readBotCollaborationMeta(message.agentMeta?.botCollaboration);const direct = readBotDirectMessageMeta(message.agentMeta?.botDirectMessage);- if (task?.role === 'delegation-request' || task?.role === 'interjection' || direct) {+ const isTaskTrace = task?.role === 'delegation-request' || task?.role === 'interjection';+ if (isTaskTrace || direct) {result.push({key: messageNormalizeKey(message), source: message, kind: 'system', role: message.role,- label: 'companion', body: typeof message.content === 'string' ? message.content : '',+ // Task traces are status-only, including legacy rows containing execution instructions.+ label: 'companion', body: isTaskTrace ? '' : typeof message.content === 'string' ? message.content : '',align: 'agent', createdAt: message.createdAt,- companion: task && (task.role === 'delegation-request' || task.role === 'interjection')+ companion: isTaskTrace? { kind: 'task', meta: task } : { kind: 'direct', meta: direct! },});continue;diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex c987384df9..1e56710579 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -222,6 +222,9 @@ Session 任务遵守同一套机制与呈现契约:- **任务卡**:发起方消息流原位出现一张持久任务卡,实时反映排队 / 执行 / 等待 / 终态。卡片不得使用“加入对话”等通讯语言,也不得再叠加顶部运行条或另造一套协同面板。状态由任务行推送驱动,不靠消息文本。+- **补充消息留痕**:`message_session_task` 的完整指令继续投递并保存在后台任务,主聊天的发送留痕只显示简短状态。+ 桌面与手机的实时、历史展示都按结构化标记投影;旧记录不删改,正常用户内容、授权和提问继续保留。+ 此约束针对自动生成的发送留痕,不改变用户主动展开工具活动时查看原始调用参数的能力。- **完成信号**:子任务完成(或失败 / 超时 / 取消)时,发起方收到一条**用户不可见**的内部指令(synthetic-trigger 隐藏行),据此接手继续工作;用户看到的终态由任务卡承载,时间线里不得出现机读文本或内部 id。