Skip to content

The agent that grows with you

fix(desktop): honour voice.stop_phrases in the spoken-stop matcher (#117801)

aydnOktay802a0cf6ffe0
diff --git a/apps/desktop/src/lib/voice-stop-word.test.ts b/apps/desktop/src/lib/voice-stop-word.test.ts
index abcd8029e74..517df48455c 100644
--- a/apps/desktop/src/lib/voice-stop-word.test.ts
+++ b/apps/desktop/src/lib/voice-stop-word.test.ts
@@ -5,7 +5,7 @@ import { interceptsTypedVoiceStop, isVoiceStopCommand } from './voice-stop-word'
describe('isVoiceStopCommand', () => {
it('matches bare stop commands', () => {
for (const phrase of ['stop', 'Stop', 'STOP', 'stop.', 'stop!', ' stop ', 'stop…']) {
- expect(isVoiceStopCommand(phrase)).toBe(true)
+ expect(isVoiceStopCommand(phrase, { mode: 'default' })).toBe(true)
}
})
@@ -25,13 +25,13 @@ describe('isVoiceStopCommand', () => {
'bye',
'cancel'
]) {
- expect(isVoiceStopCommand(phrase)).toBe(true)
+ expect(isVoiceStopCommand(phrase, { mode: 'default' })).toBe(true)
}
})
it('matches stop commands addressed to Hermes', () => {
for (const phrase of ['hermes stop', 'hey hermes stop', 'hey hermes, stop', 'ok stop', 'okay stop']) {
- expect(isVoiceStopCommand(phrase)).toBe(true)
+ expect(isVoiceStopCommand(phrase, { mode: 'default' })).toBe(true)
}
})
@@ -44,21 +44,37 @@ describe('isVoiceStopCommand', () => {
"don't stop now",
'the bus stop is closed'
]) {
- expect(isVoiceStopCommand(phrase)).toBe(false)
+ expect(isVoiceStopCommand(phrase, { mode: 'default' })).toBe(false)
}
})
it('does not match bare address words or empty input', () => {
for (const phrase of ['', ' ', 'hermes', 'hey hermes', 'ok', 'okay', 'hey']) {
- expect(isVoiceStopCommand(phrase)).toBe(false)
+ expect(isVoiceStopCommand(phrase, { mode: 'default' })).toBe(false)
}
})
it('does not match unrelated short utterances', () => {
for (const phrase of ['hello', 'yes', 'what time is it', 'thanks']) {
- expect(isVoiceStopCommand(phrase)).toBe(false)
+ expect(isVoiceStopCommand(phrase, { mode: 'default' })).toBe(false)
}
})
+
+ it('honours configured voice.stop_phrases in any language (#117801)', () => {
+ const config = { mode: 'custom' as const, phrases: ['отбой', 'стоп', 'stop'] }
+
+ expect(isVoiceStopCommand('отбой', config)).toBe(true)
+ expect(isVoiceStopCommand('Стоп!', config)).toBe(true)
+ expect(isVoiceStopCommand('hermes отбой', config)).toBe(true)
+ expect(isVoiceStopCommand('stop the docker container', config)).toBe(false)
+ // Built-in English extras are NOT active when the key is set.
+ expect(isVoiceStopCommand('goodbye', config)).toBe(false)
+ })
+
+ it('disables spoken stop when voice.stop_phrases is an empty list', () => {
+ expect(isVoiceStopCommand('stop', { mode: 'disabled' })).toBe(false)
+ expect(isVoiceStopCommand('отбой', { mode: 'disabled' })).toBe(false)
+ })
})
describe('interceptsTypedVoiceStop', () => {
diff --git a/apps/desktop/src/lib/voice-stop-word.ts b/apps/desktop/src/lib/voice-stop-word.ts
index 2ed2e3769aa..ae272046b88 100644
--- a/apps/desktop/src/lib/voice-stop-word.ts
+++ b/apps/desktop/src/lib/voice-stop-word.ts
@@ -11,9 +11,15 @@
// phrase (optionally addressed to Hermes), so a real turn that merely contains
// the word "stop" — e.g. "stop the docker container" or "how do I stop a
// running process" — is never swallowed.
+//
+// Config: when `voice.stop_phrases` is set, those phrases are matched (any
+// language). When the key is absent, the built-in English list below is used.
+// An explicit empty list disables spoken stop entirely — mirroring
+// `tools.voice_mode.is_voice_stop_phrase` (#117801).
+
+import { $voiceStopPhraseConfig, type VoiceStopPhraseConfig } from '@/store/voice-prefs'
-// Canonical stop commands. Kept short and unambiguous; each must be the entire
-// spoken utterance to match.
+// Canonical English stop commands used when `voice.stop_phrases` is unset.
const STOP_PHRASES: readonly string[] = [
'stop',
'stop listening',
@@ -63,16 +69,39 @@ function stripAddress(text: string): string {
return text
}
+function phrasesForConfig(config: VoiceStopPhraseConfig): readonly string[] | null {
+ if (config.mode === 'disabled') {
+ return null
+ }
+
+ if (config.mode === 'custom') {
+ return config.phrases.map(normalize).filter(phrase => phrase.length > 0)
+ }
+
+ return STOP_PHRASES
+}
+
/**
* True when the entire spoken utterance is a stop command (optionally addressed
* to Hermes). Returns false for anything that merely contains "stop" as part of
* a longer, substantive request.
+ *
+ * Pass `config` in tests; production reads `$voiceStopPhraseConfig`.
*/
-export function isVoiceStopCommand(transcript: string): boolean {
+export function isVoiceStopCommand(
+ transcript: string,
+ config: VoiceStopPhraseConfig = $voiceStopPhraseConfig.get()
+): boolean {
if (!transcript) {
return false
}
+ const phrases = phrasesForConfig(config)
+
+ if (phrases == null || phrases.length === 0) {
+ return false
+ }
+
const normalized = normalize(transcript)
if (!normalized) {
@@ -85,7 +114,7 @@ export function isVoiceStopCommand(transcript: string): boolean {
const candidates = new Set([normalized, stripAddress(normalized)])
for (const candidate of candidates) {
- if (STOP_PHRASES.includes(candidate)) {
+ if (phrases.includes(candidate)) {
return true
}
}
diff --git a/apps/desktop/src/store/voice-prefs.test.ts b/apps/desktop/src/store/voice-prefs.test.ts
index e59f3775b40..21db2320b91 100644
--- a/apps/desktop/src/store/voice-prefs.test.ts
+++ b/apps/desktop/src/store/voice-prefs.test.ts
@@ -7,7 +7,7 @@ vi.mock('@/hermes', () => ({
import { saveHermesConfig } from '@/hermes'
-import { $voiceStopPhrase, applyVoiceStopPhraseFromConfig } from './voice-prefs'
+import { $voiceStopPhrase, $voiceStopPhraseConfig, applyVoiceStopPhraseFromConfig } from './voice-prefs'
it('keeps the desktop toggle local across config refreshes', async () => {
for (const fails of [false, true]) {
@@ -70,28 +70,37 @@ describe('applyVoiceStopPhraseFromConfig', () => {
it('defaults to "stop" when the key is absent (backend default applies)', () => {
applyVoiceStopPhraseFromConfig({ voice: {} })
expect($voiceStopPhrase.get()).toBe('stop')
+ expect($voiceStopPhraseConfig.get()).toEqual({ mode: 'default' })
applyVoiceStopPhraseFromConfig(null)
expect($voiceStopPhrase.get()).toBe('stop')
+ expect($voiceStopPhraseConfig.get()).toEqual({ mode: 'default' })
})
it('uses the first configured phrase so a custom phrase renders correctly', () => {
applyVoiceStopPhraseFromConfig({ voice: { stop_phrases: ['goodbye hermes', 'stop'] } })
expect($voiceStopPhrase.get()).toBe('goodbye hermes')
+ expect($voiceStopPhraseConfig.get()).toEqual({
+ mode: 'custom',
+ phrases: ['goodbye hermes', 'stop']
+ })
})
it('coerces a bare string like the backend does', () => {
applyVoiceStopPhraseFromConfig({ voice: { stop_phrases: 'halt' } })
expect($voiceStopPhrase.get()).toBe('halt')
+ expect($voiceStopPhraseConfig.get()).toEqual({ mode: 'custom', phrases: ['halt'] })
})
it('null phrase when stop phrases are disabled — no notice is shown', () => {
applyVoiceStopPhraseFromConfig({ voice: { stop_phrases: [] } })
expect($voiceStopPhrase.get()).toBeNull()
+ expect($voiceStopPhraseConfig.get()).toEqual({ mode: 'disabled' })
})
it('malformed entries are skipped; all-blank list disables', () => {
applyVoiceStopPhraseFromConfig({ voice: { stop_phrases: [' ', ''] } })
expect($voiceStopPhrase.get()).toBeNull()
+ expect($voiceStopPhraseConfig.get()).toEqual({ mode: 'disabled' })
})
})
diff --git a/apps/desktop/src/store/voice-prefs.ts b/apps/desktop/src/store/voice-prefs.ts
index 00a412c4b69..960ab310f22 100644
--- a/apps/desktop/src/store/voice-prefs.ts
+++ b/apps/desktop/src/store/voice-prefs.ts
@@ -21,23 +21,35 @@ export function applyAutoSpeakFromConfig(config: { voice?: { auto_tts?: unknown
// Defaults to "stop" (the backend default) before config loads.
export const $voiceStopPhrase = atom<string | null>('stop')
-/** Seed the stop-phrase atom from a loaded config payload (mount / refresh). */
+/** How the desktop matcher should treat `voice.stop_phrases` (#117801). */
+export type VoiceStopPhraseConfig =
+ | { mode: 'default' }
+ | { mode: 'custom'; phrases: readonly string[] }
+ | { mode: 'disabled' }
+
+// Full matcher config — kept in sync with `$voiceStopPhrase` so the spoken
+// stop recognizer honours the same list the notice advertises.
+export const $voiceStopPhraseConfig = atom<VoiceStopPhraseConfig>({ mode: 'default' })
+
+/** Seed the stop-phrase atoms from a loaded config payload (mount / refresh). */
export function applyVoiceStopPhraseFromConfig(
config: { voice?: { stop_phrases?: unknown } | null } | null | undefined
) {
const raw = config?.voice?.stop_phrases
if (raw === undefined) {
- // Key absent — backend default applies.
+ // Key absent — backend default + built-in English matcher list.
$voiceStopPhrase.set('stop')
+ $voiceStopPhraseConfig.set({ mode: 'default' })
return
}
const list = Array.isArray(raw) ? raw : typeof raw === 'string' ? [raw] : []
- const first = list.map(entry => String(entry).trim()).find(entry => entry.length > 0)
+ const phrases = list.map(entry => String(entry).trim()).filter(entry => entry.length > 0)
- $voiceStopPhrase.set(first ?? null)
+ $voiceStopPhrase.set(phrases[0] ?? null)
+ $voiceStopPhraseConfig.set(phrases.length > 0 ? { mode: 'custom', phrases } : { mode: 'disabled' })
}
// `voice.thinking_sound` — ambient bubble blips while the agent works during a