hex/docs/features/voice-action.md
Kit Langton e7d6559f8b
Settings: icon rows, Labs sidebar, and one Advanced fold per pane (#340)
* Settings: icon rows, Labs sidebar, and one Advanced fold per pane (t419)

* Settings: update the Linux UI tests for Labs and Advanced folds (t419)

* Settings: the Bluetooth microphone row in General's Advanced fold (t419)

* Settings: regenerate the goldens for icon rows and Labs (t419)

* Settings: allow a point of pixel snap in the fold test (t419)

* Settings: the fold test measures the row right below it (t419)

* Settings: name the sidebar row type in the nav tests (t419)
2026-10-29 10:28:02 -07:00

269 lines
14 KiB
Markdown

# 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](commands.md) or ordinary [Dictation](dictation.md).
This map covers macOS; [Linux](#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
```ts
Labs > Voice Action switch, or Hex > Voice Action once on // voice-action; off by default
├── Enable Voice Action -> Activate saved shortcut; the pane joins the sidebar
├── Shortcut -> Option-Command by default // independent of Dictation
├── Processing -> OpenCode model
└── Advanced ▸ -> Shortcut side, 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](../../src/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](../../src/dictation_processor.rs), not a separate
Hex-owned provider service.
```ts
HEX_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](https://github.com/anomalyco/hex/issues/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](https://github.com/anomalyco/hex/issues/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
```ts
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](../../src/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](../../src/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](../../src/recognition.rs)
when the runtime edit binding becomes `None`; the settings tests alone do not
prove that runtime transition.
### Hold Or Promote
```ts
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](../../src/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](dictation.md#hold-and-short-taps) 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](../../src/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](#cold-modifier-order).
### Optional Selection
```ts
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](../../src/recognition.rs), `capture_optional` in
[accessibility.rs](../../src/accessibility.rs), and `voice_action_prompt` in
[dictation_processor.rs](../../src/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
```ts
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](../../src/parakeet.rs), `process_voice_action_cancellable` and
`voice_action_failure` in [dictation_processor.rs](../../src/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](../../src/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](recovery.md#degrade-only-the-failing-dependency)
for the distinction from ordinary Dictation's best-effort processing fallback.
### Output And Cancellation
```ts
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](../../src/recognition.rs), `finish_output` in
[parakeet.rs](../../src/parakeet.rs), and [paste.rs](../../src/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](dictation.md#cancellation-before-commit) and
[Recovery](recovery.md#cancel-without-losing-other-work) for the shared boundary.
## Gaps And Constraints
### Cold Modifier Order
```ts
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](../../src/recognition.rs).
[#23](https://github.com/anomalyco/hex/issues/23) still needs both modifier orders
with a controlled opener, then native audio-onset evidence. See
[Recovery](recovery.md#cold-voice-action); 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
```ts
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](../../src/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](../../src/linux_app.rs) and `commands_reach_only_a_listening_route`
in [linux_service.rs](../../src/linux_service.rs)). `run_voice_action` in
[linux_dictation.rs](../../src/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.