Skip to content

The agent that grows with you

fix(tui): run Ink /voice on|off|status on the owner's per-session voice mode

Tekniumb66c23360ef9
diff --git a/gateway/session_config.py b/gateway/session_config.py
index 83507c60408..24b98f1f0e2 100644
--- a/gateway/session_config.py
+++ b/gateway/session_config.py
@@ -59,6 +59,8 @@ async def config_get(connection, ref, params):
policy = _authorize(connection, ref, params)
if 'cwd' in params and (key != 'project' or not isinstance(params['cwd'], str)):
raise RuntimeStoreError('invalid_params')
+ if key == 'voice':
+ return _voice(connection, ref)
agent = connection.authority.agent(ref) if ref.session_id else None
def read():
@@ -99,6 +101,36 @@ async def config_get(connection, ref, params):
return await asyncio.to_thread(read)
+def session_voice_mode(connection, ref):
+ """``off`` / ``voice_only`` / ``all``: the session's ``/voice`` mode as the messaging handler stored it."""
+ runner, live = connection.authority.runner, connection.authority.sessions[ref.session_id]
+ modes = getattr(runner, '_voice_mode', None) or {}
+ return modes.get(runner._voice_key_for_source(live.source), 'off')
+
+
+def local_voice_enabled(session_id):
+ """True/False for a local session the running owner holds (its gateway ``/voice`` mode), else
+ None (no owner in this process, or not one of its sessions: the sidecar's env flag applies)."""
+ from gateway.run_api import _ACTIVE_RUNNER
+ from gateway.session_authorities import all_authorities
+ if _ACTIVE_RUNNER is None or not isinstance(session_id, str) or not session_id:
+ return None
+ for authority in all_authorities(_ACTIVE_RUNNER):
+ live = getattr(authority, 'sessions', {}).get(session_id)
+ if live is not None:
+ modes = getattr(_ACTIVE_RUNNER, '_voice_mode', None) or {}
+ return modes.get(_ACTIVE_RUNNER._voice_key_for_source(live.source), 'off') != 'off'
+ return None
+
+
+def _voice(connection, ref):
+ """The session's own ``/voice`` mode, so Ink mirrors the gateway's per-session state instead of
+ the sidecar's process-global ``HERMES_VOICE`` (T9)."""
+ if not ref.session_id:
+ raise RuntimeStoreError('invalid_params')
+ return {'value': session_voice_mode(connection, ref)}
+
+
def _fast(connection, ref, policy, agent, cfg):
from agent.fast_mode import parse_service_tier
if ref.session_id: # the session's next-turn tier: its /fast pin, else its policy's
diff --git a/tests/gateway/test_session_tui_ops.py b/tests/gateway/test_session_tui_ops.py
index c18511166f8..66fa0832876 100644
--- a/tests/gateway/test_session_tui_ops.py
+++ b/tests/gateway/test_session_tui_ops.py
@@ -230,3 +230,44 @@ def test_rollback_restore_reads_a_null_all_as_omitted(tmp_path):
asyncio.run(probe())
kept = (['mine.txt'], 'hand edit\n')
assert out == {'omitted': kept, 'null': kept, 'false': kept, 'true': (None, 'original mine\n')}, out
+
+
+def test_config_get_voice_reports_the_sessions_own_voice_mode(tmp_path):
+ """T9: Ink's /voice runs the owner's per-session handler (slash.exec) and reads the mode back
+ with ``config.get key=voice``; the sidecar's process-global HERMES_VOICE is never consulted."""
+ with owner(tmp_path) as (home, _peer, desc):
+ async def probe():
+ async with websocket(home, desc) as ws:
+ sid = (await rpc(ws, 'session.create', request_id='voice', source='tui', toolsets=[]))['result']['session_id']
+ other = (await rpc(ws, 'session.create', request_id='voice2', source='tui', toolsets=[]))['result']['session_id']
+ assert (await rpc(ws, 'config.get', key='voice', session_id=sid))['result']['value'] == 'off'
+ on = await rpc(ws, 'slash.exec', command='voice on', session_id=sid)
+ assert on['result']['type'] == 'exec', on
+ assert (await rpc(ws, 'config.get', key='voice', session_id=sid))['result']['value'] == 'voice_only'
+ assert (await rpc(ws, 'config.get', key='voice', session_id=other))['result']['value'] == 'off'
+ await rpc(ws, 'slash.exec', command='voice off', session_id=sid)
+ assert (await rpc(ws, 'config.get', key='voice', session_id=sid))['result']['value'] == 'off'
+ assert (await rpc(ws, 'config.get', key='voice'))['error']['message'] == 'invalid_params'
+ asyncio.run(probe())
+
+
+def test_voice_record_follows_the_sessions_gateway_voice_mode(tmp_path):
+ """T9: push-to-talk (``voice.record``) gates on the session's gateway voice mode, the state
+ Ink's ``/voice on`` sets through slash.exec, not the sidecar's process-global HERMES_VOICE."""
+ with owner(tmp_path) as (home, _peer, desc):
+ async def probe():
+ async with websocket(home, desc) as ws:
+ sid = (await rpc(ws, 'session.create', request_id='rec', source='tui', toolsets=[]))['result']['session_id']
+ off = await rpc(ws, 'voice.record', action='start', session_id=sid)
+ assert off.get('error', {}).get('code') == 4015, off
+ await rpc(ws, 'slash.exec', command='voice on', session_id=sid)
+ on = await rpc(ws, 'voice.record', action='start', session_id=sid)
+ # No microphone in CI: any answer but "voice mode is off" proves the gate passed.
+ assert on.get('error', {}).get('code') != 4015, on
+ await rpc(ws, 'voice.record', action='stop', session_id=sid)
+ await rpc(ws, 'slash.exec', command='voice off', session_id=sid)
+ again = await rpc(ws, 'voice.record', action='start', session_id=sid)
+ assert again.get('error', {}).get('code') == 4015, again
+ asyncio.run(probe())
diff --git a/tui_gateway/methods_voice.py b/tui_gateway/methods_voice.py
index b83e278e045..978beb6f094 100644
--- a/tui_gateway/methods_voice.py
+++ b/tui_gateway/methods_voice.py
@@ -52,6 +52,17 @@ def _voice_mode_enabled() -> bool:
return os.environ.get("HERMES_VOICE", "").strip() == "1"
+def _session_voice_enabled(session_id) -> bool:
+ """Push-to-talk gate: a shared-owner local session's own gateway ``/voice`` mode (what Ink's
+ ``/voice on`` sets through slash.exec, T9); the sidecar's env flag for its own sessions."""
+ try:
+ from gateway.session_config import local_voice_enabled
+ held = local_voice_enabled(session_id)
+ except ImportError:
+ held = None
+ return _voice_mode_enabled() if held is None else held
+
+
def _voice_tts_enabled() -> bool:
return os.environ.get("HERMES_VOICE_TTS", "").strip() == "1"
@@ -733,7 +744,7 @@ def _(rid, params: dict) -> dict:
return _ok(rid, {"status": "busy", "reason": "wake_owned"})
try:
global _voice_event_sid, _voice_event_transport, _voice_wake_owner
- if action == "start" and not _voice_mode_enabled():
+ if action == "start" and not _session_voice_enabled(params.get("session_id")):
return _err(rid, 4015, "voice mode is off — enable with /voice on")
with _voice_sid_lock:
_voice_event_sid = params.get("session_id") or _voice_event_sid
diff --git a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
index 1b7e6145c9c..5c685477405 100644
--- a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
+++ b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
@@ -12,6 +12,8 @@ const flush = () => new Promise(resolve => setImmediate(resolve))
const LEGACY = ['session.title', 'session.undo', 'session.usage', 'slash.exec', 'tools.configure']
function harness() {
+ let voiceMode = 'off'
+
const messages = [
{ role: 'user', content: 'first', row_id: 11 },
{ role: 'assistant', content: 'a1', row_id: 12 },
@@ -65,6 +67,16 @@ function harness() {
}
}
+ if (method === 'slash.exec' && /^voice( |$)/.test(params.command)) {
+ voiceMode = params.command === 'voice on' ? 'voice_only' : params.command === 'voice off' ? 'off' : voiceMode
+
+ return { type: 'exec', output: `voice: ${voiceMode}` }
+ }
+
+ if (method === 'config.get' && params.key === 'voice') {
+ return { value: voiceMode }
+ }
+
if (method === 'config.get') {
return { value: params.key === 'skin' ? 'default' : 'auto' }
}
@@ -89,7 +101,10 @@ function harness() {
const panel = vi.fn()
const page = vi.fn()
+ const voice = { setVoiceEnabled: vi.fn(), setVoiceRecordKey: vi.fn(), setVoiceTts: vi.fn() }
+
const ctx = {
+ voice,
slashFlightRef: { current: 0 },
gateway: { gw: { isCanonical: true, request }, rpc: request },
transcript: { page, panel, send, sys, setHistoryItems: vi.fn(), trimLastExchange: (items: unknown[]) => items },
@@ -98,9 +113,34 @@ function harness() {
composer: { enqueue: vi.fn() }
}
- return { page, panel, request, send, slash: createSlashHandler(ctx as any), sys }
+ return { page, panel, request, send, slash: createSlashHandler(ctx as any), sys, voice }
}
+it('/voice on|off|status run on the owner and mirror its per-session voice mode, never voice.toggle (T9)', async () => {
+ const { request, slash, sys, voice } = harness()
+
+ slash('/voice on')
+ await flush()
+ await flush()
+ expect(request).toHaveBeenCalledWith('slash.exec', { command: 'voice on', session_id: 'owner' })
+ expect(request).toHaveBeenCalledWith('config.get', { key: 'voice', session_id: 'owner' })
+ expect(voice.setVoiceEnabled).toHaveBeenLastCalledWith(true)
+ expect(voice.setVoiceTts).toHaveBeenLastCalledWith(false)
+
+ slash('/voice status')
+ await flush()
+ await flush()
+ expect(voice.setVoiceEnabled).toHaveBeenLastCalledWith(true)
+
+ slash('/voice off')
+ await flush()
+ await flush()
+ expect(voice.setVoiceEnabled).toHaveBeenLastCalledWith(false)
+
+ expect(request.mock.calls.some(([method]) => method === 'voice.toggle')).toBe(false)
+ expect(sys.mock.calls.map(([text]) => String(text))).toContain('voice: voice_only')
+})
+
beforeEach(() => {
resetUiState()
patchUiState({ sid: 'owner', info: { model: 'm', skills: {}, tools: {}, execution_epoch: '1', execution_generation: 3 } as any })
diff --git a/ui-tui/src/__tests__/useConfigSync.test.ts b/ui-tui/src/__tests__/useConfigSync.test.ts
index df77fea0301..49a14e4e3e0 100644
--- a/ui-tui/src/__tests__/useConfigSync.test.ts
+++ b/ui-tui/src/__tests__/useConfigSync.test.ts
@@ -549,3 +549,19 @@ describe('hydrateFullConfig', () => {
expect(setBell).toHaveBeenCalledWith(true)
})
})
+
+describe('hydrateVoiceMode (T9)', () => {
+ it("seeds the voice bit from the session's gateway /voice mode on the shared owner", async () => {
+ const request = vi.fn(async () => ({ value: 'voice_only' }))
+ const setVoiceEnabled = vi.fn()
+ const { hydrateVoiceMode } = await import('../app/useConfigSync.js')
+
+ await hydrateVoiceMode({ isCanonical: true, request } as never, setVoiceEnabled, { isCurrent: () => true, sid: 's1' })
+ expect(request).toHaveBeenCalledWith('config.get', { key: 'voice', session_id: 's1' })
+ expect(setVoiceEnabled).toHaveBeenCalledWith(true)
+
+ request.mockClear()
+ await hydrateVoiceMode({ isCanonical: false, request } as never, setVoiceEnabled, { isCurrent: () => true, sid: 's1' })
+ expect(request).not.toHaveBeenCalled()
+ })
+})
diff --git a/ui-tui/src/app/slash/commands/session.ts b/ui-tui/src/app/slash/commands/session.ts
index d197f203d3f..19972c0dc9e 100644
--- a/ui-tui/src/app/slash/commands/session.ts
+++ b/ui-tui/src/app/slash/commands/session.ts
@@ -400,6 +400,41 @@ export const sessionCommands: SlashCommand[] = [
return ctx.transcript.sys(t('canonical.controls.notAvailable', 'voice tts'))
}
+ // T9: the shared owner holds a session's voice mode (its /voice handler, per session). The
+ // sidecar's voice.toggle flipped the owner's process-global HERMES_VOICE for every chat; run
+ // the owner's handler instead and mirror the mode it reports back.
+ if (ctx.gateway.gw?.isCanonical && ctx.sid) {
+ const sid = ctx.sid
+ const command = normalized === 'on' || normalized === 'off' ? `voice ${normalized}` : 'voice status'
+
+ return void ctx.gateway.gw
+ .request<SlashExecResponse>('slash.exec', { command, session_id: sid })
+ .then(r => {
+ if (ctx.stale()) {
+ return
+ }
+
+ const text = r?.output?.trim()
+
+ if (text) {
+ ctx.transcript.sys(text)
+ }
+
+ return ctx.gateway.rpc<ConfigGetValueResponse>('config.get', { key: 'voice', session_id: sid })
+ })
+ .then(r => {
+ if (!r || ctx.stale()) {
+ return
+ }
+
+ // Local sessions refuse `/voice tts` (the owner never speaks a TUI reply), so speech
+ // output stays off; the mic mode follows the gateway's per-session state.
+ ctx.voice.setVoiceEnabled(r.value === 'voice_only' || r.value === 'all')
+ ctx.voice.setVoiceTts(false)
+ })
+ .catch(ctx.guardedErr)
+ }
+
ctx.gateway.rpc<VoiceToggleResponse>('voice.toggle', { action }).then(
ctx.guarded<VoiceToggleResponse>(r => {
ctx.voice.setVoiceEnabled(!!r.enabled)
diff --git a/ui-tui/src/app/useConfigSync.ts b/ui-tui/src/app/useConfigSync.ts
index efa758d4913..f9ae2eed842 100644
--- a/ui-tui/src/app/useConfigSync.ts
+++ b/ui-tui/src/app/useConfigSync.ts
@@ -339,6 +339,24 @@ export const applyDisplay = (
})
}
+/** T9: on the shared owner the voice bit is the session's gateway `/voice` mode (`config.get
+ * key=voice`), not the owner process's HERMES_VOICE env, which Ink's own env never reflected. */
+export const hydrateVoiceMode = async (
+ gw: GatewayClient,
+ setVoiceEnabled: (v: boolean) => void,
+ scope: { isCurrent: () => boolean; sid: string }
+) => {
+ if (!gw.isCanonical) {
+ return
+ }
+
+ const r = await quietRpc<{ value?: string }>(gw, 'config.get', { key: 'voice', session_id: scope.sid })
+
+ if (r && scope.isCurrent()) {
+ setVoiceEnabled(r.value === 'voice_only' || r.value === 'all')
+ }
+}
+
export function useConfigSync({
gw,
setBellOnComplete,
@@ -363,6 +381,7 @@ export function useConfigSync({
// Environment flags are enough to initialize the UI bit; the heavier status
// check still runs when the user opens /voice.
setVoiceEnabled(process.env.HERMES_VOICE === '1')
+ void hydrateVoiceMode(gw, setVoiceEnabled, scope)
quietRpc<ConfigMtimeResponse>(gw, 'config.get', { key: 'mtime', session_id: sid }).then(r => {
if (!scope.isCurrent()) {return}
mtimeRef.current = Number(r?.mtime ?? 0)
diff --git a/website/docs/developer-guide/gateway-command-parity.md b/website/docs/developer-guide/gateway-command-parity.md
index 59891960ca2..91713eb1ccc 100644
--- a/website/docs/developer-guide/gateway-command-parity.md
+++ b/website/docs/developer-guide/gateway-command-parity.md
@@ -128,7 +128,7 @@ handler does; `client-local (cli_only)` commands are terminal/UI features of a c
| `/usage` | read (bare only (`reset` refused)) | HermesCLI._handle_usage_command | canonical route | slash.exec | slash.exec | |
| `/verbose` | control | HermesCLI._toggle_verbose | config.set | unavailable: terminal | slash.exec | per-session setting (gateway handler) |
| `/version` (/v) | read | HermesCLI._cmd_version | slash.exec | slash.exec | slash.exec | |
-| `/voice` | control | HermesCLI._handle_voice_command | sidecar: voice.toggle; `tts` refused | unavailable: composer-voice | slash.exec | per-session setting (gateway handler) |
+| `/voice` | control | HermesCLI._handle_voice_command | config.get, slash.exec; sidecar: voice.toggle; `tts` refused | unavailable: composer-voice | slash.exec | per-session setting (gateway handler) |
| `/wake` | refused | HermesCLI._handle_wake_command | local | action: wake | slash.exec: refused | client-local (cli_only) |
| `/whoami` | read | HermesCLI._handle_whoami_command | slash.exec | slash.exec | slash.exec | |
| `/worktree` | refused | HermesCLI._handle_worktree_command | slash.exec: refused | slash.exec: refused | slash.exec: refused | client-local (cli_only) |