Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openless-all/app/crates/openless-capsule/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ pub struct CapsulePopupState {
/// Display name of the translation target, already localized by the host.
#[serde(default)]
pub translation_target: Option<String>,
#[serde(default)]
pub skip_auto_style: bool,
#[serde(default)]
pub style_pack_id: Option<String>,
#[serde(default)]
pub style_pack_name: Option<String>,
}

/// Copy shared with the WebView capsule (`src/i18n/*.ts`, `capsule.*`).
Expand Down
185 changes: 157 additions & 28 deletions openless-all/app/crates/openless-core/src/api.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,20 @@ pub const PREFERENCE_FIELDS: &[PreferenceField] = &[
shape: PreferenceShape::Object,
reason: "device_bound",
},
PreferenceField {
rust_name: "skip_auto_style_hotkey",
key: "skipAutoStyleHotkey",
class: PreferenceClass::DeviceProfile,
shape: PreferenceShape::Object,
reason: "device_bound",
},
PreferenceField {
rust_name: "skip_auto_style_picker_enabled",
key: "skipAutoStylePickerEnabled",
class: PreferenceClass::Portable,
shape: PreferenceShape::Boolean,
reason: "portable_setting",
},
PreferenceField {
rust_name: "switch_style_hotkey",
key: "switchStyleHotkey",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ fn all_current_preference_fields_have_an_explicit_registration() {
assert_eq!(registered.len(), registry::PREFERENCE_FIELDS.len());
}

#[test]
fn skip_auto_style_e2ee_device_profile_accepts_legacy_and_new_fields() {
let mut old = sample().documents().clone();
let profile = old.documents.iter_mut().find(|doc| doc.kind == DocumentKind::DeviceProfile).unwrap();
profile.value["preferences"].as_object_mut().unwrap().remove("skipAutoStyleHotkey");
profile.value["preferences"].as_object_mut().unwrap().remove("skipAutoStylePickerEnabled");
validate_sync_documents(old, Revision::new(3)).unwrap();
let mut data = snapshot();
data.preferences.expose_mut()["skipAutoStyleHotkey"] = json!({"primary":"","modifiers":[]});
data.preferences.expose_mut()["skipAutoStylePickerEnabled"] = json!(true);
let exported = export_snapshot(data).unwrap();
let documents = &exported.documents.documents().documents;
let profile = documents.iter().find(|doc| doc.kind == DocumentKind::DeviceProfile).unwrap();
assert_eq!(profile.value["preferences"]["skipAutoStyleHotkey"]["primary"], "");
let picker = documents.iter().find(|doc| doc.kind == DocumentKind::Preferences && doc.id == "skipAutoStylePickerEnabled").unwrap();
assert_eq!(picker.value, true);
}

#[test]
fn new_optional_preference_distinguishes_untouched_from_explicit_default() {
let untouched = crate::shared_types::UserPreferences::default();
Expand Down
66 changes: 66 additions & 0 deletions openless-all/app/crates/openless-core/src/dictation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub enum DictationOutputTarget {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DictationStartOptions {
pub translation_requested: bool,
pub skip_auto_style: bool,
pub audio_source: DictationAudioSource,
pub insert_text: bool,
pub output_target: DictationOutputTarget,
Expand All @@ -56,6 +57,7 @@ impl Default for DictationStartOptions {
fn default() -> Self {
Self {
translation_requested: false,
skip_auto_style: false,
audio_source: DictationAudioSource::Microphone,
insert_text: true,
output_target: DictationOutputTarget::ForegroundApp,
Expand Down Expand Up @@ -125,6 +127,7 @@ impl DictationProviderInvocations {
pub struct DictationPolishContext {
pub mode: PolishMode,
pub style_pack_id: String,
pub style_pack_name: String,
pub style_system_prompt: String,
/// Frozen target metadata, composed only at request time; never part of Raw identity.
pub input_scene_prefix: Option<String>,
Expand Down Expand Up @@ -206,6 +209,9 @@ pub struct RecordingPlan {

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DictationContext {
/// Owned start-time alternatives. Later preference, routing and pack edits
/// cannot change either side of the toggle or a submitted parallel segment.
pub(crate) style_choices: DictationStyleChoices,
pub(crate) input_app: Option<crate::app_style_routing::InputApp>,
/// Annotated built-in Raw prompt, captured before any later prompt changes.
pub(crate) raw_passthrough_prompt: Option<String>,
Expand Down Expand Up @@ -237,6 +243,27 @@ pub struct DictationContext {
pub insertion: DictationInsertionContext,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(tag = "mode", rename_all = "camelCase")]
pub enum DictationStyleSelection {
#[default]
Automatic,
SkipAuto,
StylePack {
#[serde(rename = "stylePackId")]
style_pack_id: String,
},
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct DictationStyleChoices {
pub automatic: StylePack,
pub polish: StylePack,
pub available: Vec<StylePack>,
pub automatic_prior_turns: Vec<PolishHistoryTurn>,
pub selection: DictationStyleSelection,
}

impl Default for DictationContext {
fn default() -> Self {
let preferences = UserPreferences::default();
Expand Down Expand Up @@ -342,7 +369,15 @@ impl DictationContext {
let debug_keep_processed =
preferences.record_audio_for_debug && (preferences.debug_archive_processed || debug_both_off);
let debug_keep_raw = preferences.record_audio_for_debug && preferences.debug_archive_raw;
let automatic_prior_turns = prior_turns.clone();
Self {
style_choices: DictationStyleChoices {
automatic: style_pack.clone(),
polish: style_pack.clone(),
available: vec![style_pack.clone()],
automatic_prior_turns,
selection: DictationStyleSelection::Automatic,
},
input_app: None,
audio_source: options.audio_source,
output_target: options.output_target,
Expand Down Expand Up @@ -405,6 +440,7 @@ impl DictationContext {
input_scene_prefix: None,
mode: style_pack.base_mode,
style_pack_id: style_pack.id.clone(),
style_pack_name: style_pack.name.clone(),
style_system_prompt: crate::style_packs::dictation_style_prompt(style_pack),
hotwords,
working_languages: preferences.working_languages.clone(),
Expand Down Expand Up @@ -473,6 +509,36 @@ impl DictationContext {
next
}

pub(crate) fn with_style_selection(
&self,
selection: DictationStyleSelection,
) -> Result<Self, crate::BackendError> {
let pack = match &selection {
DictationStyleSelection::Automatic => &self.style_choices.automatic,
DictationStyleSelection::SkipAuto => &self.style_choices.polish,
DictationStyleSelection::StylePack { style_pack_id } => self.style_choices.available
.iter().find(|pack| pack.id == *style_pack_id && pack.enabled)
.ok_or_else(|| crate::BackendError::new(crate::BackendErrorCode::InvalidArgument,
"style is not available in this recording"))?,
};
let mut updated = self.clone();
updated.style_choices.selection = selection;
updated.polish.mode = pack.base_mode;
updated.polish.style_pack_id = pack.id.clone();
updated.polish.style_pack_name = pack.name.clone();
updated.polish.style_system_prompt = crate::style_packs::dictation_style_prompt(pack);
// History turns belong to the original style. Never feed them into
// a newly selected style or re-read mutable history mid-recording.
updated.polish.prior_turns = if pack.id == self.style_choices.automatic.id {
self.style_choices.automatic_prior_turns.clone()
} else { Vec::new() };
if updated.unconfigured_llm_raw.is_some() {
updated.unconfigured_llm_raw = Some((updated.polish.mode, updated.polish.style_system_prompt.clone()));
}
updated.restore_or_apply_unconfigured_llm_raw();
Ok(updated)
}

pub fn with_output_target(&self, target: DictationOutputTarget) -> Self {
let mut next = self.clone();
next.output_target = target;
Expand Down
4 changes: 2 additions & 2 deletions openless-all/app/crates/openless-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub mod contract {
pub use activity::{ActivityDay, ActivityStore, DayStats};
pub use api::{
AsrRoute, AsrUsage, BackendRepositories, BackendSnapshot, CliDispatchOutcome,
DictationHotkeyDispatchOptions, DictationHotkeyEdge, DictationTranslationTarget,
DictationHotkeyDispatchOptions, DictationHotkeyEdge, DictationTranslationTarget, DictationStyleTarget,
LessComputerHotkeyAction, LessComputerVoiceFinish, LessComputerVoiceOptions,
LessComputerVoiceSession, OpenLessBackend, QaVoiceCaptureResult, QaVoiceCaptureSession,
StartupSnapshot, VoiceTranscriptionSession,
Expand Down Expand Up @@ -275,7 +275,7 @@ pub use credentials::{
pub use dictation_context::{
build_asr_prompt, eligible_polish_context_turns, DictationAudioSource, DictationContext,
DictationInsertionContext, DictationOutputTarget, DictationPolishContext,
DictationStartOptions, DictationStopOptions, PolishHistoryTurn, ProviderInvocation,
DictationStartOptions, DictationStopOptions, DictationStyleSelection, PolishHistoryTurn, ProviderInvocation,
RecordingPlan, ASR_PROMPT_CHAR_BUDGET,
};
pub use dictation_engine::{PipelineDictationEngine, PolishFailurePolicy};
Expand Down
4 changes: 2 additions & 2 deletions openless-all/app/crates/openless-core/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ pub trait DictationEngine: Send + Sync + 'static {
}

/// Replace the immutable session snapshot before finalization when a host
/// action (currently Android's finish-and-translate gesture) is only known
/// at stop time. Implementations that retain the context must override this
/// action (translation, destination or output-style selection) changes the
/// final polish intent. Implementations that retain the context must override this
/// method; settings are never re-read here.
fn update_context(
&self,
Expand Down
3 changes: 3 additions & 0 deletions openless-all/app/crates/openless-core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct HotkeyRuntimeTarget {
pub qa_companion_key: String,
pub quick_note: Option<ShortcutBinding>,
pub translation: ShortcutBinding,
#[serde(default = "crate::shared_types::default_skip_auto_style_hotkey")]
pub skip_auto_style: ShortcutBinding,
pub switch_style: Option<ShortcutBinding>,
pub open_app: Option<ShortcutBinding>,
pub selection_polish: Option<ShortcutBinding>,
Expand All @@ -85,6 +87,7 @@ impl From<&UserPreferences> for HotkeyRuntimeTarget {
qa_companion_key: preferences.qa_companion_key.clone(),
quick_note: preferences.quick_note_hotkey.clone(),
translation: preferences.translation_hotkey.clone(),
skip_auto_style: preferences.skip_auto_style_hotkey.clone(),
switch_style: preferences.switch_style_hotkey.clone(),
open_app: preferences.open_app_hotkey.clone(),
selection_polish: preferences.selection_polish_hotkey.clone(),
Expand Down
51 changes: 51 additions & 0 deletions openless-all/app/crates/openless-core/src/shared_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ pub struct UserPreferences {
pub custom_combo_hotkey: Option<ComboBinding>,
#[serde(default = "default_translation_hotkey")]
pub translation_hotkey: ShortcutBinding,
#[serde(default = "default_skip_auto_style_hotkey")]
pub skip_auto_style_hotkey: ShortcutBinding,
#[serde(default)]
pub skip_auto_style_picker_enabled: bool,
/// "Switch style" global hotkey. `None` = disabled (no global key
/// registered); `Some(...)` = registered. Defaults to `Some(default key)`
/// — zero behavior change for existing users, only newly clearable
Expand Down Expand Up @@ -1187,6 +1191,9 @@ struct UserPreferencesWire {
qa_save_history: bool,
custom_combo_hotkey: Option<ComboBinding>,
translation_hotkey: Option<ShortcutBinding>,
skip_auto_style_hotkey: Option<ShortcutBinding>,
#[serde(default)]
skip_auto_style_picker_enabled: bool,
switch_style_hotkey: Option<ShortcutBinding>,
open_app_hotkey: Option<ShortcutBinding>,
#[serde(default)]
Expand Down Expand Up @@ -1442,6 +1449,8 @@ impl Default for UserPreferencesWire {
qa_save_history: prefs.qa_save_history,
custom_combo_hotkey: prefs.custom_combo_hotkey,
translation_hotkey: None,
skip_auto_style_hotkey: None,
skip_auto_style_picker_enabled: prefs.skip_auto_style_picker_enabled,
// Carry the default key (Some) so a missing field still means enabled; None exclusively means "user disabled".
switch_style_hotkey: prefs.switch_style_hotkey,
open_app_hotkey: prefs.open_app_hotkey,
Expand Down Expand Up @@ -1594,6 +1603,28 @@ impl<'de> Deserialize<'de> for UserPreferences {
right: AndroidOverlayGestureAction::None,
});

let skip_auto_style_hotkey = wire.skip_auto_style_hotkey.clone().unwrap_or_else(|| {
let proposed = default_skip_auto_style_hotkey();
// A newly introduced default must never steal an existing user's key.
let occupied = [
Some(&dictation_hotkey), wire.translation_hotkey.as_ref(), wire.qa_hotkey.as_ref(),
wire.switch_style_hotkey.as_ref(), wire.open_app_hotkey.as_ref(),
wire.quick_note_hotkey.as_ref(), wire.coding_agent_voice_hotkey.as_ref(),
wire.coding_agent_panel_hotkey.as_ref(), wire.coding_agent_quick_hotkey.as_ref(),
selection_polish_hotkey.as_ref(),
].into_iter().flatten().any(|other| crate::shortcut_types::bindings_overlap(&proposed, other));
if occupied { ShortcutBinding::unassigned() } else { proposed }
});
// Older previews assigned bare Alt on Windows. Until a paired,
// menu-safe native implementation is verified, migrate modifier taps
// to unassigned; custom global combinations remain available.
#[cfg(target_os = "windows")]
let skip_auto_style_hotkey =
if crate::shortcut_types::legacy_modifier_trigger(&skip_auto_style_hotkey).is_some() {
ShortcutBinding::unassigned()
} else {
skip_auto_style_hotkey
};
Ok(Self {
hotkey: wire.hotkey,
dictation_hotkey,
Expand Down Expand Up @@ -1702,6 +1733,8 @@ impl<'de> Deserialize<'de> for UserPreferences {
translation_hotkey: wire
.translation_hotkey
.unwrap_or_else(default_translation_hotkey),
skip_auto_style_hotkey,
skip_auto_style_picker_enabled: wire.skip_auto_style_picker_enabled,
// Pass the Option through: None = user disabled — no
// unwrap_or_else collapse back to the default key (the root
// cause of #576 "can't disable"). A missing field falls to the
Expand Down Expand Up @@ -1972,6 +2005,16 @@ fn default_translation_hotkey() -> ShortcutBinding {
}
}

pub(crate) fn default_skip_auto_style_hotkey() -> ShortcutBinding {
if cfg!(target_os = "windows") {
return ShortcutBinding::unassigned();
}
ShortcutBinding {
primary: if cfg!(target_os = "macos") { "LeftCommand" } else { "LeftAlt" }.into(),
modifiers: Vec::new(),
}
}

fn default_switch_style_hotkey() -> Option<ShortcutBinding> {
Some(ShortcutBinding {
primary: "S".into(),
Expand Down Expand Up @@ -2102,6 +2145,8 @@ impl Default for UserPreferences {
qa_save_history: false,
custom_combo_hotkey: None,
translation_hotkey: default_translation_hotkey(),
skip_auto_style_hotkey: default_skip_auto_style_hotkey(),
skip_auto_style_picker_enabled: false,
switch_style_hotkey: default_switch_style_hotkey(),
open_app_hotkey: default_open_app_hotkey(),
style_pack_hotkeys: Vec::new(),
Expand Down Expand Up @@ -2938,6 +2983,12 @@ pub struct CapsulePayload {
/// user immediately knows this output goes through the translation
/// pipeline. See issue #4.
pub translation: bool,
#[serde(default)]
pub skip_auto_style: bool,
#[serde(default)]
pub style_pack_id: Option<String>,
#[serde(default)]
pub style_pack_name: Option<String>,
/// Whether this is a Less Computer (voice agent controlling the
/// computer) session. The frontend switches the processing label from
/// "thinking" to "using" — the agent is operating the computer, not
Expand Down
Loading
Loading