The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scope reply Copy/Read-aloud to the current message, keep full-response as an explicit action
Brooklyn Nicholson966dce069ca4
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsxindex dfbf763bc8b..6ce32363f8c 100644--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx@@ -95,6 +95,13 @@ interface MessageActionProps {* streaming delta flush (the text changes ~30×/s), which profiling showed* was a large slice of per-token script time on long transcripts. */getMessageText: () => string+ /** Lazy accessor for the whole response group's blank-line-joined text — the+ * explicit full-response copy/read-aloud scope (#118864). Identical to+ * `getMessageText` on a solo reply. */+ getFullResponseText: () => string+ /** True when the response group carries more than one text-bearing reply, so+ * the current-reply and full-response scopes actually differ. */+ fullResponseAvailable: booleanonBranchInNewChat?: (messageId: string) => void}@@ -245,7 +252,16 @@ const AssistantMessageBody: FC<AssistantMessageProps & { collapsedNotice?: null// stable across the 30 Hz delta stream, so this adds no per-token renders).const turnDurationS = useAuiState(s => s.message.metadata?.custom?.durationS as number | undefined)- const getMessageText = useCallback(+ // Response-scope text accessors (#118864). The DEFAULT copy/read-aloud reads+ // only THIS message's text: joining the whole response group mixed sealed+ // interim narration and mid-turn commentary into the final reply's clipboard+ // and speech. The whole-turn semantic survives as an explicit second scope+ // (Copy full response / Shift-click Read aloud) — the live-view counterpart+ // of the rehydrated single bubble for the background-continuation grouping+ // 3bdd4cc5fd delivered.+ const getMessageText = useCallback(() => messageContentText(messageRuntime.getState().content), [messageRuntime])++ const getFullResponseText = useCallback(() =>responseIds.length? responseIds@@ -256,6 +272,8 @@ const AssistantMessageBody: FC<AssistantMessageProps & { collapsedNotice?: null[messageRuntime, responseIds, threadRuntime])+ const fullResponseAvailable = responseIds.length > 1+// useEnterAnimation consults `enabled` ONLY when its callback ref fires,// i.e. at mount: the hook parks the value in a ref and returns a// useCallback([]) identity, and its own contract is "`enabled` is captured@@ -321,14 +339,23 @@ const AssistantMessageBody: FC<AssistantMessageProps & { collapsedNotice?: null</MessagePrimitive.Error></div><MessageTimelineTimestamp className="px-(--message-text-indent) pt-0.5" suppressIfDuplicatePart />- {hasVisibleText && !isInterim && responseTail && (- <AssistantFooter- durationS={turnDurationS}- getMessageText={getMessageText}- messageId={messageId}- onBranchInNewChat={onBranchInNewChat}- />- )}+ {/* Sealed interims skip the footer so a tool-heavy turn doesn't grow a+ copy bar per paragraph (72dd01c553) — EXCEPT when the interim is the+ group's last text-bearing row (the turn ended on a tool-only bubble):+ without the bar that turn has no copy/branch affordance at all+ (#118864). */}+ {hasVisibleText &&+ responseTail &&+ (!isInterim || (responseIds.length > 0 && responseIds.at(-1) === messageId)) && (+ <AssistantFooter+ durationS={turnDurationS}+ fullResponseAvailable={fullResponseAvailable}+ getFullResponseText={getFullResponseText}+ getMessageText={getMessageText}+ messageId={messageId}+ onBranchInNewChat={onBranchInNewChat}+ />+ )}{/* Last thing in the turn — under the action bar, the way Cursor ends aturn on its summary rather than burying it above the controls. */}<SettledChangedFiles />@@ -938,6 +965,8 @@ const ErrorRecoveryActions: FC = () => {const AssistantActionBar: FC<MessageActionProps & { durationS?: number }> = ({durationS,+ fullResponseAvailable,+ getFullResponseText,messageId,getMessageText,onBranchInNewChat@@ -992,7 +1021,20 @@ const AssistantActionBar: FC<MessageActionProps & { durationS?: number }> = ({</TooltipIconButton>)}<CopyButton appearance="icon" buttonSize="icon" label={copy.copy} text={getMessageText} />- <ReadAloudButton getText={getMessageText} messageId={messageId} />+ {fullResponseAvailable && (+ <CopyButton+ appearance="icon"+ buttonSize="icon"+ label={copy.copyFullResponse}+ text={getFullResponseText}+ />+ )}+ <ReadAloudButton+ fullResponseAvailable={fullResponseAvailable}+ getFullText={getFullResponseText}+ getText={getMessageText}+ messageId={messageId}+ /><ActionBarPrimitive.Reload asChild><TooltipIconButton onClick={() => triggerHaptic('submit')} tooltip={copy.refresh}><RefreshCwIcon className="size-3.5" />@@ -1039,7 +1081,12 @@ const AssistantActionBar: FC<MessageActionProps & { durationS?: number }> = ({)}-const ReadAloudButton: FC<{ getText: () => string; messageId: string }> = ({ getText, messageId }) => {+const ReadAloudButton: FC<{+ fullResponseAvailable: boolean+ getFullText: () => string+ getText: () => string+ messageId: string+}> = ({ fullResponseAvailable, getFullText, getText, messageId }) => {const { t } = useI18n()const copy = t.assistant.threadconst voicePlayback = useStore($voicePlayback)@@ -1055,29 +1102,41 @@ const ReadAloudButton: FC<{ getText: () => string; messageId: string }> = ({ getconst isSpeaking = readAloudStatus === 'speaking'const anyPlaybackActive = voicePlayback.status !== 'idle'const Icon = isPreparing ? Loader2Icon : isSpeaking ? VolumeXIcon : AudioLines- const tooltip = isPreparing ? copy.preparingAudio : isSpeaking ? copy.stopReading : copy.readAloud-- const read = useCallback(async () => {- const text = getText()- if (!text || $voicePlayback.get().status !== 'idle') {- return- }+ const tooltip = isPreparing+ ? copy.preparingAudio+ : isSpeaking+ ? copy.stopReading+ : fullResponseAvailable+ ? `${copy.readAloud} (${copy.readAloudFullResponseHint})`+ : copy.readAloud++ // Default reads the current reply only; Shift-click reads the whole response+ // group — the read-aloud mirror of the two copy scopes (#118864).+ const read = useCallback(+ async (full: boolean) => {+ const text = full ? getFullText() : getText()++ if (!text || $voicePlayback.get().status !== 'idle') {+ return+ }- try {- await playSpeechText(text, { connectionId, messageId, profile, source: 'read-aloud' })- markAssistantIdSpoken(sessionId, view.$messages.get(), messageId)- } catch (error) {- notifyError(error, copy.readAloudFailed)- }- }, [connectionId, copy.readAloudFailed, getText, messageId, profile, sessionId, view.$messages])+ try {+ await playSpeechText(text, { connectionId, messageId, profile, source: 'read-aloud' })+ markAssistantIdSpoken(sessionId, view.$messages.get(), messageId)+ } catch (error) {+ notifyError(error, copy.readAloudFailed)+ }+ },+ [connectionId, copy.readAloudFailed, getFullText, getText, messageId, profile, sessionId, view.$messages]+ )return (<TooltipIconButtondisabled={isPreparing || (!isSpeaking && anyPlaybackActive)}- onClick={() => {+ onClick={event => {triggerHaptic('selection')- void (isSpeaking ? stopVoicePlayback() : read())+ void (isSpeaking ? stopVoicePlayback() : read(event.shiftKey))}}tooltip={tooltip}>diff --git a/apps/desktop/src/components/assistant-ui/thread/response-copy-scope.test.tsx b/apps/desktop/src/components/assistant-ui/thread/response-copy-scope.test.tsxnew file mode 100644index 00000000000..16970137527--- /dev/null+++ b/apps/desktop/src/components/assistant-ui/thread/response-copy-scope.test.tsx@@ -0,0 +1,93 @@+// Bug #118864: the footer's text accessor (getMessageText) joined EVERY+// message in the response group, so the tail reply's Copy/Read-aloud included+// sealed interim narration and mid-turn commentary. The default Copy/Read+// aloud must read only the current (tail) reply, with a separate+// full-response copy that keeps the whole-tool-turn semantic the grouping+// change (3bdd4cc5fd) delivered for background continuations.+import { cleanup, fireEvent, render, waitFor, within } from '@testing-library/react'+import { afterEach, beforeEach, expect, it, vi } from 'vitest'++import { toChatMessages } from '@/lib/chat-messages'+import { toRuntimeMessage } from '@/lib/chat-runtime'+import type { SessionMessage } from '@/types/hermes'++import { stubThreadEnvironment, ThreadRuntime } from '../test-utils'++import { Thread } from '.'++beforeEach(stubThreadEnvironment)+afterEach(() => {+ cleanup()+ vi.unstubAllGlobals()+})++const stored: SessionMessage[] = [+ { role: 'user', content: 'Verify it.', timestamp: 1 },+ { role: 'assistant', content: 'Checking the deployment.', timestamp: 2 },+ {+ role: 'user',+ content: '[IMPORTANT: Background process proc_example completed normally (exit code 0).\nOutput:\nVerified.]',+ timestamp: 3+ },+ { role: 'assistant', content: 'The deployment is verified.', timestamp: 4 }+]++const messages = () => toChatMessages(stored).map(toRuntimeMessage)++function renderThread() {+ const clipboard = { writeText: vi.fn().mockResolvedValue(undefined) }+ vi.stubGlobal('navigator', { ...navigator, clipboard })++ const rendered = render(+ <ThreadRuntime messages={messages()}>+ <Thread />+ </ThreadRuntime>+ )++ return { clipboard, ...rendered }+}++it('default Copy reads only the tail reply, not the whole response group', async () => {+ const { clipboard, container } = renderThread()++ await waitFor(() => expect(container.textContent).toContain('The deployment is verified.'))+ const actions = container.querySelector('[data-slot="aui_msg-actions"]') as HTMLElement+ fireEvent.click(within(actions).getByRole('button', { name: /^copy$/i }))++ await waitFor(() => expect(clipboard.writeText).toHaveBeenLastCalledWith('The deployment is verified.'))+})++it('Copy full response reads every assistant text segment in the group', async () => {+ const { clipboard, container } = renderThread()++ await waitFor(() => expect(container.textContent).toContain('The deployment is verified.'))+ const actions = container.querySelector('[data-slot="aui_msg-actions"]') as HTMLElement+ fireEvent.click(within(actions).getByRole('button', { name: /copy full response/i }))++ await waitFor(() =>+ expect(clipboard.writeText).toHaveBeenLastCalledWith('Checking the deployment.\n\nThe deployment is verified.')+ )+})++it('a solo reply copies its own text and offers no separate full-response button', async () => {+ const storedSolo: SessionMessage[] = [+ { role: 'user', content: 'Hi', timestamp: 1 },+ { role: 'assistant', content: 'Hello there.', timestamp: 2 }+ ]++ const clipboard = { writeText: vi.fn().mockResolvedValue(undefined) }+ vi.stubGlobal('navigator', { ...navigator, clipboard })++ const { container } = render(+ <ThreadRuntime messages={toChatMessages(storedSolo).map(toRuntimeMessage)}>+ <Thread />+ </ThreadRuntime>+ )++ await waitFor(() => expect(container.textContent).toContain('Hello there.'))+ const actions = container.querySelector('[data-slot="aui_msg-actions"]') as HTMLElement+ fireEvent.click(within(actions).getByRole('button', { name: /^copy$/i }))+ await waitFor(() => expect(clipboard.writeText).toHaveBeenLastCalledWith('Hello there.'))+ // The two scopes are identical on a solo reply, so only the default Copy exists.+ expect(within(actions).queryByRole('button', { name: /copy full response/i })).toBeNull()+})diff --git a/apps/desktop/src/components/assistant-ui/thread/response-group.test.tsx b/apps/desktop/src/components/assistant-ui/thread/response-group.test.tsxindex ec55e9d5485..19064661fa4 100644--- a/apps/desktop/src/components/assistant-ui/thread/response-group.test.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/response-group.test.tsx@@ -58,7 +58,11 @@ it('keeps background continuations in one response with one action bar and the o[...container.querySelectorAll('[data-role="assistant"]')].map(e => e.getAttribute('data-message-id'))).toEqual([messages[1]!.id, messages[3]!.id])const actions = container.querySelector('[data-slot="aui_msg-actions"]') as HTMLElement- fireEvent.click(within(actions).getByRole('button', { name: 'Copy' }))+ // Default Copy reads only the tail reply; the full-response scope is a+ // separate explicit action (#118864).+ fireEvent.click(within(actions).getByRole('button', { name: /^copy$/i }))+ await waitFor(() => expect(clipboard.writeText).toHaveBeenLastCalledWith('The deployment is verified.'))+ fireEvent.click(within(actions).getByRole('button', { name: /copy full response/i }))await waitFor(() =>expect(clipboard.writeText).toHaveBeenLastCalledWith('Checking the deployment.\n\nThe deployment is verified.'))diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.tsindex 9421f89a4dd..4e82e3345e2 100644--- a/apps/desktop/src/i18n/ar.ts+++ b/apps/desktop/src/i18n/ar.ts@@ -3260,6 +3260,8 @@ export const ar = defineLocale({preparingAudio: 'جار تجهيز الصوت',stopReading: 'إيقاف القراءة',readAloud: 'قراءة بصوت عال',+ copyFullResponse: 'نسخ الرد الكامل',+ readAloudFullResponseHint: 'انقر مع الضغط على Shift: قراءة الرد الكامل بصوت عال',editMessage: 'تحرير الرسالة',scrollToBottom: 'التمرير إلى الأسفل',stop: 'إيقاف',diff --git a/apps/desktop/src/i18n/de.ts b/apps/desktop/src/i18n/de.tsindex c0ae6e2809f..f7d74581fcd 100644--- a/apps/desktop/src/i18n/de.ts+++ b/apps/desktop/src/i18n/de.ts@@ -5604,6 +5604,8 @@ export const deOverrides = {preparingAudio: 'Bereitet Audio vor...',stopReading: 'Vorlesen stoppen',readAloud: 'Vorlesen',+ copyFullResponse: 'Vollständige Antwort kopieren',+ readAloudFullResponseHint: 'Umschalt-Klick: vollständige Antwort vorlesen',editMessage: 'Nachricht bearbeiten',expandMessage: 'Nachricht aufklappen',scrollToBottom: 'Nach unten scrollen',diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex f4c91c0eacf..c8c60aaa5c6 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -5194,6 +5194,8 @@ export const en: Translations = {preparingAudio: 'Preparing audio...',stopReading: 'Stop reading',readAloud: 'Read aloud',+ copyFullResponse: 'Copy full response',+ readAloudFullResponseHint: 'Shift-click: read the full response',editMessage: 'Edit message',expandMessage: 'Expand message',scrollToBottom: 'Scroll to bottom',diff --git a/apps/desktop/src/i18n/es.ts b/apps/desktop/src/i18n/es.tsindex 3584ba11c2d..6097799ed37 100644--- a/apps/desktop/src/i18n/es.ts+++ b/apps/desktop/src/i18n/es.ts@@ -5592,6 +5592,8 @@ export const esOverrides = {preparingAudio: 'Preparando audio...',stopReading: 'Detener lectura',readAloud: 'Leer en voz alta',+ copyFullResponse: 'Copiar la respuesta completa',+ readAloudFullResponseHint: 'Mayús+clic: leer la respuesta completa',editMessage: 'Editar mensaje',expandMessage: 'Expandir mensaje',scrollToBottom: 'Desplazarse hacia abajo',diff --git a/apps/desktop/src/i18n/fr.ts b/apps/desktop/src/i18n/fr.tsindex 09c55c98bf3..976ad46a590 100644--- a/apps/desktop/src/i18n/fr.ts+++ b/apps/desktop/src/i18n/fr.ts@@ -5614,6 +5614,8 @@ export const frOverrides = {preparingAudio: "Préparation de l'audio…",stopReading: 'Arrêter la lecture',readAloud: 'Lire à voix haute',+ copyFullResponse: 'Copier la réponse complète',+ readAloudFullResponseHint: 'Maj+clic : lire la réponse complète',editMessage: 'Modifier le message',expandMessage: 'Développer le message',scrollToBottom: 'Défiler vers le bas',diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.tsindex 42e97a4fa8c..81102b814cf 100644--- a/apps/desktop/src/i18n/ja.ts+++ b/apps/desktop/src/i18n/ja.ts@@ -3830,6 +3830,8 @@ export const ja = defineLocale({preparingAudio: '音声を準備中...',stopReading: '読み上げを停止',readAloud: '読み上げ',+ copyFullResponse: '回答全体をコピー',+ readAloudFullResponseHint: 'Shiftを押しながらクリック: 回答全体を読み上げ',editMessage: 'メッセージを編集',stop: '停止',restorePrevious: '前のチェックポイントに戻す',diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.tsindex 3df1cd60a06..219bb01db42 100644--- a/apps/desktop/src/i18n/ru.ts+++ b/apps/desktop/src/i18n/ru.ts@@ -3950,6 +3950,8 @@ export const ru = defineLocale({preparingAudio: 'Подготовка аудио...',stopReading: 'Остановить чтение',readAloud: 'Зачитать вслух',+ copyFullResponse: 'Копировать весь ответ',+ readAloudFullResponseHint: 'Shift+клик: прочитать весь ответ',editMessage: 'Изменить сообщение',expandMessage: 'Развернуть сообщение',scrollToBottom: 'Прокрутить вниз',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 9c94b5c217f..589d5d3871a 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -4315,6 +4315,8 @@ export interface Translations {preparingAudio: stringstopReading: stringreadAloud: string+ copyFullResponse: string+ readAloudFullResponseHint: stringeditMessage: stringexpandMessage: stringscrollToBottom: stringdiff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.tsindex 793caf3f9db..08624d07b1e 100644--- a/apps/desktop/src/i18n/zh-hant.ts+++ b/apps/desktop/src/i18n/zh-hant.ts@@ -4000,6 +4000,8 @@ export const zhHant = defineLocale({preparingAudio: '正在準備音訊...',stopReading: '停止朗讀',readAloud: '朗讀',+ copyFullResponse: '複製完整回覆',+ readAloudFullResponseHint: '按住 Shift 點擊:朗讀完整回覆',editMessage: '編輯訊息',stop: '停止',restorePrevious: '還原至上一個檢查點',diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 38c630aec72..0b75a7e906a 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -4786,6 +4786,8 @@ export const zh = defineLocale({preparingAudio: '正在准备音频...',stopReading: '停止朗读',readAloud: '朗读',+ copyFullResponse: '复制完整回复',+ readAloudFullResponseHint: '按住 Shift 点击:朗读完整回复',editMessage: '编辑消息',expandMessage: '展开消息',scrollToBottom: '滚动到底部',