Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 优化推荐提示词发送与 Tab 交互 (#3310)
Dashb62bdaf6690b
diff --git a/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.ts b/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.tsindex f27fa03a02..99f8d637cc 100644--- a/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.ts+++ b/apps/desktop/src/renderer/__tests__/chatInputSteerShortcut.test.ts@@ -50,12 +50,12 @@ describe('ChatInput steer shortcut contract', () => {);expect(windowKeydownBlock).toContain("(enterIntent === 'queue' || enterIntent === 'steer')");expect(windowKeydownBlock).toContain("currentState !== 'listening'");- expect(windowKeydownBlock).toContain('void dispatchSendRef.current(enterIntent);');+ expect(windowKeydownBlock).toContain('void voiceInputStopAndSendRef.current(enterIntent);');const paletteGuard = windowComposerCaptureBlock.indexOf('panelBridgeRef.current?.captureKey(event)',);const modifiedSend = windowComposerCaptureBlock.indexOf(- 'void dispatchSendRef.current(enterIntent);',+ 'void voiceInputStopAndSendRef.current(enterIntent);',);expect(paletteGuard).toBeGreaterThan(-1);expect(paletteGuard).toBeLessThan(modifiedSend);@@ -69,7 +69,7 @@ describe('ChatInput steer shortcut contract', () => {expect(editorEnterBlock).toContain('platform: window.electronAPI?.platform');expect(editorEnterBlock).toContain("if (enterIntent === 'native') return false;");expect(editorEnterBlock).toContain("if (enterIntent === 'ignore')");- expect(editorEnterBlock).toContain('void dispatchSendRef.current(enterIntent);');+ expect(editorEnterBlock).toContain('void voiceInputStopAndSendRef.current(enterIntent);');// Tiptap's document is current before React's send-button effect updates// composerCanSubmitRef. The resolver must not use that lagging UI mirror.expect(windowComposerCaptureBlock).not.toContain('composerCanSubmitRef.current');diff --git a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.tsindex 0571dcf8ee..c8c4ad866d 100644--- a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts+++ b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts@@ -332,9 +332,7 @@ describe('device-link Desktop-only 确认 — 控制端只读投影', () => {const chatInput = src.indexOf('<ChatInput', branchStart);expect(branchStart).toBeGreaterThan(-1);expect(chatInput).toBeGreaterThan(branchStart);- expect(src.slice(branchStart, chatInput)).not.toContain(- 'pendingRemoteDesktopConfirmation',- );+ expect(src.slice(branchStart, chatInput)).not.toContain('pendingRemoteDesktopConfirmation');});it.each(['issue_confirm', 'rename_sessions_confirm', 'ghost_grant_confirm'] as const)(@@ -1014,8 +1012,10 @@ describe('远程交互接线不变式', () => {expect(syncEnd).toBeGreaterThan(syncStart);const syncBody = chatInputSrc.slice(syncStart, syncEnd);expect(syncBody).toContain('patchVendorPrefsPreservingModelChoice');- expect(syncBody).toContain('markModelChoice ? patchVendorPrefs : patchVendorPrefsPreservingModelChoice');- expect(syncBody).toContain("opts.markModelChoice === true");+ expect(syncBody).toMatch(+ /markModelChoice\s*\?\s*patchVendorPrefs\s*:\s*patchVendorPrefsPreservingModelChoice/,+ );+ expect(syncBody).toContain('opts.markModelChoice === true');expect(syncBody).toContain('markModelChoice');expect(syncBody).toContain('{ model: modelId, providerId: activeProviderId ?? null }');expect(syncBody).not.toContain(': { model: modelId }');@@ -1032,7 +1032,7 @@ describe('远程交互接线不变式', () => {'markModelChoice === false ? patchVendorPrefsPreservingModelChoice : patchVendorPrefs',);expect(appSrc).toContain('model: modelId');- expect(appSrc).not.toContain("markModelChoice === false ? {} : { model: modelId }");+ expect(appSrc).not.toContain('markModelChoice === false ? {} : { model: modelId }');const draftSrc = read('state/newMakerDraft.ts');expect(draftSrc).toContain('if (!opts.markModelChoice && modelChosen[vendor] === true)');@@ -1183,9 +1183,7 @@ describe('远程交互接线不变式', () => {);expect(activeEffort).toBeGreaterThan(-1);// 没有显式目标(既有的 effort / fast 编辑入口)时仍回落当前 dlSel / seed 的档。- expect(body).toMatch(- /dlSel\?\.effort \?\? deviceLinkInitial\?\.effort/,- );+ expect(body).toMatch(/dlSel\?\.effort \?\? deviceLinkInitial\?\.effort/);expect(payloadEffort).toBeGreaterThan(activeEffort);});@@ -1203,7 +1201,9 @@ describe('远程交互接线不变式', () => {expect(pushStart).toBeGreaterThan(-1);const pushBody = src.slice(pushStart, pushEnd);expect(pushBody).toContain('target?: {');- expect(pushBody).toContain("const model = target?.modelId ?? dlSel?.model ?? deviceLinkInitial?.model;");+ expect(pushBody).toContain(+ 'const model = target?.modelId ?? dlSel?.model ?? deviceLinkInitial?.model;',+ );expect(pushBody).toContain('agent: target?.agent ?? capabilityAgentKind');expect(pushBody).toMatch(/providerId: target\s*\r?\n?\s*\?\s*\(target\.providerId \?\? ''\)/);// 给了目标就**只**认目标的档 —— 不许再回落到上一个模型的 dlSel.effort。diff --git a/apps/desktop/src/renderer/__tests__/promptRecommendationBadge.test.ts b/apps/desktop/src/renderer/__tests__/promptRecommendationBadge.test.tsindex 2e989f3dbd..f51da16daa 100644--- a/apps/desktop/src/renderer/__tests__/promptRecommendationBadge.test.ts+++ b/apps/desktop/src/renderer/__tests__/promptRecommendationBadge.test.ts@@ -9,11 +9,22 @@ const chatInputSource = readFileSync();describe('prompt recommendation shortcut badge', () => {- it('keeps the prompt shrinkable while reserving space for a pill badge', () => {- expect(chatInputSource).toContain('className="min-w-0 flex-1 truncate"');+ it('keeps a keycap badge beside the prompt while allowing long text to truncate', () => {expect(chatInputSource).toContain(- "'ml-1.5 inline-flex shrink-0 items-center rounded-full border'",+ "'pointer-events-none absolute left-0 top-0 inline-flex max-w-full min-w-0 items-center py-[3px]'",);+ expect(chatInputSource).toContain('className="min-w-0 truncate"');+ expect(chatInputSource).toContain(+ "'pointer-events-auto ml-1 inline-flex h-4 min-w-[22px] shrink-0 cursor-pointer items-center justify-center rounded-lg border border-current'",+ );+ expect(chatInputSource).toContain(+ "'bg-transparent px-0.5 text-11 font-normal leading-none text-inherit'",+ );+ expect(chatInputSource).toContain(+ "'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]'",+ );+ expect(chatInputSource).toContain('onMouseDown={(event) => event.preventDefault()}');+ expect(chatInputSource).toContain('onClick={acceptPromptRecommendation}');});it('uses the complete locale catalog for the visible key label', () => {diff --git a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.tsindex 7757d9fcff..71c70a62cf 100644--- a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts+++ b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts@@ -159,26 +159,28 @@ describe('isAgentSwitchResponseFresh(远程意图读回的新鲜度守卫)',};it('在途期间无人改动 → 应用读回结果', async () => {- const { isAgentSwitchResponseFresh } = await import('@/components/new-chat/agentSwitchConfirmation');+ const { isAgentSwitchResponseFresh } =+ await import('@/components/new-chat/agentSwitchConfirmation');expect(isAgentSwitchResponseFresh(base)).toBe(true);});it('effect 已清理(切走会话)→ 丢弃', async () => {- const { isAgentSwitchResponseFresh } = await import('@/components/new-chat/agentSwitchConfirmation');+ const { isAgentSwitchResponseFresh } =+ await import('@/components/new-chat/agentSwitchConfirmation');expect(isAgentSwitchResponseFresh({ ...base, cancelled: true })).toBe(false);});it('本端 ABA:点选登记后又撤销 → 写序号已变,丢弃', async () => {- const { isAgentSwitchResponseFresh } = await import('@/components/new-chat/agentSwitchConfirmation');+ const { isAgentSwitchResponseFresh } =+ await import('@/components/new-chat/agentSwitchConfirmation');expect(isAgentSwitchResponseFresh({ ...base, writeSeqNow: 5 })).toBe(false);});it('外部 ABA:另一窗口 / 被控端把意图改成非空又清回 null → 修订号已变,丢弃', async () => {- const { isAgentSwitchResponseFresh } = await import('@/components/new-chat/agentSwitchConfirmation');+ const { isAgentSwitchResponseFresh } =+ await import('@/components/new-chat/agentSwitchConfirmation');// 外部回流不经本端点选,writeSeq 不动;值也回到发起时的 null —— 只有修订号能识别。- expect(- isAgentSwitchResponseFresh({ ...base, writeSeqNow: 3, intentRevNow: 9 }),- ).toBe(false);+ expect(isAgentSwitchResponseFresh({ ...base, writeSeqNow: 3, intentRevNow: 9 })).toBe(false);});});@@ -481,7 +483,7 @@ describe('agentSwitchCoordinator(串行链与写序号按 session,跨组件mod.__resetAgentSwitchCoordinatorForTests();return mod;};- const deferred = <T,>() => {+ const deferred = <T>() => {let resolve!: (v: T) => void;const promise = new Promise<T>((r) => {resolve = r;@@ -654,11 +656,8 @@ describe('agentSwitchCoordinator(串行链与写序号按 session,跨组件});it('发送检查与登记原子化:切换在途时拒绝,外层准备 token 与共享发送边界可嵌套', async () => {- const {- beginAgentSwitchOperation,- hasPendingAgentSendDispatch,- tryBeginAgentSendDispatch,- } = await load();+ const { beginAgentSwitchOperation, hasPendingAgentSendDispatch, tryBeginAgentSendDispatch } =+ await load();const finishSwitch = beginAgentSwitchOperation('s1');expect(tryBeginAgentSendDispatch('s1')).toBeNull();expect(hasPendingAgentSendDispatch('s1')).toBe(false);@@ -762,9 +761,12 @@ describe('makerChatStore 共享发送边界', () => {const coordinator = await import('@/lib/agentSwitchCoordinator');coordinator.__resetAgentSwitchCoordinatorForTests();let rejectRetry!: (reason: Error) => void;- const retryLastError = vi.fn(() => new Promise<never>((_resolve, reject) => {- rejectRetry = reject;- }));+ const retryLastError = vi.fn(+ () =>+ new Promise<never>((_resolve, reject) => {+ rejectRetry = reject;+ }),+ );vi.stubGlobal('window', {electronAPI: { maker: { input: { retryLastError } } },});@@ -785,9 +787,12 @@ describe('makerChatStore 共享发送边界', () => {const coordinator = await import('@/lib/agentSwitchCoordinator');coordinator.__resetAgentSwitchCoordinatorForTests();let rejectCompact!: (reason: Error) => void;- const compact = vi.fn(() => new Promise<never>((_resolve, reject) => {- rejectCompact = reject;- }));+ const compact = vi.fn(+ () =>+ new Promise<never>((_resolve, reject) => {+ rejectCompact = reject;+ }),+ );vi.stubGlobal('window', { electronAPI: { maker: { input: { compact } } } });const { makerChatStore } = await import('@/lib/makerChatStore');@@ -990,10 +995,7 @@ describe('ChatInput 的入口门控与调用路由', () => {compactSession,);const resumeQueue = storeSource.indexOf('function resumeQueue(');- const resumeBegin = storeSource.indexOf(- 'runAgentDispatchProjectionOperation(',- resumeQueue,- );+ const resumeBegin = storeSource.indexOf('runAgentDispatchProjectionOperation(', resumeQueue);const steerMessage = storeSource.indexOf('function steerMessage(');const steerBegin = storeSource.indexOf('return withAgentSendDispatch(', steerMessage);const steerQueuedMessage = storeSource.indexOf('function steerQueuedMessage(');@@ -1095,7 +1097,10 @@ describe('ChatInput 的入口门控与调用路由', () => {it('切换事务返回真实结果:失败 / 被拒返 false,登记成功才返 true', () => {const start = source.indexOf('const performAgentSwitch = useCallback(');expect(start).toBeGreaterThan(-1);- const body = source.slice(start, source.indexOf('const performAgentSwitchRef = useRef(', start));+ const body = source.slice(+ start,+ source.indexOf('const performAgentSwitchRef = useRef(', start),+ );// 签名显式声明 Promise<boolean> —— 返回值是契约的一部分,不靠推断。expect(body).toContain('): Promise<boolean> => {');// 「没落地」的四个出口:无会话 / pending send 拒绝 / 会话已切走 / ack 被超车。@@ -1156,9 +1161,15 @@ describe('ChatInput 的入口门控与调用路由', () => {// ★ 偏好同步同族(2026-08-19 review P2):回声已匹配时 syncSessionDraftModelPrefs 也必须// 用权威快照的 effort/fastMode/providerId —— 覆盖 effort-only / Fast-only / 两者均改 /// provider 归一化四种场景;权威快照缺某字段时该维不写,不回落本端旧值。- expect(source).toContain('const authoritative = registeredIntentMatchesCurrent ? registeredIntent : null;');- expect(source).toContain('const syncedEffort = authoritative ? authoritative.effort : newEffort;');- expect(source).toContain('const syncedFast = authoritative ? authoritative.fastMode : targetFast;');+ expect(source).toContain(+ 'const authoritative = registeredIntentMatchesCurrent ? registeredIntent : null;',+ );+ expect(source).toContain(+ 'const syncedEffort = authoritative ? authoritative.effort : newEffort;',+ );+ expect(source).toContain(+ 'const syncedFast = authoritative ? authoritative.fastMode : targetFast;',+ );expect(source).toContain('const syncedProviderId = authoritative ? authoritative.providerId : providerId;',);@@ -1182,8 +1193,7 @@ describe('ChatInput 的入口门控与调用路由', () => {resolve(process.cwd(), 'src/renderer/components/new-chat/ModelSelector.tsx'),'utf8',).replace(/\r\n/g, '\n');- const matches =- selectorSource.match(/open=\{open \|\| keepOpenForAgentConfirmation\}/g) ?? [];+ const matches = selectorSource.match(/open=\{open \|\| keepOpenForAgentConfirmation\}/g) ?? [];expect(matches).toHaveLength(2);expect(selectorSource).not.toContain('(open || keepOpenForAgentConfirmation) && !disabled');expect(selectorSource).not.toContain('(open && !disabled) || keepOpenForAgentConfirmation');@@ -1193,9 +1203,7 @@ describe('ChatInput 的入口门控与调用路由', () => {});it('换引擎确认只认任务真实引擎,不认挂着的意图', () => {- expect(source).toContain(- 'runtimeAgentKind != null && runtimeAgentKind === targetAgent',- );+ expect(source).toMatch(/runtimeAgentKind != null\s*&&\s*runtimeAgentKind === targetAgent/);expect(source).not.toContain('makerChatStore.getAgentSwitchIntent(sessionId)?.target === targetAgent',);@@ -1236,8 +1244,6 @@ describe('ChatInput 的入口门控与调用路由', () => {});});--describe('CCAgentSessionView 上下文环压缩入口按 agent 能力分流(#1927)', () => {const viewSource = readFileSync(resolve(process.cwd(), 'src/renderer/features/cc-agent/CCAgentSessionView.tsx'),diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex c61b752cec..1ebea2bfbb 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -1121,6 +1121,7 @@ export function ChatInput({const recommendationRef = useRef(recommendation);recommendationRef.current = recommendation;const showRecommendationRef = useRef(false);+ const acceptPromptRecommendationRef = useRef<() => boolean>(() => false);// session 切换时 ChatInput/Editor 会复用;推荐资格必须等目标草稿完成水合后再判断。const [composerHydrationGeneration, setComposerHydrationGeneration] = useState(0);// 完整输入框空判断:不仅检查 ProseMirror 文档是否为空,还检查附件、浏览器评论和语音稿。@@ -2379,23 +2380,10 @@ export function ChatInput({!event.altKey &&!event.repeat &&!event.isComposing &&- showRecommendationRef.current &&- recommendedPromptRef.current &&- !composerMutationLockedRef.current+ acceptPromptRecommendationRef.current()) {- if (composerFullyEmptyRef.current()) {- const prompt = recommendedPromptRef.current;- if (!prompt) return false;- event.preventDefault();- const activeRecommendation = recommendationRef.current;- // 先消费 Store 条目(overlay 与正文同位置,不先撤会有一帧重叠),再插入文本。- showRecommendationRef.current = false;- if (sessionId && activeRecommendation) {- dismissPromptRecommendation(sessionId, activeRecommendation.revision);- }- view.dispatch(view.state.tr.insertText(prompt));- return true;- }+ event.preventDefault();+ return true;}// cycle-permission-mode (registry 默认 Shift+Tab, 用户可改绑) —— 输入框@@ -2586,7 +2574,7 @@ export function ChatInput({void voiceInputStopAndSendRef.current(enterIntent);return true;}- void dispatchSendRef.current(enterIntent);+ void voiceInputStopAndSendRef.current(enterIntent);return true;}return false;@@ -3252,7 +3240,7 @@ export function ChatInput({if (panelBridgeRef.current?.captureKey(event)) return;clearPressTimer();voiceShortcutPressRef.current = null;- void dispatchSendRef.current(enterIntent);+ void voiceInputStopAndSendRef.current(enterIntent);return;}@@ -5628,6 +5616,31 @@ export function ChatInput({[onQueueSteer],);+ const acceptPromptRecommendation = useCallback((): boolean => {+ if (+ !editor ||+ editor.isDestroyed ||+ !showRecommendationRef.current ||+ !recommendedPromptRef.current ||+ !composerFullyEmptyRef.current() ||+ composerMutationLockedRef.current+ ) {+ return false;+ }+ const prompt = recommendedPromptRef.current;+ const activeRecommendation = recommendationRef.current;+ // 与 Tab 接受保持同一消费顺序:先撤 overlay,再同步写入正文,让本次点击+ // 复用完整发送链;若后续预检失败,推荐词仍作为普通草稿留在输入框供重试。+ showRecommendationRef.current = false;+ if (sessionId && activeRecommendation) {+ dismissPromptRecommendation(sessionId, activeRecommendation.revision);+ }+ editor.view.dispatch(editor.state.tr.insertText(prompt));+ editor.commands.focus('end');+ return true;+ }, [editor, sessionId]);+ acceptPromptRecommendationRef.current = acceptPromptRecommendation;+const handleClickSend = useCallback(async (deliveryMode: MessageDeliveryMode = 'queue') => {if (voiceBusyOnCurrentComposer) {@@ -5657,9 +5670,11 @@ export function ChatInput({await stopAndSend;return;}+ acceptPromptRecommendation();await dispatchSend(deliveryMode);},[+ acceptPromptRecommendation,dispatchSend,editor,handleVoiceInputStop,@@ -5829,7 +5844,9 @@ export function ChatInput({const markModelChoice = opts.markModelChoice === true;if (!remoteDeviceId) {const vendor = agentKind === 'codex' ? 'codex' : agentKind === 'pi' ? 'pi' : 'cc';- const persistPrefs = markModelChoice ? patchVendorPrefs : patchVendorPrefsPreservingModelChoice;+ const persistPrefs = markModelChoice+ ? patchVendorPrefs+ : patchVendorPrefsPreservingModelChoice;persistPrefs(vendor, {// 换模才带配对并打标记。本机只改思考档 / Fast 不写回活动模型,// 避免未打标用户把区域默认改成当前任务模型。@@ -6038,7 +6055,8 @@ export function ChatInput({hasSwitchIntent:!!sessionId &&!!targetAgent &&- runtimeAgentKind != null && runtimeAgentKind === targetAgent,+ runtimeAgentKind != null &&+ runtimeAgentKind === targetAgent,confirm: confirmDialog,copy: {title: t('newChat.chatInput.agentSwitch.confirmation.title'),@@ -6615,10 +6633,7 @@ export function ChatInput({// model-only 不改变当前生效来源;effort 能力也必须按该来源精确解析,避免同 id 的// 内置模型档位穿进 BYOM。恢复优先级:模型预设 > 旧 per-model 记忆 > 沿用当前 > 模型默认。- const { efforts, defaultEffort } = resolveModelEfforts(- newModelId,- effectiveSourceId,- );+ const { efforts, defaultEffort } = resolveModelEfforts(newModelId, effectiveSourceId);const providerEffort =modelMemory && currentModelAgentKind && effectiveSourceId? modelMemory.getEffort(currentModelAgentKind, effectiveSourceId, newModelId)@@ -7494,7 +7509,7 @@ export function ChatInput({const hasMessage = !isEditorEmpty(editor);renderSnapshotRef.current = composerRenderSnapshot(trigger, hasMessage);- const canSend = hasMessage || hasAttachments || browserComments.length > 0;+ const hasComposerPayload = hasMessage || hasAttachments || browserComments.length > 0;const hasVoiceDraftText = voiceBusyOnCurrentComposer && voiceInput.draftText.trim().length > 0;// 推荐 overlay 的可见判据:开关开启 + 有推荐词 + 输入框空 + 无附件/浏览器评论/语音草稿 + 输入框未锁定。// composerMutationLocked 涵盖 disabled、sendDispatchInFlight、当前输入框所属语音及远程只读/锁定状态。@@ -7513,6 +7528,8 @@ export function ChatInput({});// handleKeyDown 的稳定闭包只按真实可见性接受 Tab,避免隐藏推荐被误填入。showRecommendationRef.current = showRecommendationOverlay;+ // 可见推荐本身就是一次可发送输入:按钮点击时会先把它同步写入正文,再走现有发送链。+ const canSend = hasComposerPayload || showRecommendationOverlay;const [voiceReleaseToSendActive, setVoiceReleaseToSendActive] = useState(false);const sendButtonDisabled = Boolean(disabled ||@@ -7977,23 +7994,27 @@ export function ChatInput({{showRecommendationOverlay && (<divclassName={cn(- 'pointer-events-none absolute left-0 top-0 flex w-full min-w-0 items-center truncate py-[3px]',+ 'pointer-events-none absolute left-0 top-0 inline-flex max-w-full min-w-0 items-center py-[3px]','text-15 leading-[1.467] font-normal','text-[var(--chat-input-placeholder-subtle)]',)}- aria-hidden="true">- <span className="min-w-0 flex-1 truncate">{recommendedPrompt}</span>- <kbd+ <span className="min-w-0 truncate" aria-hidden="true">+ {recommendedPrompt}+ </span>+ <button+ type="button"+ aria-label={`${t('newChat.chatInput.recommendationShortcut')}: ${recommendedPrompt ?? ''}`}className={cn(- 'ml-1.5 inline-flex shrink-0 items-center rounded-full border',- 'border-[var(--chat-input-border)] bg-[var(--perm-code-bg)]',- 'px-1 py-[1px] text-11 font-normal',- 'text-[var(--status-bar-meta)]',+ 'pointer-events-auto ml-1 inline-flex h-4 min-w-[22px] shrink-0 cursor-pointer items-center justify-center rounded-lg border border-current',+ 'bg-transparent px-0.5 text-11 font-normal leading-none text-inherit',+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]',)}+ onMouseDown={(event) => event.preventDefault()}+ onClick={acceptPromptRecommendation}>{t('newChat.chatInput.recommendationShortcut')}- </kbd>+ </button></div>)}</div>diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/composerPromptRecommendation.test.ts b/apps/desktop/src/renderer/components/new-chat/__tests__/composerPromptRecommendation.test.tsindex 8ac3a97f3d..82d194bf19 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/composerPromptRecommendation.test.ts+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/composerPromptRecommendation.test.ts@@ -47,6 +47,73 @@ describe('shouldShowComposerPromptRecommendation', () => {expect(dismissAt).toBeLessThan(clearContentAt);});+ it('推荐可见时启用发送,并在点击后直接作为正文发送', () => {+ expect(CHAT_INPUT_SOURCE).toContain(+ 'const canSend = hasComposerPayload || showRecommendationOverlay;',+ );++ const acceptStart = CHAT_INPUT_SOURCE.indexOf('const acceptPromptRecommendation = useCallback');+ const acceptEnd = CHAT_INPUT_SOURCE.indexOf('const handleClickSend = useCallback', acceptStart);+ const acceptBlock = CHAT_INPUT_SOURCE.slice(acceptStart, acceptEnd);+ expect(acceptStart).toBeGreaterThanOrEqual(0);+ expect(acceptBlock).toContain('!showRecommendationRef.current');+ expect(acceptBlock).toContain('!composerFullyEmptyRef.current()');+ expect(acceptBlock).toContain('composerMutationLockedRef.current');+ expect(acceptBlock).toContain('showRecommendationRef.current = false;');+ expect(acceptBlock).toContain(+ 'dismissPromptRecommendation(sessionId, activeRecommendation.revision)',+ );+ expect(acceptBlock).toContain('editor.view.dispatch(editor.state.tr.insertText(prompt));');+ expect(acceptBlock).toContain("editor.commands.focus('end');");+ expect(acceptBlock).toContain(+ 'acceptPromptRecommendationRef.current = acceptPromptRecommendation;',+ );++ const clickStart = acceptEnd;+ const clickEnd = CHAT_INPUT_SOURCE.indexOf(+ 'voiceInputStopAndSendRef.current = handleClickSend;',+ clickStart,+ );+ const clickBlock = CHAT_INPUT_SOURCE.slice(clickStart, clickEnd);+ expect(clickBlock.lastIndexOf('acceptPromptRecommendation();')).toBeLessThan(+ clickBlock.lastIndexOf('await dispatchSend(deliveryMode);'),+ );+ });++ it('键盘 Tab 与可点击 keycap 共用同一个推荐接受动作', () => {+ expect(CHAT_INPUT_SOURCE).toContain(+ 'const acceptPromptRecommendationRef = useRef<() => boolean>(() => false);',+ );+ expect(CHAT_INPUT_SOURCE).toContain('acceptPromptRecommendationRef.current()');+ expect(CHAT_INPUT_SOURCE).toContain('onClick={acceptPromptRecommendation}');+ });++ it('所有配置为发送的 Enter 快捷键都与点击按钮走同一条发送链', () => {+ const editorEnterStart = CHAT_INPUT_SOURCE.indexOf(+ '// Resolve the configurable send shortcut after structured list handling.',+ );+ const editorEnterEnd = CHAT_INPUT_SOURCE.indexOf('return false;\n },', editorEnterStart);+ const editorEnterBlock = CHAT_INPUT_SOURCE.slice(editorEnterStart, editorEnterEnd);+ const windowEnterStart = CHAT_INPUT_SOURCE.indexOf(+ 'const enterIntent = resolveComposerEnterIntent(',+ editorEnterEnd,+ );+ const windowEnterEnd = CHAT_INPUT_SOURCE.indexOf(+ "if (\n currentState === 'listening'",+ windowEnterStart,+ );+ const windowEnterBlock = CHAT_INPUT_SOURCE.slice(windowEnterStart, windowEnterEnd);++ expect(editorEnterStart).toBeGreaterThanOrEqual(0);+ expect(editorEnterBlock).toContain("if (enterIntent === 'native') return false;");+ expect(editorEnterBlock).toContain('void voiceInputStopAndSendRef.current(enterIntent);');+ expect(editorEnterBlock).not.toContain('void dispatchSendRef.current(enterIntent);');+ expect(windowEnterStart).toBeGreaterThan(editorEnterEnd);+ expect(windowEnterBlock).toContain('panelBridgeRef.current?.captureKey(event)');+ expect(windowEnterBlock).toContain('void voiceInputStopAndSendRef.current(enterIntent);');+ expect(windowEnterBlock).not.toContain('void dispatchSendRef.current(enterIntent);');+ });+it('等待目标 session 草稿水合后才判断 candidate 是否为空输入', () => {expect(CHAT_INPUT_SOURCE).toContain('storageKeyForDraftRef.current !== storageKey');expect(CHAT_INPUT_SOURCE).toContain(diff --git a/apps/desktop/src/renderer/lib/__tests__/providerModelEfforts.test.ts b/apps/desktop/src/renderer/lib/__tests__/providerModelEfforts.test.tsindex 852d3830c8..f23fab2b08 100644--- a/apps/desktop/src/renderer/lib/__tests__/providerModelEfforts.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/providerModelEfforts.test.ts@@ -146,7 +146,7 @@ describe('resolveProviderModelEfforts', () => {'resolveModelEfforts(\n newModelId,\n providerId,\n targetAgentKind,\n )',);expect(source.slice(modelChangeStart, modelChangeEnd)).toMatch(- /resolveModelEfforts\(\s*newModelId,\s*effectiveSourceId,\s*\)/,+ /resolveModelEfforts\(\s*newModelId,\s*effectiveSourceId,?\s*\)/,);expect(source.slice(providerChangeStart, providerChangeEnd)).toContain('{ effort: eff, fastMode: restoredFast }',