The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): wake-word toggle button in the composer
Hermes Agent8177457cd1a1
diff --git a/apps/desktop/src/app/chat/composer/controls.tsx b/apps/desktop/src/app/chat/composer/controls.tsxindex 996b962f544..647a7647ba5 100644--- a/apps/desktop/src/app/chat/composer/controls.tsx+++ b/apps/desktop/src/app/chat/composer/controls.tsx@@ -1,10 +1,13 @@+import { useStore } from '@nanostores/react'+import { Button } from '@/components/ui/button'import { Codicon } from '@/components/ui/codicon'import { Tip, TipKeybindLabel } from '@/components/ui/tooltip'import { useI18n } from '@/i18n'import { triggerHaptic } from '@/lib/haptics'-import { AudioLines, iconSize, Layers3, Loader2, Square, SteeringWheel, Volume2, VolumeX } from '@/lib/icons'+import { AudioLines, Ear, EarOff, iconSize, Layers3, Loader2, Square, SteeringWheel, Volume2, VolumeX } from '@/lib/icons'import { cn } from '@/lib/utils'+import { $wakeWord, toggleWakeWord } from '@/store/wake-word'import type { ConversationStatus } from './hooks/use-voice-conversation'import { ModelPill } from './model-pill'@@ -80,6 +83,7 @@ export function ComposerControls({<ModelPill compact={compactModelPill} disabled={disabled} model={state.model} /><DictationButton disabled={disabled} onToggle={onDictate} state={state.voice} status={voiceStatus} /><AutoSpeakButton active={autoSpeak} disabled={disabled} onToggle={onToggleAutoSpeak} />+ <WakeWordButton disabled={disabled} />{busyAction === 'steer' ? (<Tip label={<TipKeybindLabel actionId="composer.queue" text={c.queueMessage} />}><Button@@ -294,6 +298,49 @@ function AutoSpeakButton({ active, disabled, onToggle }: { active: boolean; disa)}+// "Hey Hermes" wake-word toggle. Three states: listening (accent-highlighted,+// like the auto-speak toggle above), off (muted ear-off), and unavailable —+// when the backend reports the wake word can't run, the button hides entirely+// so the row stays clean. Backend refusals ({started:false, reason}) keep the+// toggle off and surface the reason/hint in the tooltip.+function WakeWordButton({ disabled }: { disabled: boolean }) {+ const { t } = useI18n()+ const c = t.composer+ const wake = useStore($wakeWord)++ if (!wake.available) {+ return null+ }++ const phrase = wake.phrase || 'hey hermes'+ const label = wake.listening ? c.wakeWordListening(phrase) : c.wakeWordOff(phrase)+ const tooltip = wake.notice ? `${label} — ${wake.notice}` : label++ return (+ <Tip label={tooltip}>+ <Button+ aria-label={label}+ aria-pressed={wake.listening}+ className={cn(+ GHOST_ICON_BTN,+ 'p-0',+ wake.listening && 'bg-primary/10 text-primary hover:bg-primary/15 hover:text-primary'+ )}+ disabled={disabled || wake.pending}+ onClick={() => {+ triggerHaptic(wake.listening ? 'close' : 'open')+ void toggleWakeWord()+ }}+ size="icon"+ type="button"+ variant="ghost"+ >+ {wake.listening ? <Ear className={iconSize.sm} /> : <EarOff className={iconSize.sm} />}+ </Button>+ </Tip>+ )+}+function DictationButton({disabled,state,diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsxindex a8359290af2..3ba86e4741f 100644--- a/apps/desktop/src/app/contrib/wiring.tsx+++ b/apps/desktop/src/app/contrib/wiring.tsx@@ -55,6 +55,7 @@ import {setMessages} from '@/store/session'import { clearSessionTodos, setSessionTodos, todosForHydration } from '@/store/todos'+import { armWakeWord } from '@/store/wake-word'import { isSecondaryWindow } from '@/store/windows'import { useSkinCommand } from '@/themes/use-skin-command'@@ -701,7 +702,9 @@ export function ContribWiring({ children }: { children: ReactNode }) {useEffect(() => {if (gatewayState === 'open') {- void requestGateway('wake.start', { surface: 'gui' }).catch(() => undefined)+ // Status-then-arm, syncing $wakeWord so the composer toggle reflects the+ // same listener this auto-arm claims.+ void armWakeWord(requestGateway)}}, [gatewayState, requestGateway])diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 7e973fcc1b8..cb20d06c7bc 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -1958,6 +1958,8 @@ export const en: Translations = {voiceDictation: 'Voice dictation',speakReplies: 'Read replies aloud',stopSpeakingReplies: 'Stop reading replies aloud',+ wakeWordListening: phrase => `Wake word: "${phrase}" — listening`,+ wakeWordOff: phrase => `Wake word: "${phrase}" — off`,lookupLoading: 'Looking up…',lookupNoMatches: 'No matches.',lookupTry: 'Try',diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.tsindex 6ec6c487200..4f70f97e691 100644--- a/apps/desktop/src/i18n/ja.ts+++ b/apps/desktop/src/i18n/ja.ts@@ -1817,6 +1817,8 @@ export const ja = defineLocale({voiceDictation: '音声口述',speakReplies: '返信を読み上げる',stopSpeakingReplies: '返信の読み上げを停止',+ wakeWordListening: phrase => `ウェイクワード:「${phrase}」— 待機中`,+ wakeWordOff: phrase => `ウェイクワード:「${phrase}」— オフ`,lookupLoading: '検索中…',lookupNoMatches: '一致なし。',lookupTry: '試す',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 56ff50769e9..a1042ce7d88 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -1644,6 +1644,8 @@ export interface Translations {voiceDictation: stringspeakReplies: stringstopSpeakingReplies: string+ wakeWordListening: (phrase: string) => string+ wakeWordOff: (phrase: string) => stringlookupLoading: stringlookupNoMatches: stringlookupTry: stringdiff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.tsindex 10f85b9940e..c45f1cbeceb 100644--- a/apps/desktop/src/i18n/zh-hant.ts+++ b/apps/desktop/src/i18n/zh-hant.ts@@ -1760,6 +1760,8 @@ export const zhHant = defineLocale({voiceDictation: '語音聽寫',speakReplies: '朗讀回覆',stopSpeakingReplies: '停止朗讀回覆',+ wakeWordListening: phrase => `喚醒詞:「${phrase}」— 正在聆聽`,+ wakeWordOff: phrase => `喚醒詞:「${phrase}」— 已關閉`,lookupLoading: '查詢中…',lookupNoMatches: '沒有相符項目。',lookupTry: '試試',diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 1b692d40b1d..a5b48ed368a 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -2151,6 +2151,8 @@ export const zh: Translations = {voiceDictation: '语音听写',speakReplies: '朗读回复',stopSpeakingReplies: '停止朗读回复',+ wakeWordListening: phrase => `唤醒词:"${phrase}" — 正在监听`,+ wakeWordOff: phrase => `唤醒词:"${phrase}" — 已关闭`,lookupLoading: '查找中…',lookupNoMatches: '没有匹配项。',lookupTry: '试试',diff --git a/apps/desktop/src/lib/icons.ts b/apps/desktop/src/lib/icons.tsindex 35e6a92237d..bd5fc978bcf 100644--- a/apps/desktop/src/lib/icons.ts+++ b/apps/desktop/src/lib/icons.ts@@ -37,6 +37,8 @@ import {IconCpu as Cpu,IconCreditCard as CreditCard,IconDownload as Download,+ IconEar as Ear,+ IconEarOff as EarOff,IconEgg as Egg,IconExternalLink as ExternalLink,IconEye as Eye,@@ -160,6 +162,8 @@ export {Cpu,CreditCard,Download,+ Ear,+ EarOff,Egg,ExternalLink,Eye,diff --git a/apps/desktop/src/store/wake-word.test.ts b/apps/desktop/src/store/wake-word.test.tsnew file mode 100644index 00000000000..21a8f74b539--- /dev/null+++ b/apps/desktop/src/store/wake-word.test.ts@@ -0,0 +1,240 @@+import { beforeEach, describe, expect, it, vi } from 'vitest'++import {+ $wakeWord,+ applyWakeStartResult,+ applyWakeStatus,+ applyWakeStopResult,+ armWakeWord,+ resetWakeWordState,+ toggleWakeWord,+ type WakeRequester+} from './wake-word'++const requester = (impl: (method: string, params?: Record<string, unknown>) => unknown) =>+ vi.fn(async (method: string, params: Record<string, unknown> = {}) => impl(method, params)) as unknown as WakeRequester++beforeEach(() => {+ resetWakeWordState()+})++describe('applyWakeStatus', () => {+ it('syncs availability, listening and phrase from wake.status', () => {+ applyWakeStatus({+ available: true,+ hint: '',+ listening: true,+ owned_by_caller: true,+ owner_surface: 'gui',+ phrase: 'hey hermes',+ provider: 'openwakeword'+ })++ expect($wakeWord.get()).toMatchObject({+ available: true,+ listening: true,+ notice: '',+ phrase: 'hey hermes'+ })+ })++ it('keeps the button hidden and carries the hint when unavailable', () => {+ applyWakeStatus({ available: false, hint: 'pip install openwakeword', listening: false, phrase: 'hey hermes' })++ const state = $wakeWord.get()+ expect(state.available).toBe(false)+ expect(state.listening).toBe(false)+ expect(state.notice).toBe('pip install openwakeword')+ })+})++describe('toggleWakeWord', () => {+ it('starts via wake.start with surface gui when off, and flips to listening', async () => {+ applyWakeStatus({ available: true, listening: false, phrase: 'hey hermes' })++ const request = requester(method => {+ expect(method).toBe('wake.start')++ return { owner_surface: 'gui', phrase: 'hey hermes', provider: 'porcupine', started: true }+ })++ await toggleWakeWord(request)++ expect(request).toHaveBeenCalledWith('wake.start', { surface: 'gui' })+ expect($wakeWord.get()).toMatchObject({ listening: true, notice: '', pending: false })+ })++ it('stops via wake.stop when listening', async () => {+ applyWakeStatus({ available: true, listening: true, phrase: 'hey hermes' })++ const request = requester(method => {+ expect(method).toBe('wake.stop')++ return { reason: null, stopped: true }+ })++ await toggleWakeWord(request)++ expect(request).toHaveBeenCalledWith('wake.stop', {})+ expect($wakeWord.get()).toMatchObject({ listening: false, notice: '', pending: false })+ })++ it('does NOT flip state on {started:false, reason} and surfaces the reason', async () => {+ applyWakeStatus({ available: true, listening: false, phrase: 'hey hermes' })++ await toggleWakeWord(requester(() => ({ owner_surface: 'tui', reason: 'owned', started: false })))++ const state = $wakeWord.get()+ expect(state.listening).toBe(false)+ expect(state.notice).toBe('owned')+ expect(state.available).toBe(true)+ })++ it('marks the feature unavailable when start refuses with reason unavailable', async () => {+ applyWakeStatus({ available: true, listening: false, phrase: 'hey hermes' })++ await toggleWakeWord(+ requester(() => ({ hint: 'Set PORCUPINE_ACCESS_KEY', reason: 'unavailable', started: false }))+ )++ const state = $wakeWord.get()+ expect(state.available).toBe(false)+ expect(state.listening).toBe(false)+ expect(state.notice).toBe('Set PORCUPINE_ACCESS_KEY')+ })++ it('stays off and keeps the error as the notice when the RPC throws', async () => {+ applyWakeStatus({ available: true, listening: false, phrase: 'hey hermes' })++ await toggleWakeWord(+ requester(() => {+ throw new Error('Hermes gateway unavailable')+ })+ )++ expect($wakeWord.get()).toMatchObject({+ listening: false,+ notice: 'Hermes gateway unavailable',+ pending: false+ })+ })++ it('ignores clicks while a toggle is already in flight', async () => {+ applyWakeStatus({ available: true, listening: false, phrase: 'hey hermes' })++ let resolveStart: (value: unknown) => void = () => undefined++ const request = vi.fn(+ async () =>+ new Promise(resolve => {+ resolveStart = resolve+ })+ ) as unknown as WakeRequester++ const first = toggleWakeWord(request)+ await toggleWakeWord(request)++ expect(request).toHaveBeenCalledTimes(1)++ resolveStart({ phrase: 'hey hermes', started: true })+ await first++ expect($wakeWord.get().listening).toBe(true)+ })+})++describe('armWakeWord (gateway-ready auto-arm)', () => {+ it('queries wake.status then arms and syncs the store', async () => {+ const calls: string[] = []++ const request = requester(method => {+ calls.push(method)++ if (method === 'wake.status') {+ return { available: true, listening: false, phrase: 'hey hermes', provider: 'porcupine' }+ }++ return { phrase: 'hey hermes', started: true }+ })++ await armWakeWord(request)++ expect(calls).toEqual(['wake.status', 'wake.start'])+ expect($wakeWord.get()).toMatchObject({ available: true, listening: true, phrase: 'hey hermes' })+ })++ it('does not attempt to arm when the wake word is unavailable', async () => {+ const calls: string[] = []++ const request = requester(method => {+ calls.push(method)++ return { available: false, hint: 'no mic', listening: false, phrase: 'hey hermes' }+ })++ await armWakeWord(request)++ expect(calls).toEqual(['wake.status'])+ expect($wakeWord.get()).toMatchObject({ available: false, listening: false, notice: 'no mic' })+ })++ it('skips arming when this surface already listens (status sync only)', async () => {+ const calls: string[] = []++ const request = requester(method => {+ calls.push(method)++ return { available: true, listening: true, owned_by_caller: true, phrase: 'hey hermes' }+ })++ await armWakeWord(request)++ expect(calls).toEqual(['wake.status'])+ expect($wakeWord.get()).toMatchObject({ available: true, listening: true })+ })++ it('keeps the default hidden state when the backend lacks wake.* methods', async () => {+ await armWakeWord(+ requester(() => {+ throw new Error('Unknown method: wake.status')+ })+ )++ expect($wakeWord.get()).toMatchObject({ available: false, listening: false })+ })++ it('keeps the toggle off when auto-arm is refused (e.g. TUI owns the mic)', async () => {+ const request = requester(method =>+ method === 'wake.status'+ ? { available: true, listening: false, owner_surface: 'tui', phrase: 'hey hermes' }+ : { owner_surface: 'tui', reason: 'owned', started: false }+ )++ await armWakeWord(request)++ const state = $wakeWord.get()+ expect(state.available).toBe(true)+ expect(state.listening).toBe(false)+ expect(state.notice).toBe('owned')+ })+})++describe('applyWakeStopResult', () => {+ it('lands on off even when the backend says not_owner', () => {+ applyWakeStatus({ available: true, listening: true, phrase: 'hey hermes' })++ applyWakeStopResult({ reason: 'not_owner', stopped: false })++ const state = $wakeWord.get()+ expect(state.listening).toBe(false)+ expect(state.notice).toBe('not_owner')+ })+})++describe('applyWakeStartResult', () => {+ it('adopts the backend phrase when the listener starts', () => {+ applyWakeStartResult({ phrase: 'computer', provider: 'porcupine', started: true })++ expect($wakeWord.get()).toMatchObject({ available: true, listening: true, phrase: 'computer' })+ })+})diff --git a/apps/desktop/src/store/wake-word.ts b/apps/desktop/src/store/wake-word.tsnew file mode 100644index 00000000000..97f0c8b3c89--- /dev/null+++ b/apps/desktop/src/store/wake-word.ts@@ -0,0 +1,183 @@+import { atom } from 'nanostores'++import { $gateway } from '@/store/gateway'++// "Hey Hermes" wake-word listener state for the composer toggle. The gateway is+// the single source of truth (the listener lives in the backend and is shared+// with the TUI under a single-owner mic lease); this atom is the renderer's+// cache of that truth, refreshed from every wake.* RPC response we see.++export interface WakeWordState {+ /** Wake word can run at all (deps + mic + key). False hides the toggle. */+ available: boolean+ /** The listener is armed and owned by this surface. */+ listening: boolean+ /** Last failure reason/hint (start refused, unavailable, …) for the tooltip. */+ notice: string+ /** A toggle RPC is in flight — guards double-clicks. */+ pending: boolean+ /** Human-facing wake phrase, e.g. "hey hermes". */+ phrase: string+}++const INITIAL_WAKE_WORD_STATE: WakeWordState = {+ available: false,+ listening: false,+ notice: '',+ pending: false,+ phrase: ''+}++export const $wakeWord = atom<WakeWordState>(INITIAL_WAKE_WORD_STATE)++export interface WakeStatusResponse {+ available?: boolean+ hint?: string+ listening?: boolean+ owned_by_caller?: boolean+ owner_surface?: string | null+ phrase?: string+ provider?: string+}++export interface WakeStartResponse {+ hint?: string+ owner_surface?: string | null+ phrase?: string+ provider?: string+ reason?: string+ started?: boolean+}++export interface WakeStopResponse {+ reason?: string | null+ stopped?: boolean+}++/** Minimal requester shape — satisfied by both `useGatewayRequest`'s+ * `requestGateway` and the `$gateway` instance wrapper below. */+export type WakeRequester = <T>(method: string, params?: Record<string, unknown>) => Promise<T>++const gatewayRequester: WakeRequester = async <T>(method: string, params: Record<string, unknown> = {}) => {+ const gateway = $gateway.get()++ if (!gateway) {+ throw new Error('Hermes gateway unavailable')+ }++ return gateway.request<T>(method, params)+}++const noticeFrom = (result: { hint?: string; reason?: string | null } | null | undefined): string =>+ result?.hint?.trim() || result?.reason?.trim() || ''++/** Sync the atom from a `wake.status` payload (mount / gateway-ready). */+export function applyWakeStatus(status: WakeStatusResponse | null | undefined): void {+ const current = $wakeWord.get()+ const listening = Boolean(status?.listening)++ $wakeWord.set({+ ...current,+ available: Boolean(status?.available),+ listening,+ notice: listening ? '' : noticeFrom(status),+ phrase: status?.phrase?.trim() || current.phrase+ })+}++/** Sync the atom from a `wake.start` response. A `{started:false, reason}`+ * refusal keeps the toggle off and surfaces the reason as the tooltip. */+export function applyWakeStartResult(result: WakeStartResponse | null | undefined): void {+ const current = $wakeWord.get()++ if (result?.started) {+ $wakeWord.set({+ ...current,+ available: true,+ listening: true,+ notice: '',+ pending: false,+ phrase: result.phrase?.trim() || current.phrase+ })++ return+ }++ $wakeWord.set({+ ...current,+ // The backend probes requirements on start; an explicit "unavailable"+ // refusal means the feature can't run here, so hide the toggle.+ available: result?.reason === 'unavailable' ? false : current.available,+ listening: false,+ notice: noticeFrom(result),+ pending: false+ })+}++/** Sync the atom from a `wake.stop` response. `{stopped:false, reason:'not_owner'}`+ * still means WE are not listening, so the toggle lands on off either way. */+export function applyWakeStopResult(result: WakeStopResponse | null | undefined): void {+ const current = $wakeWord.get()++ $wakeWord.set({+ ...current,+ listening: false,+ notice: result?.stopped ? '' : noticeFrom(result),+ pending: false+ })+}++/**+ * Gateway-ready sync + auto-arm (wiring.tsx). Queries `wake.status` first so+ * the button knows availability/phrase even when arming is refused, then arms+ * the listener for this surface exactly like the historical auto-arm did.+ * Best-effort: a gateway without the wake.* methods leaves the atom at its+ * hidden default.+ */+export async function armWakeWord(request: WakeRequester = gatewayRequester): Promise<void> {+ try {+ const status = await request<WakeStatusResponse>('wake.status', {})+ applyWakeStatus(status)++ if (!status?.available || status.listening) {+ return+ }++ const result = await request<WakeStartResponse>('wake.start', { surface: 'gui' })+ applyWakeStartResult(result)+ } catch {+ // Older backends / transient failures — keep whatever we last knew.+ }+}++/** The composer button's click handler: stop when listening, start otherwise. */+export async function toggleWakeWord(request: WakeRequester = gatewayRequester): Promise<void> {+ const state = $wakeWord.get()++ if (state.pending) {+ return+ }++ $wakeWord.set({ ...state, pending: true })++ try {+ if (state.listening) {+ applyWakeStopResult(await request<WakeStopResponse>('wake.stop', {}))+ } else {+ applyWakeStartResult(await request<WakeStartResponse>('wake.start', { surface: 'gui' }))+ }+ } catch (error) {+ const current = $wakeWord.get()++ $wakeWord.set({+ ...current,+ notice: error instanceof Error ? error.message : String(error),+ pending: false+ })+ }+}++/** Test-only reset. */+export function resetWakeWordState(): void {+ $wakeWord.set(INITIAL_WAKE_WORD_STATE)+}