hex/docs/features/voice-action.md
Dax 3738413154
fix(opencode): accept a V2 opencode and explain unavailable switches (#282)
Discovery now looks for `opencode` as well as `opencode2` in every location,
preferring any `opencode2`. A plain `opencode` counts only once a bounded
probe proves it V2 (`--version` >= 2, or a prerelease that answers
`api get /api/info`); a V1-only install shows "Requires OpenCode V2".
The reason now shows beside the Modes transformation and Voice Action
switches.

Fixes #281
2026-10-28 09:27:42 -04:00

14 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; Linux differs only in how the instruction is captured. 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. rune_ui/voice_action.rs keeps the toggle reachable when OpenCode is unavailable, says why beside it ("Requires OpenCode", "Requires OpenCode V2"), and the Processing section offers setup/retry actions. HEX discovers the OpenCode V2 CLI and its managed service through dictation_processor.rs, not a separate HEX-owned provider service.

VOICE_CONTROL_OPENCODE_CLI set -> Use it as is
Otherwise PATH, home install folders, Node version managers, Homebrew
├── Any `opencode2` -> Use it                        // beats every `opencode`
├── Else an `opencode` whose `--version` is 2.x -> Use it
├── Else an `opencode` printing `0.0.0-…` that answers `api get /api/info` -> Use it
├── Only V1 `opencode` -> "Requires OpenCode V2"     // never run for generation
└── Nothing -> "Requires OpenCode"                  // both rechecked every 60 s

The bounded probe runs only on the catalog, generation, and Capture threads and keeps each definite verdict until the executable changes; the hotkey and UI paths only read that verdict (#281). opencode2_is_preferred_and_only_a_v2_opencode_is_accepted and release_versions_tell_the_generations_apart cover precedence and V1 rejection with temporary executables, not installed CLIs.

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 in 2.1.21: 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 rune_ui/voice_action.rs: voice_action_opt_in_rejects_active_conflicts_without_rebinding and voice_action_toggle_preserves_configuration_and_can_always_disable; the pane test voice_action_saves_its_opt_in_and_refuses_a_taken_shortcut. 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.

A modifier-only Voice Action shortcut, promoted or not, gets Dictation's chord breaker once its own hold is accepted, so a modifier-tap hotkey in another app does not fire on release. Hex drops the breaker before the focused app, which would otherwise beep at an unhandled key with ⌘ held, even in a text field. Check: voice_action_promotion_breaks_its_own_chord_after_its_hold.

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); when no explicit model is selected, HEX ranks available fast models from RECOMMENDED_OPENCODE_MODELS (starting with gemini-3.1-flash-lite on minimal thinking, claude-haiku-4-5, and gpt-5.4-nano on none) and walks those candidates in order before falling back to OpenCode's default. model_catalog_ranks_recommended_models_and_selects_top_available_default_with_variant and ranked_generation_walks_candidates_until_one_succeeds cover catalog ranking, preferred variant selection, and candidate fallback. 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.

  • Scene limits: the voice-action, voice-action-off, voice-action-unavailable, voice-action-models, and modes-opencode-v1 scenes are 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.

Linux

Voice Action > Enable                                 // voice-action.linux; off by default
├── X11 -> Hold the saved shortcut (Ctrl+Alt+I by default) -> Release -> Run
├── Wayland + GlobalShortcuts portal -> Hold the granted trigger -> Release -> Run
├── Wayland without the portal -> Desktop keybinding runs
│   `hex voice-action start` on press, `hex voice-action stop` on release,
│   or `hex voice-action toggle`
├── Escape or `hex dictation cancel` -> Cancel the instruction
└── Selected text -> Primary selection (X11 clipboard, `wl-paste --primary`)

The shortcut and commands feed the same state machine as dictation in linux_input.rs, so Voice Action and dictation never record at once, and a command while Voice Action is off fails with an error from the service (commands_route_only_to_a_started_listener in linux_app.rs and commands_reach_only_a_listening_route in linux_service.rs). run_voice_action in linux_dictation.rs sends the instruction and selection through the same OpenCode Voice Action processing and pastes the reply. voice_action_records_while_its_shortcut_is_held and voice_action_commands_are_idempotent cover the gestures; no OpenCode request or paste has been observed on a Linux desktop.