Skip to content

The agent that grows with you

feat(desktop): full back-and-forth voice on "Hey Hermes" wake

Brooklyn Nicholson8a4d58287e48
diff --git a/apps/desktop/src/app/chat/composer/focus.ts b/apps/desktop/src/app/chat/composer/focus.ts
index 7120fde2b1a..3ddc096156c 100644
--- a/apps/desktop/src/app/chat/composer/focus.ts
+++ b/apps/desktop/src/app/chat/composer/focus.ts
@@ -42,6 +42,7 @@ const INSERT_EVENT = 'hermes:composer-insert'
const INSERT_REFS_EVENT = 'hermes:composer-insert-refs'
const SUBMIT_EVENT = 'hermes:composer-submit'
const VOICE_TOGGLE_EVENT = 'hermes:composer-voice-toggle'
+const VOICE_START_EVENT = 'hermes:composer-voice-start'
interface SubmitDetail {
target: ComposerTarget
@@ -150,6 +151,14 @@ export const requestVoiceToggle = (target: ComposerTarget | 'active' = 'active')
export const onComposerVoiceToggleRequest = (handler: (target: ComposerTarget) => void) =>
subscribe<{ target: ComposerTarget }>(VOICE_TOGGLE_EVENT, ({ target }) => handler(target))
+/** Explicitly START (never stop) the active composer's voice conversation —
+ * used by the "Hey Hermes" wake word so a fresh session begins back-and-forth
+ * voice without the toggle risking an immediate stop. */
+export const requestVoiceStart = () => dispatch<{ at: number }>(VOICE_START_EVENT, { at: Date.now() })
+
+export const onComposerVoiceStartRequest = (handler: () => void) =>
+ subscribe<{ at: number }>(VOICE_START_EVENT, () => handler())
+
/**
* Focus a composer input across React commit + browser focus restore.
*
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.ts
index 8e53096f322..5817c502ca0 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-voice.ts
@@ -4,11 +4,12 @@ import { useI18n } from '@/i18n'
import { chatMessageText, collectUnspokenTurnSpeech } from '@/lib/chat-messages'
import { triggerHaptic } from '@/lib/haptics'
import { resetBrowseState } from '@/store/composer-input-history'
+import { $gateway } from '@/store/gateway'
import { notifyError } from '@/store/notifications'
import { $autoSpeakReplies, setAutoSpeakReplies } from '@/store/voice-prefs'
import type { ComposerTarget } from '../focus'
-import { onComposerVoiceToggleRequest } from '../focus'
+import { onComposerVoiceStartRequest, onComposerVoiceToggleRequest } from '../focus'
import { useComposerScope } from '../scope'
import type { ChatBarProps } from '../types'
@@ -142,6 +143,34 @@ export function useComposerVoice({
[target, toggleVoiceConversation]
)
+ useEffect(
+ () =>
+ onComposerVoiceStartRequest(() => {
+ if (target === 'main' && !disabled && !voiceConversationActive) {
+ setVoiceConversationActive(true)
+ }
+ }),
+ [disabled, target, voiceConversationActive]
+ )
+
+ const wakePausedRef = useRef(false)
+
+ useEffect(() => {
+ const gateway = $gateway.get()
+
+ if (!gateway) {
+ return
+ }
+
+ if (voiceConversationActive) {
+ wakePausedRef.current = true
+ void gateway.request('wake.pause', {}).catch(() => undefined)
+ } else if (wakePausedRef.current) {
+ wakePausedRef.current = false
+ void gateway.request('wake.resume', {}).catch(() => undefined)
+ }
+ }, [voiceConversationActive])
+
// Explicit start/end for the on-screen conversation controls (the hotkey uses
// the gated toggle above).
const startConversation = useCallback(() => setVoiceConversationActive(true), [])
diff --git a/apps/desktop/src/app/desktop-controller.tsx b/apps/desktop/src/app/desktop-controller.tsx
index 6623636f187..08e27c0cf22 100644
--- a/apps/desktop/src/app/desktop-controller.tsx
+++ b/apps/desktop/src/app/desktop-controller.tsx
@@ -105,7 +105,7 @@ import { openUpdatesWindow, startUpdatePoller, stopUpdatePoller } from '../store
import { isSecondaryWindow } from '../store/windows'
import { ChatView } from './chat'
-import { requestComposerFocus, requestComposerInsert } from './chat/composer/focus'
+import { requestComposerFocus, requestComposerInsert, requestVoiceStart } from './chat/composer/focus'
import { useComposerActions } from './chat/hooks/use-composer-actions'
import {
ChatPreviewRail,
@@ -1018,7 +1018,12 @@ export function DesktopController() {
if (!gw) {
return
}
- return gw.on('wake.detected', () => startFreshSessionDraft())
+ return gw.on('wake.detected', () => {
+ startFreshSessionDraft()
+ // Begin hands-free back-and-forth voice in the fresh session. The bus
+ // defers a tick, so the new composer is mounted before voice starts.
+ requestVoiceStart()
+ })
}, [gatewayState, requestGateway, gatewayRef, startFreshSessionDraft])
// Keep the cron jobs section live without a user action: the scheduler ticks