Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(composer): 保留已有提示消息的显示优先级

Dash2722d0339f37
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index 088bb0398f..7c68cda8ba 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -8998,8 +8998,22 @@ export function ChatInput({
});
// 推荐 overlay 的可见判据:开关开启 + 有推荐词 + 输入框空 + 无附件/浏览器评论/语音草稿 + 输入框未锁定。
// composerMutationLocked 涵盖 disabled、sendDispatchInFlight、当前输入框所属语音及远程只读/锁定状态。
+ const showRecommendationOverlay = shouldShowComposerPromptRecommendation({
+ ...recommendationComposerState,
+ prompt: recommendedPrompt,
+ });
+ // handleKeyDown 的稳定闭包只按真实可见性接受 Tab,避免隐藏推荐被误填入。
+ showRecommendationRef.current = showRecommendationOverlay;
+ // 首页建议悬停预览:输入框锁定(发送中 / 语音占用 / 禁用)时不预览,免得遮住进行中的状态。
+ // 预览期间有按键或硬件动作时撤掉本次预览、露出真实正文(闸门见 handleKeyDown 与硬件动作订阅);
+ // 建议移开后复位。
+ const [dismissedPreviewPrompt, setDismissedPreviewPrompt] = useState<string | null>(null);
+ if (!previewPrompt && dismissedPreviewPrompt !== null) setDismissedPreviewPrompt(null);
+ const showPromptPreview =
+ !!previewPrompt && previewPrompt !== dismissedPreviewPrompt && !composerMutationLocked;
const voiceHintEmpty =
!!editor && !editor.isDestroyed && composerDocIsEmpty(editor.state.doc) && !hasVoiceDraftText;
+ // 已有推荐或建议预览优先于语音入门提示;实际录音仍由输入框锁定状态切换为录音指引。
const voiceHint = voiceHintEmpty
? voiceBusyOnCurrentComposer && voiceInput.state === 'listening'
? t(
@@ -9007,24 +9021,15 @@ export function ChatInput({
? 'newChat.chatInput.voiceInput.speakRelease'
: 'newChat.chatInput.voiceInput.speakPressAgain',
)
- : composerVoiceHovered && composerVoiceHoverHintReady && composerLongPressVoiceInputEnabled && !composerTypingLocked
+ : !showRecommendationOverlay &&
+ !showPromptPreview &&
+ composerVoiceHovered &&
+ composerVoiceHoverHintReady &&
+ composerLongPressVoiceInputEnabled &&
+ !composerTypingLocked
? t('newChat.chatInput.voiceInput.holdComposer')
: null
: null;
- const showRecommendationOverlay =
- !voiceHint && shouldShowComposerPromptRecommendation({
- ...recommendationComposerState,
- prompt: recommendedPrompt,
- });
- // handleKeyDown 的稳定闭包只按真实可见性接受 Tab,避免隐藏推荐被误填入。
- showRecommendationRef.current = showRecommendationOverlay;
- // 首页建议悬停预览:输入框锁定(发送中 / 语音占用 / 禁用)时不预览,免得遮住进行中的状态。
- // 预览期间有按键或硬件动作时撤掉本次预览、露出真实正文(闸门见 handleKeyDown 与硬件动作订阅);
- // 建议移开后复位。
- const [dismissedPreviewPrompt, setDismissedPreviewPrompt] = useState<string | null>(null);
- if (!previewPrompt && dismissedPreviewPrompt !== null) setDismissedPreviewPrompt(null);
- const showPromptPreview =
- !!previewPrompt && previewPrompt !== dismissedPreviewPrompt && !composerMutationLocked && !voiceHint;
promptPreviewInputGuardRef.current = () => {
if (!showPromptPreview) return false;
setDismissedPreviewPrompt(previewPrompt ?? null);
diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx
index 87d9f057b2..7d35d78eda 100644
--- a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx
@@ -22,6 +22,13 @@ import type { ModelSelector } from '../ModelSelector';
import type { UseVoiceInputResult } from '@/voice-input/useVoiceInput';
import { useAttachments } from '@/hooks/useAttachments';
import { dispatchInputDeviceAction } from '@/lib/inputDeviceActions';
+import { makerChatStore } from '@/lib/makerChatStore';
+import {
+ __testing as promptRecommendations,
+ beginPromptRecommendationPrediction,
+ clearPromptRecommendationSession,
+ resolvePromptRecommendationPrediction,
+} from '@/lib/promptRecommendationStore';
import type { InputDeviceRendererAction } from '../../../../shared/inputDevices';
const h = vi.hoisted(() => ({ t: (key: string) => key, confirm: vi.fn(), editor: null as Editor | null, listening: false, stop: vi.fn().mockResolvedValue(undefined),
@@ -304,6 +311,45 @@ it('shows voice guidance only in an empty composer and distinguishes holding fro
expect(screen.queryByTestId('composer-voice-hint')).toBeNull();
});
+// 2026-10-26 regression (unit/jsdom): existing guidance must survive the 500ms
+// voice hover delay. The empty-composer test above has no recommendation/preview.
+it.each(['recommendation', 'preview'] as const)('keeps %s visible while hovering the empty composer', async kind => {
+ const sessionId = 'voice-hint-priority';
+ const prompt = 'Continue with this plan';
+ const view = renderComposer({ sessionId, previewPrompt: kind === 'preview' ? prompt : undefined });
+ await waitFor(() => expect(h.editor).not.toBeNull());
+ vi.spyOn(makerChatStore, 'getPromptRecommendationCompletionStatus').mockReturnValue({
+ turnStoppedByUser: false, hasTerminalError: false, sideTask: false,
+ hasBackgroundAgentWork: false, hasAutoDrainingQueue: false,
+ });
+ if (kind === 'recommendation') {
+ await act(async () => {
+ promptRecommendations.applyRunningSnapshot(new Map([[sessionId, { isRunning: true }]]));
+ promptRecommendations.noteTurnEnded(sessionId, 200);
+ promptRecommendations.applyRunningSnapshot(new Map());
+ promptRecommendations.settleCompletion(sessionId);
+ const seq = beginPromptRecommendationPrediction(sessionId, 200)!;
+ resolvePromptRecommendationPrediction(sessionId, 200, seq, prompt);
+ });
+ }
+ expect(screen.getByText(prompt)).toBeTruthy();
+ vi.useFakeTimers();
+ try {
+ fireEvent.pointerEnter(h.editor!.view.dom.parentElement!.parentElement!);
+ await act(async () => { await vi.advanceTimersByTimeAsync(500); });
+ expect(screen.queryByTestId('composer-voice-hint')).toBeNull();
+ expect(screen.getByText(prompt)).toBeTruthy();
+ if (kind === 'recommendation') {
+ supplyRangeGeometry();
+ await act(async () => { fireEvent.keyDown(h.editor!.view.dom, { key: 'Tab' }); });
+ expect(h.editor!.getText()).toBe(prompt);
+ }
+ } finally {
+ vi.useRealTimers();
+ clearPromptRecommendationSession(sessionId);
+ }
+});
+
// #374 / voiceInputButtonAnchor: the real toolbar must keep the voice control
// immediately beside the main action while listening, submitting, refining,
// and returning to idle. A source-text guard could miss a misplaced rendered