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(voice): keep companion calls available with prompt recommendations

JiangJiahaoa5d3bcd08fb7
diff --git a/apps/desktop/scripts/fixtures/companion-composer/companion-composer-fixture.tsx b/apps/desktop/scripts/fixtures/companion-composer/companion-composer-fixture.tsx
index 44bde6cea4..ee0a63ff71 100644
--- a/apps/desktop/scripts/fixtures/companion-composer/companion-composer-fixture.tsx
+++ b/apps/desktop/scripts/fixtures/companion-composer/companion-composer-fixture.tsx
@@ -1,7 +1,14 @@
-import { useState, type ComponentProps } from 'react';
-import { mountPage, subscription } from '../../ui-page/harness';
+import { useEffect, useState, type ComponentProps } from 'react';
+import { ctx, mountPage, subscription } from '../../ui-page/harness';
import { ChatInput } from '../../../src/renderer/components/new-chat/ChatInput';
import { getDefaultVoiceInputSettings } from '../../../src/shared/voiceInputData';
+import { makerChatStore } from '../../../src/renderer/lib/makerChatStore';
+import {
+ __testing as promptRecommendations,
+ beginPromptRecommendationPrediction,
+ clearPromptRecommendationSession,
+ resolvePromptRecommendationPrediction,
+} from '../../../src/renderer/lib/promptRecommendationStore';
// The fixture's custom origin lacks secure-context randomUUID. These IDs only
// identify in-memory send snapshots; production uses Chromium's secure implementation.
@@ -16,6 +23,21 @@ function Fixture() {
const [running, setRunning] = useState(false);
const [callOpen, setCallOpen] = useState(false);
const [sent, setSent] = useState('');
+ useEffect(() => {
+ if (typeof ctx.data.recommendation !== 'string') return;
+ const sessionId = 'fixture-companion';
+ // Seed a completed turn and model result; keep the real recommendation
+ // store, editor acceptance and call/send dispatch for the coexistence check.
+ makerChatStore.getSnapshot(sessionId);
+ promptRecommendations.applyRunningSnapshot(new Map([[sessionId, { isRunning: true }]]));
+ promptRecommendations.noteTurnEnded(sessionId, 200);
+ promptRecommendations.applyRunningSnapshot(new Map());
+ promptRecommendations.settleCompletion(sessionId);
+ const seq = beginPromptRecommendationPrediction(sessionId, 200);
+ if (seq !== null)
+ resolvePromptRecommendationPrediction(sessionId, 200, seq, ctx.data.recommendation);
+ return () => clearPromptRecommendationSession(sessionId);
+ }, []);
const files: ComponentProps<typeof ChatInput>['attachmentState'] = {
attachments: attached
? [
diff --git a/apps/desktop/scripts/fixtures/companion-composer/ui-page.mjs b/apps/desktop/scripts/fixtures/companion-composer/ui-page.mjs
index 4862d9cba7..5c32d42859 100644
--- a/apps/desktop/scripts/fixtures/companion-composer/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/companion-composer/ui-page.mjs
@@ -27,6 +27,15 @@ export default {
'src/renderer/voice-input/useVoiceInput': `import { useState, useRef } from 'react'; export function useVoiceInput(editor) { const [state, setState] = useState('idle'); const current = useRef(state); const update = value => { current.current = value; setState(value); }; return { state, getState: () => current.current, isListening: state === 'listening', isBusy: state !== 'idle', draftText: '', start: () => { update('listening'); return true; }, stop: async () => { update('idle'); editor?.commands.setContent('<p>Dictated message</p>'); }, cancel: async () => update('idle') }; }`,
},
cases: {
+ recommendation: {
+ about: 'Recommendation and call coexist; starting a call preserves the suggestion, accepting it restores Send',
+ data: { recommendation: '帮我整理下一步计划' },
+ },
+ 'recommendation-narrow': {
+ about: 'Recommendation and call remain usable at narrow width',
+ data: { recommendation: '帮我整理下一步计划' },
+ viewport: { width: 360, height: 400 },
+ },
'voice-hold': {
about: 'Empty composer hints, native mouse selection during hold, and button hold/click release semantics',
viewport: { width: 360, height: 400 },
@@ -44,6 +53,34 @@ export default {
await page.locator('[contenteditable="true"]').waitFor();
},
async check(page, ui) {
+ if (ui.data.recommendation) {
+ const editor = page.locator('[contenteditable]');
+ const call = page.getByRole('button', { name: await ui.t('bots.voiceMode.startConversation'), exact: true });
+ const send = page.getByRole('button', { name: await ui.t('newChat.sendButton.send'), exact: true });
+ const suggestion = page.getByRole('button', {
+ name: `${await ui.t('newChat.chatInput.recommendationShortcut')}: ${ui.data.recommendation}`,
+ exact: true,
+ });
+ await suggestion.waitFor();
+ await ui.capture('recommendation');
+ assert.equal(await call.count(), 1);
+ assert.equal(await send.count(), 0);
+ await call.click();
+ assert.equal(await suggestion.count(), 0);
+ assert.equal(await editor.textContent(), '');
+ assert.equal(await page.getByTestId('sent').textContent(), '');
+ await page.getByTestId('end-call').click();
+ await suggestion.waitFor();
+ assert.equal(await call.evaluate((node) => node === document.activeElement), true);
+ await suggestion.click();
+ assert.equal(await editor.textContent(), ui.data.recommendation);
+ assert.equal(await call.count(), 0);
+ await ui.capture('accepted');
+ await send.click();
+ await call.waitFor();
+ assert.equal(await page.getByTestId('sent').textContent(), ui.data.recommendation);
+ return;
+ }
if (ui.case === 'voice-hold') {
const editor = page.locator('.ProseMirror');
const hint = page.getByTestId('composer-voice-hint');
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index 57296755bb..abc71dc7c5 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -9196,11 +9196,13 @@ export function ChatInput({
showStopButton && (canSend || voiceBusyOnCurrentComposer) && !sendDispatchInFlight;
// Companion-only idle action: keep the existing send/stop slots and voice-release
// target. Recording/refinement and queue editing must never become "start call".
+ // A recommendation is still a suggestion: keep the call available until the
+ // user accepts it into the draft. Its Tab/click acceptance and Enter send remain available.
const mainSlotIsVoice = Boolean(
onStartVoiceConversation &&
!queueEditActive &&
!mainSlotIsStop &&
- !canSend &&
+ !hasComposerPayload &&
!hasVoiceDraftText &&
!voiceBusyOnCurrentComposer,
);
diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx
index 8a28e82312..3528383777 100644
--- a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx
@@ -620,6 +620,61 @@ function companionProps() {
return { ...props, deviceLinkDeviceId: null, initialModel: 'fixture-chat', initialProviderId: 'openai' };
}
+// Unit regression for the 2026-10-29 coexistence rule: an empty companion
+// editor with a ready recommendation must still offer a call. Existing tests
+// cover drafts and recommendations separately, not this combined state.
+it.each(['click', 'Tab', 'Enter'] as const)('keeps a recommendation alongside the call action and accepts it with %s', async (accept) => {
+ const onSend = vi.fn().mockResolvedValue(true);
+ const onStartVoiceConversation = vi.fn();
+ const inputProps = { ...companionProps(), sessionId: 'queue-shortcut', onSend, onStartVoiceConversation };
+ const view = render(<ChatInput {...inputProps} />);
+ await act(async () => { h.editor!.commands.clearContent(); });
+ // jsdom has no Range geometry; real selection scrolling is covered by the Electron fixture.
+ h.editor!.view.setProps({ handleScrollToSelection: () => true });
+ vi.spyOn(makerChatStore, 'getPromptRecommendationCompletionStatus').mockReturnValue({
+ turnStoppedByUser: false, hasTerminalError: false, sideTask: false,
+ hasBackgroundAgentWork: false, hasAutoDrainingQueue: false,
+ });
+ const prompt = 'Continue with the recommendation';
+ await act(async () => {
+ promptRecommendations.applyRunningSnapshot(new Map([['queue-shortcut', { isRunning: true }]]));
+ promptRecommendations.noteTurnEnded('queue-shortcut', 200);
+ promptRecommendations.applyRunningSnapshot(new Map());
+ promptRecommendations.settleCompletion('queue-shortcut');
+ const seq = beginPromptRecommendationPrediction('queue-shortcut', 200)!;
+ resolvePromptRecommendationPrediction('queue-shortcut', 200, seq, prompt);
+ });
+ expect(screen.getByText(prompt)).toBeTruthy();
+ const call = screen.getByRole('button', { name: 'bots.voiceMode.startConversation' });
+ fireEvent.click(call);
+ expect(onStartVoiceConversation).toHaveBeenCalledOnce();
+ expect(onSend).not.toHaveBeenCalled();
+ expect(h.editor!.getText()).toBe('');
+
+ view.rerender(<ChatInput {...inputProps} voiceConversationActive />);
+ expect(screen.queryByText(prompt)).toBeNull();
+ view.rerender(<ChatInput {...inputProps} />);
+ expect(screen.getByText(prompt)).toBeTruthy();
+ await act(async () => {
+ if (accept === 'click') {
+ fireEvent.click(screen.getByRole('button', { name: `newChat.chatInput.recommendationShortcut: ${prompt}` }));
+ } else {
+ h.editor!.view.dom.focus();
+ fireEvent.keyDown(h.editor!.view.dom, { key: accept, code: accept });
+ }
+ });
+ if (accept !== 'Enter') {
+ expect(h.editor!.getText()).toBe(prompt);
+ expect(screen.queryByRole('button', { name: 'bots.voiceMode.startConversation' })).toBeNull();
+ expect(onSend).not.toHaveBeenCalled();
+ await act(async () => { fireEvent.click(screen.getByRole('button', { name: 'newChat.sendButton.send' })); });
+ }
+ expect(onSend).toHaveBeenCalledOnce();
+ expect(onSend.mock.calls[0][0]).toBe(prompt);
+ expect(onStartVoiceConversation).toHaveBeenCalledOnce();
+ expect(screen.getByRole('button', { name: 'bots.voiceMode.startConversation' })).toBeTruthy();
+});
+
it('switches one companion action between call and send, retaining focus and dispatching the draft once', async () => {
const onSend = vi.fn().mockResolvedValue(true);
const onStartVoiceConversation = vi.fn();
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 3e78e0d411..10e4ee33d3 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -1252,9 +1252,11 @@ Applies to submit-on-Enter fields: the chat composer, goal input, ask input, etc
> Expanded 2026-07. Cindy's motion character extends the paper-like restraint of §1 / §7: **ordinary UI fades, nudges, and resizes smoothly; overshoot is limited to the explicitly registered Done, Usage History chart and mobile new-task morph responses below**. Functional state transitions are allowed; decorative motion is forbidden. This section pins "functional" into executable tiers and prototypes so components stop inventing their own durations and curves.
**Desktop companion composer action (owner-approved prototype, 2026-10-22).** An idle
-one-to-one companion composer shows dictation and a call action. A sendable draft
-(including attachments or a visible prompt recommendation) replaces the call with Send
-in the same 30px circular target. Crossfade the icon layers and scale 55% ↔ 100% on
+one-to-one companion composer shows dictation and a call action. A visible prompt
+recommendation keeps the call action available (owner correction, 2026-10-29); its
+Tab/click acceptance and Enter send remain available. An accepted or typed draft,
+attachments or browser comments replace the call with Send in the same 30px circular
+target. Crossfade the icon layers and scale 55% ↔ 100% on
`--motion-enter` (250ms) / `--motion-ease-move`; keep the shell, hit target and dictation
position fixed, with no bounce. CSS transitions retarget from their current values.
Respect reduced motion, retain keyboard focus, and reject a press whose action changes
diff --git a/docs/design-rules/design-inventory.md b/docs/design-rules/design-inventory.md
index 9da7569d75..be3264141c 100644
--- a/docs/design-rules/design-inventory.md
+++ b/docs/design-rules/design-inventory.md
@@ -273,6 +273,6 @@ Mobile 已由 DS-7 纳入同一台账(2026-09-10 静态入口发现),保
伙伴语音操作条:`CompanionVoiceToolbar.tsx` 复用原通话控制器,输入框保留草稿并锁定,操作条与详情预留布局空间;窄窗换行,Light/Dark 语义 token,退出及后台任务边界见 `docs/product-rules/companion-voice-mode.md`。
-伙伴输入框双按钮(2026-10-22,用户确认原型):`ChatInput` / `SendButton` 在空输入时显示听写与语音对话,有可发送内容后同槽位切换为发送;30px 固定命中区,250ms 图标缩放与淡切,Light/Dark 语义 token,减弱动效即时切换。保留停止、排队、待发内容编辑和听写发送。规范见 `DESIGN.md §14.4`,验证入口 `ui:check --page companion-composer`;截图证据随 #6768 发布,不等同真实 ASR/TTS 验收。
+伙伴输入框双按钮(2026-10-22,用户确认原型):`ChatInput` / `SendButton` 在空输入时显示听写与语音对话;推荐输入出现时仍保留语音入口,采纳推荐为正文或输入正文、添加附件/浏览器评论后同槽位切换为发送(2026-10-29 用户裁决);30px 固定命中区,250ms 图标缩放与淡切,Light/Dark 语义 token,减弱动效即时切换。保留停止、排队、待发内容编辑和听写发送。规范见 `DESIGN.md §14.4`,验证入口 `ui:check --page companion-composer`;截图证据随 #6768 发布,不等同真实 ASR/TTS 验收。
语音型号管理(2026-10-23,#6768 评审修复):`desktop.settings` 的 TTS 行复用显示开关与未显示分区,支持重新选回首次未勾选的目录型号;Main 的可用性投影复用伙伴朗读目录资格。北京 Token Plan 独立推荐 Qwen-Audio,两个添加入口同源。沿用 `DESIGN.md §4` 标准控件、`§5` 点击目标与 `§10` 双主题语义 token;双主题单页证据随 PR 提供,不等同真实套餐合成验收。
diff --git a/docs/product-rules/companion-voice-mode.md b/docs/product-rules/companion-voice-mode.md
index f377e9da26..c9a8d04b8b 100644
--- a/docs/product-rules/companion-voice-mode.md
+++ b/docs/product-rules/companion-voice-mode.md
@@ -2,7 +2,7 @@
## 范围与行为
-- 本机伙伴一对一输入框在空闲、无可发送内容时显示听写与语音对话两个按钮,语音对话使用声波图标和“开始语音对话”提示。输入非空文字、添加附件或显示可发送的推荐内容后,语音对话按钮在同一槽位切换为发送;250ms 图标缩放与淡切,减弱动效时即时切换。录音/转写期间保留结束并发送入口,伙伴工作时的停止、排队和待发内容编辑保持原有语义。标题栏不再提供语音入口。沿用伙伴身份和所选聊天模型,为每次通话建立独立上下文;日常语音不逐条写入 canonical 任务。需要执行的工作交给原 canonical 任务,继续复用其工作目录、工具权限和后台执行流程。
+- 本机伙伴一对一输入框在空闲、无正文、附件或浏览器评论时显示听写与语音对话两个按钮,语音对话使用声波图标和“开始语音对话”提示。推荐输入与语音对话入口同时保留(2026-10-29 用户裁决):推荐出现不替换声波按钮,点击声波不采纳或发送推荐;推荐仍可按 Tab 或点击采纳,也可按发送快捷键直接发送。推荐采纳为正文、输入非空文字、添加附件或浏览器评论后,语音对话按钮在同一槽位切换为发送;250ms 图标缩放与淡切,减弱动效时即时切换。录音/转写期间保留结束并发送入口,伙伴工作时的停止、排队和待发内容编辑保持原有语义。标题栏不再提供语音入口。沿用伙伴身份和所选聊天模型,为每次通话建立独立上下文;日常语音不逐条写入 canonical 任务。需要执行的工作交给原 canonical 任务,继续复用其工作目录、工具权限和后台执行流程。
- 用户点击输入框的语音对话按钮后,重新读取当前目录和该伙伴偏好;配置有效即开始连接并采集麦克风,无需再点击“开始”。模型缺失、音色未选或接口不明时直接打开“伙伴设置 → 语音”,不采集麦克风;设置完成不会自动开始,需返回输入框明确点击。使用现有语音输入的 ASR 设置和当前账号的服务模式;不启用听写润色,不修改原有听写行为。
- 自动发送仍保留 1.25 秒停顿,但声音停顿与文字稳定独立计时。上游提供可校验的音频结束位置时,依据实际已处理音频核对停顿;迟到/修订的最终文字只重新等待 350ms 稳定窗口,不再重启整段 1.25 秒。没有时间信息、时间越界或恢复重放无法对齐音频时钟时,继续从文字变化开始保守等待 1.25 秒,保护只有 ASR 检出的弱声。后续声音活动仍延后发送,未定稿分段仍阻止发送;手动发送可跳过停顿,但不能发送未完成的识别文字。900ms 声音释放只提前提交 ASR 缓冲,声音活动检测本身不能产生消息。
- ASR 能力声明区分片段定稿(`segment-final`)、声学停顿(`acoustic`)、手动提交(`manual`)与语义结束(`semantic`)。`final` 只锁定片段文字,实际 `turnEnd` 需要独立证据;能力声明本身也不是一次轮次结束事件。本阶段不启用语义提前发送、不增加语义断句模型调用,所有模式仍保留 1.25 秒回退。SAUC 传递有效 `end_time`,其 `definite` 不推断语义结束;Qwen 关联同一 item 的 `speech_stopped.audio_end_ms`,只标声学结束;OpenAI 手动模式标明 commit,不能当作用户说完;ElevenLabs Scribe 声明 VAD 能力,但没有时间/结束原因的 committed 文本仍按回退处理。fallback 只继承实际胜出的供应商能力与事件,旧连接回调和恢复后的失配时间戳不能缩短等待。