feat(desktop): add read-aloud playback for agent chat messages

Let a user explicitly play/stop a delivered agent response from the
message action bar, reusing the local Pocket TTS stack while keeping
read-aloud fully independent from huddle orchestration.

Backend (src-tauri):
- New app-scoped message_tts module with its own TtsPipeline instance
  and fresh active/cancel flags — zero STT/barge-in/huddle-phase
  coupling. Commands: speak_chat_message / stop_chat_message_speech.
- Message-keyed lifecycle (preparing/playing/completed/stopped/
  superseded/failed) emitted as message-tts-state-changed events.
  Generation tokens guarantee stale watcher completions can never
  overwrite a newer request; one playback app-wide, newer play
  supersedes older.
- Huddle exclusion both ways: speak refuses while huddle phase is not
  Idle, and start/join_huddle stop any message playback before taking
  the audio device.
- Long-message limit mirrors the huddle cap (2000 chars, char-counted)
  with a spoken suffix and a truncated flag so the cut is disclosed,
  not silent. Missing voice model kicks off the download and surfaces
  a retryable error. No persisted audio cache.

Frontend (desktop/src):
- MessageTtsProvider (mounted in AppShell inside HuddleProvider) folds
  backend events through a pure reducer (playbackReducer.mjs) so stale
  terminal events for superseded messages can't clear newer playback.
  Errors surface as toasts + per-message state; truncation is disclosed
  via toast at playback start.
- ReadAloudButton in MessageActionBar for delivered agent text only
  (isAgent, not pending, has body), with aria-label/aria-pressed,
  tooltip, and disabled-with-reason during active huddles.

Tests: 16 Rust unit tests (truncation UTF-8 safety, supersede/stop
races, concurrent stops, event payload shape) and 13 node:test reducer
tests (out-of-order supersede delivery, detached errors, rapid
play/stop). Full suites green: cargo test (1576), pnpm test (3414),
typecheck, biome + file-size checks, desktop build.

Co-authored-by: Taylor Ho <taylorkmho@gmail.com>
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w
2026-07-27 15:30:01 -07:00
committed by npub14vtk7pvazqrq9639qu7e560wnqtl0d53ca4gjuvq6jzf3k2el23qqlwa7f
parent 8ac609c73f
commit df543aeb99
12 changed files with 1181 additions and 5 deletions

View File

@@ -482,10 +482,12 @@ const overrides = new Map([
// transition lock doc broadened to cover all protected-PID transitions, and
// clear_agent_session_caches (per-pubkey retain) added alongside the
// per-key clear. Load-bearing identity-contract change; queued to split.
// +4 (1081 -> 1085): mesh recovery keeps one app-scoped state object beside
// the embedded runtime and coordinator. Probe/re-arm logic lives in
// mesh_llm/recovery.rs rather than growing AppState or command modules.
["src-tauri/src/app_state.rs", 1085],
// +8 (1081 -> 1089): app-scoped mesh recovery and message read-aloud state
// remain as thin fields; their implementations live in dedicated modules.
["src-tauri/src/app_state.rs", 1089],
// +8 (994 -> 1002): message read-aloud mounts one app-scoped provider around
// the routed surface so all message rows share playback state and huddle gating.
["src/app/AppShell.tsx", 1002],
// multi-slot splitting + no-op suppression (#1309): the ReadStateManager
// class grew from ~700 lines to ~1019 with the addition of
// splitContextsIntoBudgetedSlots (pure fn + 5 tests), publishSplitSlots,