Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 归属解析补剥 Host 芯片 + wake 终态重复帧不误标跨主 turn
Shinkuf833468e5fc5
diff --git a/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts b/apps/desktop/src/renderer/__tests__/composerListDocument.test.tsindex c6914b6520..f16ffdbf84 100644--- a/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts+++ b/apps/desktop/src/renderer/__tests__/composerListDocument.test.ts@@ -1,6 +1,7 @@import { describe, expect, it } from 'vitest';import {+ composerDocumentContainsHostCapabilityChip,insertComposerDocumentForRestore,normalizeComposerDocumentJSON,plainTextToComposerDocument,@@ -536,4 +537,37 @@ describe('stripHostCapabilityChips', () => {],});});++ it('composerDocumentContainsHostCapabilityChip detects chips but ignores other nodes', () => {+ expect(+ composerDocumentContainsHostCapabilityChip({+ type: 'doc',+ content: [+ {+ type: 'paragraph',+ content: [+ hostCapabilityChip(),+ { type: 'text', text: ' ' },+ { type: 'text', text: '打开模拟器' },+ ],+ },+ ],+ }),+ ).toBe(true);++ expect(+ composerDocumentContainsHostCapabilityChip({+ type: 'doc',+ content: [+ {+ type: 'paragraph',+ content: [+ { type: 'mentionChip', attrs: { kind: 'slash', label: '/plan', path: '/plan' } },+ { type: 'text', text: '继续' },+ ],+ },+ ],+ }),+ ).toBe(false);+ });});diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.tsindex 1951d62219..c5fc194e66 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTaskUpdates.test.ts@@ -614,6 +614,40 @@ describe('getRunningSnapshot 后台 subagent 折算(真 store)', () => {}});+ it('wake 任务终态帧在 wake turn 已启动后重放 → 不误标跨主 turn、会话不永久转圈', async () => {+ // Codex P1:wake 型任务 terminal update 被 replay / 延迟到达时,任务此前已经+ // completed,这一帧只是同一终态的重复投递。旧逻辑把它当 fresh wakesAfterTerminal,+ // 在 wake turn 已 running(isRunning:true)时误置 pendingTaskWakeDuringTurn;+ // wake turn 的 Done 只退休标记、却因 pendingTaskWake 仍被置位而无法清除桥接,+ // 会话永久卡 running/Stop。修复:终态重复帧(already-terminal)不再重标桥接。+ const sid = `wake-replay-${Math.random().toString(36).slice(2, 8)}`;+ try {+ // 空窗:无 turn 在跑,任务 running → completed → 桥接置位+ applyTask(sid, { taskId: 't1', status: 'running', taskType: 'local_agent' });+ applyTask(sid, { taskId: 't1', status: 'completed' });+ expect(makerChatStore.getSnapshot(sid).pendingTaskWake).toBe(true);++ // wake turn 启动(isRunning:true)→ isTurnStart 清除桥接+ makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, true));+ expect(makerChatStore.getSnapshot(sid).pendingTaskWake).toBe(false);+ expect(makerChatStore.getSnapshot(sid).pendingTaskWakeDuringTurn).toBe(false);++ // 同一终态帧重放(wake turn 已 running):不得重新置位桥接/跨主 turn 标记+ applyTask(sid, { taskId: 't1', status: 'completed' });+ const replayed = makerChatStore.getSnapshot(sid);+ expect(replayed.pendingTaskWake).toBe(false);+ expect(replayed.pendingTaskWakeDuringTurn).toBe(false);++ // wake turn 结束:桥接本就清除,会话正常停,不永久转圈+ makerChatStore.__applyStatusUpdateForTest(sid, statusUpdate(sid, false, 'Done'));+ const afterDone = makerChatStore.getSnapshot(sid);+ expect(afterDone.pendingTaskWake).toBe(false);+ expect(afterDone.pendingTaskWakeDuringTurn).toBe(false);+ } finally {+ makerChatStore.purgeSession(sid);+ }+ });+it('local_bash 后台任务不折算:主 turn 结束即 stopped(dev server 不永转)', async () => {const sid = `bash-${Math.random().toString(36).slice(2, 8)}`;try {diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 787fb2471e..3170b3c00a 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -268,6 +268,7 @@ import {import { createComposerFrameScheduler } from './composerFrameScheduler';import { serializeEditorContent, serializeEditorSlice } from './composerContentSerialization';import {+ composerDocumentContainsHostCapabilityChip,composerDocumentContainsList,normalizeComposerDocumentJSON,plainTextToComposerDocument,@@ -3526,6 +3527,27 @@ export function ChatInput({});}, [editor, storageKey]);+ // device-link 归属解析成「已确认远程」后补剥 Host capability 芯片。草稿恢复+ // 效果依赖 [editor, storageKey],归属从 undefined(未解析)→ 远程 string 时不会+ // 重跑,而 normalizeRestoredComposerDraft 在未解析阶段保留了芯片(不能把已存本机+ // 草稿的芯片当远程剥掉);这里监听归属转译,一旦确认远程就把当前编辑器内容里残留+ // 的 Host 芯片剥掉,避免发送路径被 TARGET_UNAVAILABLE 拦截、逼用户手动删芯片。+ const prevConfirmedRemoteRef = useRef<boolean>(false);+ useEffect(() => {+ const isConfirmedRemote = !!remoteHostId || typeof deviceLinkDeviceId === 'string';+ const becameRemote = isConfirmedRemote && !prevConfirmedRemoteRef.current;+ prevConfirmedRemoteRef.current = isConfirmedRemote;+ if (!becameRemote || !editor) return;+ const doc = editor.getJSON();+ if (!composerDocumentContainsHostCapabilityChip(doc)) return;+ isRestoringRef.current = true;+ try {+ editor.commands.setContent(stripHostCapabilityChips(doc));+ } finally {+ isRestoringRef.current = false;+ }+ }, [editor, remoteHostId, deviceLinkDeviceId]);+// Plugin page routed entry: wait until the editor has hydrated its existing// draft, then reuse the exact same insertion/focus path as the in-composer// `$` / `+` selectors. This preserves body text and replaces an existingdiff --git a/apps/desktop/src/renderer/lib/composerListDocument.ts b/apps/desktop/src/renderer/lib/composerListDocument.tsindex e93cd84606..1538e7fd14 100644--- a/apps/desktop/src/renderer/lib/composerListDocument.ts+++ b/apps/desktop/src/renderer/lib/composerListDocument.ts@@ -336,6 +336,28 @@ export function stripHostCapabilityChips(document: JSONContent): JSONContent {return { ...document, content: nextContent };}+/**+ * Whether a composer document contains at least one Host capability chip+ * (`mentionChip` with `attrs.kind === 'plugin-capability'`), recursively.+ *+ * Used to decide whether a confirmed-remote ownership resolution needs to+ * re-run {@link stripHostCapabilityChips} over the live editor content, without+ * rebuilding the whole document (and resetting the caret) when there is nothing+ * to strip.+ */+export function composerDocumentContainsHostCapabilityChip(document: JSONContent): boolean {+ if (!document || typeof document !== 'object' || !Array.isArray(document.content)) {+ return false;+ }+ return document.content.some((node) => {+ if (!node || typeof node !== 'object') return false;+ if (node.type === 'mentionChip' && node.attrs?.kind === 'plugin-capability') {+ return true;+ }+ return composerDocumentContainsHostCapabilityChip(node);+ });+}+export interface ComposerRestoreInsertion {document: JSONContent;insertedBlocks: JSONContent[];diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 7ba3d3b81c..e71c73df5b 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -4846,7 +4846,16 @@ export function handleStreamEvent(// hasBackgroundAgentWork 返回 true,阻止 ChatInput 用不完整上下文发起预测。// 后续 wake turn 启动(isRunning:true)时 handleStatusUpdate 通过// isTurnStart 分支清除 pendingTaskWake,桥接不会永久撑住 running 快照。+ // 终态重复帧(replay / 延迟到达)不得当成新的「终态转译」:任务此前已经+ // completed / failed 时,这一帧只是同一终态的重复投递。若在 wake turn 已启动+ // (isRunning:true)之后才重放,仍把 already-terminal 的任务当 fresh wakesAfterTerminal+ // 会误置 pendingTaskWakeDuringTurn,wake turn 的 Done 只退休了标记却留下+ // pendingTaskWake,会话永久卡 running/Stop。这里只在「非终态 → 终态」的真实转译+ // 时置桥接,重复的终态帧不重新标记。+ const wasAlreadyTerminal =+ existing?.status === 'completed' || existing?.status === 'failed';const wakesAfterTerminal =+ !wasAlreadyTerminal &&(merged.status === 'completed' || merged.status === 'failed') &&isWakeAgentTask(merged);const nextWake = state.pendingTaskWake || wakesAfterTerminal;