Capture settled assistant text from the session event feed #5

Closed
opened 2026-10-25 14:57:52 +00:00 by dsh · 1 comment
Owner

Goal

The core hook: when an assistant turn settles, hand its plain text to the speech pipeline — exactly once, never for history, never for thinking/tool content.

Scope

  • In lib/client.js, a capture module. Do not borrow a session: const ref = ctx.sessions.retain(sessionId, { source: 'whaleNoises' }); a plain binding(id) is nullable and only exists while another consumer holds the generation. Release with ref.release() on dispose.
  • ref.binding.eventSource.subscribe(handler); inspect getSnapshot().change — process only kind === 'append' entries (replace/prepend are history replay; settle-assistant may carry the durable message and must not double-fire).
  • Durable assistant/message with surfaceOp === 'append' → emit { messageId, text, interrupted, turn, step }; join only text blocks; skip reasoning/tool blocks; honour interrupted.
  • Never emit from the initial window snapshot. Deduplicate by message.id across re-renders/settlement.
  • Session switch / new session / dispose must add and remove retained references cleanly (no leak, no double-speak).
  • Unit tests: fake event source driven with a realistic entry sequence; assert one emission per settled message, none for reasoning-only, none for replayed windows.
  • Debug switch (localStorage.dsh-whale-noises.debug=1) logs the emitted text length, not the text (privacy).

Acceptance

  • On a real completed turn the console shows one capture event with the visible reply text and no code/reasoning.
  • Reloading a session with history does not speak.
  • Switching sessions mid-turn still captures the settling turn.

Notes

  • Shapes verified in docs/research/dsh-plugin-api.md §4 (SessionReference, change.kind, assistant/message, StreamChunk deltas). See AGENTS.md "Text capture".
  • Depends on #1. Part of M1.
## Goal The core hook: when an assistant turn settles, hand its plain text to the speech pipeline — exactly once, never for history, never for thinking/tool content. ## Scope - [ ] In `lib/client.js`, a `capture` module. Do **not** borrow a session: `const ref = ctx.sessions.retain(sessionId, { source: 'whaleNoises' })`; a plain `binding(id)` is nullable and only exists while another consumer holds the generation. Release with `ref.release()` on dispose. - [ ] `ref.binding.eventSource.subscribe(handler)`; inspect `getSnapshot().change` — process only `kind === 'append'` entries (`replace`/`prepend` are history replay; `settle-assistant` may carry the durable message and must not double-fire). - [ ] Durable `assistant/message` with `surfaceOp === 'append'` → emit `{ messageId, text, interrupted, turn, step }`; join only `text` blocks; skip `reasoning`/tool blocks; honour `interrupted`. - [ ] Never emit from the initial window snapshot. Deduplicate by `message.id` across re-renders/settlement. - [ ] Session switch / new session / dispose must add and remove retained references cleanly (no leak, no double-speak). - [ ] Unit tests: fake event source driven with a realistic entry sequence; assert one emission per settled message, none for reasoning-only, none for replayed windows. - [ ] Debug switch (`localStorage.dsh-whale-noises.debug=1`) logs the emitted text length, not the text (privacy). ## Acceptance - On a real completed turn the console shows one capture event with the visible reply text and no code/reasoning. - Reloading a session with history does not speak. - Switching sessions mid-turn still captures the settling turn. ## Notes - Shapes verified in `docs/research/dsh-plugin-api.md` §4 (`SessionReference`, `change.kind`, `assistant/message`, `StreamChunk` deltas). See AGENTS.md "Text capture". - Depends on #1. Part of M1.
Author
Owner

Code complete in 93d6e4c. src/capture.js: extractSpokenText, assistantMessagesFromChange (append + settle-assistant, text blocks only), deduping createCapture, retain/release createSessionCapture (initial window ignored), bounded createMessageIndex for the per-message speaker (#24). Wired into src/client.js via ctx.sessions.list; debug flag logs lengths only.

7 unit tests green (fake event sources, history replay, interruption). Real-browser verification happens in #11 (M1 acceptance); the sandbox cannot install into ~/.dsh.

**Code complete** in `93d6e4c`. `src/capture.js`: `extractSpokenText`, `assistantMessagesFromChange` (append + settle-assistant, text blocks only), deduping `createCapture`, retain/release `createSessionCapture` (initial window ignored), bounded `createMessageIndex` for the per-message speaker (#24). Wired into `src/client.js` via `ctx.sessions.list`; debug flag logs lengths only. 7 unit tests green (fake event sources, history replay, interruption). Real-browser verification happens in #11 (M1 acceptance); the sandbox cannot install into `~/.dsh`.
dsh closed this issue 2026-10-25 17:44:08 +00:00
Sign in to join this conversation.
No description provided.