Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop,maker-shared): review 第四轮——信封解码与 mobile 子代理归属
Kafeifei917e2e7387c2
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.tsindex 943eee36d3..4e39d6284c 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts@@ -1376,7 +1376,7 @@ describe('session-agent-switch handoff injection', () => {const transaction = createMakerSendTransaction(deps);await transaction.sendToAgentAccepted('session-1', { type: 'user', content: '新消息' }, undefined, {- persistUserMessage: { clientId: 'client-1', content: '新消息' },+ persistUserMessage: { clientId: 'client-1', content: '{"text":"新消息","images":[],"files":[]}' },});// wire:前缀注入@@ -1386,7 +1386,7 @@ describe('session-agent-switch handoff injection', () => {);// 落库:用户原文,不带交接段(display 与 sent 分离)const persisted = vi.mocked(deps.createDbMessage).mock.calls[0]?.[1];- expect(persisted?.content).toBe('新消息');+ expect(persisted?.content).toBe('{"text":"新消息","images":[],"files":[]}');expect(consumePendingHandoff).toHaveBeenCalledWith('session-1');});@@ -1426,7 +1426,7 @@ describe('session-agent-switch handoff injection', () => {const transaction = createMakerSendTransaction(deps);await transaction.sendToAgentAccepted('session-1', { type: 'user', content: '新消息' }, undefined, {- persistUserMessage: { clientId: 'client-1', content: '新消息' },+ persistUserMessage: { clientId: 'client-1', content: '{"text":"新消息","images":[],"files":[]}' },});expect(session.send).toHaveBeenCalledWith(@@ -1434,7 +1434,7 @@ describe('session-agent-switch handoff injection', () => {expect.anything(),);const persisted = vi.mocked(deps.createDbMessage).mock.calls[0]?.[1];- expect(persisted?.content).toBe('新消息');+ expect(persisted?.content).toBe('{"text":"新消息","images":[],"files":[]}');});it('计划对账在交接段外层(对账在前、交接在后)', async () => {@@ -1446,7 +1446,7 @@ describe('session-agent-switch handoff injection', () => {const transaction = createMakerSendTransaction(deps);await transaction.sendToAgentAccepted('session-1', { type: 'user', content: '新消息' }, undefined, {- persistUserMessage: { clientId: 'client-1', content: '新消息' },+ persistUserMessage: { clientId: 'client-1', content: '{"text":"新消息","images":[],"files":[]}' },});expect(session.send).toHaveBeenCalledWith({ type: 'user', content: 'RECONCILE-NOTE\n\nHANDOFF-TEXT\n\n新消息' },@@ -1477,18 +1477,18 @@ describe('session-agent-switch handoff injection', () => {expect.anything(),);- // /compact 等斜杠控制消息(白名单判据:落库内容以 '/' 开头)+ // /compact 等斜杠控制消息(落库是 stringifyUserContent 信封,判据须解开信封)await transaction.sendToAgentAccepted('session-1', { type: 'user', content: '/compact' }, undefined, {- persistUserMessage: { clientId: 'c3', content: '/compact' },+ persistUserMessage: { clientId: 'c3', content: '{"text":"/compact","images":[],"files":[]}' },});expect(session.send).toHaveBeenLastCalledWith({ type: 'user', content: '/compact' },expect.anything(),);- // coordinator 的合成续跑指令([UI_ACTION_TRIGGER] 前缀)+ // coordinator 的合成续跑指令([UI_ACTION_TRIGGER] 前缀,信封形态)await transaction.sendToAgentAccepted('session-1', { type: 'user', content: '[UI_ACTION_TRIGGER]Continue' }, undefined, {- persistUserMessage: { clientId: 'c4', content: '[UI_ACTION_TRIGGER]Continue' },+ persistUserMessage: { clientId: 'c4', content: '{"text":"[UI_ACTION_TRIGGER]Continue"}' },});expect(session.send).toHaveBeenLastCalledWith({ type: 'user', content: '[UI_ACTION_TRIGGER]Continue' },diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.tsindex 8f75fce334..78842fe6ec 100644--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts@@ -18,6 +18,7 @@ import {import { isCredentialModeSwitchBusyError } from '../maker-host/codex-credential-switch.js';import { throwIpcError } from '../utils/ipcValidate.js';import {+ extractPlainText,prependHandoffToUserMessage,prependNoteToWireUserMessage,type HandoffWireMessage,@@ -756,18 +757,20 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Make// 时注入——内部控制轮次都不落可显示 user 行。// 失败静默跳过:对账是锦上添花,不能挡发送。const soForReconcile = (outgoingSendOpts ?? {}) as MakerSendOptions;- const reconcilePersistContent =- typeof soForReconcile.persistUserMessage?.content === 'string'- ? soForReconcile.persistUserMessage.content- : null;+ // 落库内容是 stringifyUserContent 信封({"text":...}),裸 startsWith 只会+ // 看到 '{'——必须先抽出纯文本再分类,否则 /compact、[UI_ACTION_TRIGGER]+ // 一类控制消息全部漏网(review P2)。+ const reconcilePersistText =+ soForReconcile.persistUserMessage?.content !== undefined+ ? extractPlainText(soForReconcile.persistUserMessage.content).trim()+ : '';const isOrdinaryUserTurn =soForReconcile.origin === undefined &&soForReconcile.persistUserMessage?.autoResume !== true &&soForReconcile.persistUserMessage?.origin === undefined &&- reconcilePersistContent !== null &&- reconcilePersistContent.length > 0 &&- !reconcilePersistContent.startsWith('/') &&- !reconcilePersistContent.startsWith('[UI_ACTION_TRIGGER]');+ reconcilePersistText.length > 0 &&+ !reconcilePersistText.startsWith('/') &&+ !reconcilePersistText.startsWith('[UI_ACTION_TRIGGER]');const planReconcileNote = isOrdinaryUserTurn? ((await deps.peekPlanReconcileNote?.(sessionId).catch(() => null)) ?? null): null;diff --git a/packages/maker-shared/src/messageRender.ts b/packages/maker-shared/src/messageRender.tsindex 3c8eaea3fb..c9531efea4 100644--- a/packages/maker-shared/src/messageRender.ts+++ b/packages/maker-shared/src/messageRender.ts@@ -466,6 +466,16 @@ export function dedupeToolMediaByUrl<TMedia extends MessageRenderToolMediaLike>(return out;}+/**+ * 子代理归属判定:desktop 投影出顶层 parentToolUseId;mobile / main 原始行只有+ * agentMeta.parentUuid。二者任一存在即视为子代理内部消息。+ */+function hasSubagentParent(message: MessageRenderSourceMessageLike): boolean {+ if (message.parentToolUseId) return true;+ const parentUuid = message.agentMeta?.parentUuid;+ return typeof parentUuid === 'string' && parentUuid.length > 0;+}+export function findMessageTodoInsertions<TMessage extends MessageRenderSourceMessageLike>(messages: readonly TMessage[],options: MessageRenderTodoGroupingOptions = {},@@ -505,7 +515,10 @@ export function findMessageTodoInsertions<TMessage extends MessageRenderSourceMeif (!source) continue;// 子代理内部的计划调用不属于顶层面板:它们的 owner 是那个 Agent/Task 工具行,// 混进来会顶掉主线程计划(顶层"最新计划"按位置竞争,历史病 §3.1.5)。- if (message.parentToolUseId) continue;+ // 两套字段都认:desktop 投影出顶层 parentToolUseId;mobile 保留原始+ // agentMeta.parentUuid(normalizeRemoteMessages 不投影,父行滑出分页窗口+ // 时孤儿子消息回退顶层流,不认 meta 就会把子代理清单当顶层计划)。+ if (hasSubagentParent(message)) continue;const resultText = resultByToolUseId.get(toolUseIdOf(message) ?? '');const previous = lastSessionBySource.get(source);@@ -609,7 +622,7 @@ export function getLatestMessageTodoState<TMessage extends MessageRenderSourceMeif (!isAgentPlanToolName(toolNameOf(message))) continue;// 与 findMessageTodoInsertions 同一条边界:子代理内部的计划调用不参与// 顶层"最新计划事件"的判定,否则子调用会让顶层 insertion 判为过期。- if (message.parentToolUseId) continue;+ if (hasSubagentParent(message)) continue;latestPlanIndex = index;latestPlanMessage = message;}