hex/docs/features/voice-action.md
Kit Langton 04a42dae3d refactor: consolidate settings commits, transcription padding, and SDK framing
Settings controls commit a full candidate before changing the saved UI choice,
so a failed write keeps shortcut capture open and preserves pending debounced
edits. The macOS Transcriber owns backend input padding for ordinary,
voice-protocol, and segmented transcription. Moonshine stream cleanup and the
Linux client share one owner-side path. The command SDK shares capture
normalization between constructors and host registration, and the public SDK
decodes model progress and dictation levels with one bounded SSE framer. The
signing scripts share one identity helper, and historical release evidence
moves out of the feature map.
2026-09-22 17:08:43 -07:00

11 KiB

Voice Action

Hold a separate shortcut and speak an instruction, optionally with text selected. HEX transcribes locally, asks Voice Action's OpenCode model for paste-ready text, and pastes at the current focus. This is not Voice Commands or ordinary Dictation.

This map covers macOS. Linked checks are locators, not passing runs; no tests, previews, providers, or native actions were run for this split.

How To Get To It

Hex > Voice Action                                   // voice-action; off by default
├── Enable Voice Action -> Activate saved shortcut
├── Shortcut -> Option-Command by default             // independent of Dictation
└── Processing -> OpenCode model / available Thinking variant

Foreground text target -> Optional selection -> Hold shortcut -> Speak -> Release

Requires ordinary setup permissions, a local transcription model, and OpenCode with an available text model. Commands and its Moonshine model are not required. render_voice_action in app_window.rs keeps the toggle reachable when OpenCode is unavailable; the pane offers setup/retry actions. HEX discovers opencode2 and its managed service through dictation_processor.rs, not a separate HEX-owned provider service.

Discovery uses opencode2 api get /api/info; an exact CLI 404 falls back to /api/status, then /api/health, for older V2 services. All attempts share the original deadline and cancellation flag. Authentication, server, and malformed-response failures do not trigger that fallback, and discovery output is excluded from errors. service_discovery_supports_current_and_legacy_endpoints and service_discovery_fallback_shares_deadline_and_observes_cancellation cover these routes with executable fixtures. This shared discovery also serves Modes.

Fixed after 2.1.20: releases 2.1.18 through 2.1.20 only tried /api/status and /api/health, and posted generation to /api/generate. OpenCode 0.0.0-dev-19726 and later serve only /api/info and /api/experimental/generate, so those releases report OpenCode service discovery failed (exit status: 1), and even with discovery repaired, generation received an empty 404 body and Modes fell back to the corrected transcript (#98). Generation now posts to the new route and falls back to /api/generate only on HTTP 404; generation_falls_back_to_the_legacy_route_only_when_the_new_one_is_missing covers both routes and the served-error case through a loopback fixture. On September 22, 2026 the ignored live_catalog test discovered the running 0.0.0-dev-19937 service through /api/info and loaded its catalog, the legacy names returned exactly HTTP 404 Not Found from the CLI, and an explicit-model request to /api/experimental/generate returned paste-ready text.

Sub-features

Independent Opt-In

New settings OR existing settings without enabled=true // voice-action.opt-in
  -> Off -> Saved binding neither active nor reserved

Enable -> Check shortcut conflicts -> Persist opt-in
Disable -> Cancel active Voice Action capture
        -> Keep accepted jobs, saved shortcut, model, and variant

Checks in app_settings.rs: voice_action_requires_explicit_opt_in_for_new_and_existing_settings, voice_action_settings_round_trip, and disabled_voice_action_preserves_its_binding_without_reserving_it. Checks in app_window.rs: voice_action_opt_in_rejects_active_conflicts_without_rebinding and voice_action_toggle_preserves_configuration_and_can_always_disable. These cover settings and conflict logic, not native shortcut registration. Active-capture cancellation is wired in recognition.rs when the runtime edit binding becomes None; the settings tests alone do not prove that runtime transition.

Hold Or Promote

Hold saved Voice Action shortcut                      // voice-action.shortcut
├── Intentional hold -> Capture -> Release -> Submit
└── Short tap -> Discard                               // no double-tap locking

Default Option dictation already recording + Command joins
  -> Promote same capture -> Preserve recorded audio   // not a second recording
  -> Voice Action owns release, not ordinary Dictation

Source: handle_edit_hotkey_action, voice_action_owns_action, and start_pending_voice_action in recognition.rs. Checks there: slow_chord_release_keeps_voice_action_ownership, accepted_voice_action_preserves_promoted_capture, rejected_voice_action_cancels_promoted_capture, and delayed_voice_action_edges_use_their_source_timestamps. These cover synthetic edges and capture admission, not physical onset or sample-for-sample audio continuity through promotion.

voice_action_uses_separate_binding_after_dictation_is_rebound in suppression.rs checks independent bindings. DictationHotkey::new_without_paste disables locking for this target; ordinary Dictation's double-tap settings do not add a Voice Action lock. Cold microphone modifier order remains a known gap.

Optional Selection

Intentional Voice Action -> Snapshot optional selected text // voice-action.selection
├── Accessibility exposes bounded nonempty text -> Include as prompt context
└── Empty / inaccessible / oversized -> No selection; generate from instruction

Selection capture -> No clipboard read or copy shortcut
Later paste -> Current focus, not a pinned original selection

Sources: voice_action_context_snapshot in recognition.rs, capture_optional in accessibility.rs, and voice_action_prompt in dictation_processor.rs. Checks in the processor: voice_action_prompt_keeps_the_instruction_separate_from_selected_text and voice_action_prompt_supports_generation_without_a_selection. These construct prompt strings; they do not prove Accessibility support in an arbitrary application. Selection is limited to 64 KiB; full window text is not substituted when selection is absent.

Local Transcript To Model

Accepted recording -> Selected local transcription model // voice-action.processing
  -> Instruction + optional selection + app / browser host
  -> Voice Action OpenCode model and deadline
     ├── Nonempty reply -> Paste-ready output
     └── Failure / timeout / empty -> Paste nothing      // no raw-transcript fallback

Modes -> Bypassed                                      // no corrections/rewrite/transformations

Sources: the TranscriptionTarget::VoiceAction processing branch in parakeet.rs, process_voice_action_cancellable and voice_action_failure in dictation_processor.rs. Voice Action uses its own model/variant and persisted deadline (60 seconds by default); no explicit model selection delegates to OpenCode's default. Audio transcription stays local, but the prompt text goes to the configured OpenCode provider.

voice_action_processing_never_loads_modes_and_announces_stage_before_generation in parakeet.rs checks that this route never acquires ordinary Modes profiles and announces Processing before invoking Voice Action. It uses an injected processor, not a provider or native capture pipeline.

generation_http_wait_observes_cancellation_and_deadline and cancelled_generation_process_is_killed_promptly in the processor cover local HTTP/process fixtures, not a live provider or the full Voice Action pipeline. Mode bypass and no-fallback routing are source-backed here, not a claimed end-to-end pass. See Recovery for the distinction from ordinary Dictation's best-effort processing fallback.

Output And Cancellation

Accepted jobs -> Shared bounded queue -> Submission-order output // voice-action.output
  -> Standalone paste at current focus
     ├── Successful output -> History when retention permits
     └── Last Dictation -> Unchanged                    // Paste Last never recalls this reply

Escape                                                // voice-action.cancel
├── Active capture -> Cancel that capture first
└── Otherwise -> Cancel newest cancellable accepted job
Before output commit -> No paste; after commit -> No undo

Sources: recognition.rs, finish_output in parakeet.rs, and paste.rs. Checks in parakeet.rs: parallel_processing_results_are_released_in_submission_order, repeated_cancellation_walks_back_through_pending_jobs, and output_stays_cancellable_through_preparation_but_not_after_mutation. The last explicitly includes Voice Action, its standalone paste mode, History, and unchanged last-dictation text. These use controlled output/paste boundaries and temporary History storage, not a foreground application's clipboard consumption. See Dictation and Recovery for the shared boundary.

Gaps And Constraints

Cold Modifier Order

Release when idle + default shortcut                   // known #23, not fixed here
├── Command-first -> Pending Voice Action -> Intentional threshold -> Open mic
└── Option-first -> Already-started Dictation capture -> Promote

Ordinary cold-Dictation checks -> Both Voice Action orders // NOT established

Source: start_pending_voice_action and intentional-hold handling in recognition.rs. #23 still needs both modifier orders with a controlled opener, then native audio-onset evidence. See Recovery; a successful HUD fixture does not establish equivalent audio onset.

  • Preview limits: capture-preview.sh provides voice-action, --voice-action-enabled, and --opencode-unavailable fixtures. They render states, not selection-to-provider-to-paste execution.
  • Focus and provider limits: the prompt asks for paste-ready text; tests do not guarantee a provider follows it. Moving focus while work is pending changes the eventual paste target. A failed action does not paste its local transcript.
  • Native proof: permissions, shortcut ordering, microphone mode, selection support, provider response, and target paste still need an explicit controlled end-to-end check. This map does not authorize operating the installed app.