Repository navigation
Expand file tree
/
Copy pathlabs.rs
More file actions
1317 lines (1233 loc) · 50.5 KB
/
Copy pathlabs.rs
File metadata and controls
1317 lines (1233 loc) · 50.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Labs: features we're unsure about, especially ones people asked for,
//! each behind its own switch, off by default. There is no master switch:
//! Settings › Labs lists every feature as a row with a toggle. A feature
//! with its own pane (Meetings, Voice Filter, Playground) joins the sidebar
//! as a normal item while on and is hidden while off; a behaviour-only
//! feature (Live text, Live chapters, Vocabulary biasing, keyboard-language
//! model switching, mouse shortcuts, pausing the browser, restoring Paste
//! last dictation's default shortcut, keeping the dictation on the
//! clipboard or only copying it (macOS), a second dictation shortcut
//! (macOS), Toggle's tap or hold (macOS), stopping an automatic meeting
//! recording when its call ends (macOS), and Terminal paste
//! and shortcut sharing on Windows) is just its toggle.
//!
//! Each feature has an audience (`Feature::audience`): `Everyone` ships in
//! every build; `Dev` exists only in dev builds (`dev_build::is_dev_build`:
//! debug, local, test, and dev-channel builds). A stable build never lists,
//! accepts, or runs a Dev feature, and keeps its saved setting untouched.
//!
//! Gate a feature where its work starts (the worker, thread, or capture
//! that does it), not only where its UI shows.
use std::sync::atomic::{AtomicU64, Ordering};
use clap::Subcommand;
use color_eyre::Result;
use color_eyre::eyre::eyre;
use crate::app_settings::{AppSettings, LabsSettings};
/// Where people send feedback on Labs features.
pub const FEEDBACK_URL: &str = "https://github.com/anomalyco/hex/issues/new";
/// Who a Labs feature is for.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Audience {
/// Ships in every build.
Everyone,
/// Only dev builds have it.
Dev,
}
impl Audience {
/// Whether a build of this kind has features for it.
pub const fn reaches(self, dev_build: bool) -> bool {
match self {
Self::Everyone => true,
Self::Dev => dev_build,
}
}
pub const fn name(self) -> &'static str {
match self {
Self::Everyone => "everyone",
Self::Dev => "dev",
}
}
}
/// One Labs feature.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Feature {
Meetings,
VoiceFilter,
Playground,
LiveText,
LiveChapters,
VocabularyBiasing,
TerminalPaste,
KeyboardModelSwitching,
MouseShortcuts,
PauseBrowser,
ShareShortcut,
UnloadIdle,
RestoreShortcutDefault,
KeepOnClipboard,
CopyOnly,
SpokenFormatting,
FillerWords,
SubtitleExport,
SecondDictationShortcut,
SmartSpacing,
SpokenSymbols,
PickerSortFilter,
SidedChords,
TapOrHold,
BenchmarkDetails,
ParakeetUltra,
StandaloneSpecialKeys,
HistoryStats,
RecentDictations,
SkipPauses,
StopWhenCallEnds,
OutputFixes,
PickerActiveFirst,
ModelInPlace,
PickerDownloaded,
SectionKeyAlone,
KeepRecordings,
HideMenuBarIcon,
}
impl Feature {
pub const ALL: [Self; 38] = [
Self::Meetings,
Self::VoiceFilter,
Self::Playground,
Self::LiveText,
Self::LiveChapters,
Self::VocabularyBiasing,
Self::TerminalPaste,
Self::KeyboardModelSwitching,
Self::MouseShortcuts,
Self::PauseBrowser,
Self::ShareShortcut,
Self::UnloadIdle,
Self::RestoreShortcutDefault,
Self::KeepOnClipboard,
Self::CopyOnly,
Self::SpokenFormatting,
Self::FillerWords,
Self::SubtitleExport,
Self::SecondDictationShortcut,
Self::SmartSpacing,
Self::SpokenSymbols,
Self::PickerSortFilter,
Self::SidedChords,
Self::TapOrHold,
Self::BenchmarkDetails,
Self::ParakeetUltra,
Self::StandaloneSpecialKeys,
Self::HistoryStats,
Self::RecentDictations,
Self::SkipPauses,
Self::StopWhenCallEnds,
Self::OutputFixes,
Self::PickerActiveFirst,
Self::ModelInPlace,
Self::PickerDownloaded,
Self::SectionKeyAlone,
Self::KeepRecordings,
Self::HideMenuBarIcon,
];
/// The features this OS and build have.
pub fn available() -> impl Iterator<Item = Self> {
Self::available_where(Self::shipped)
}
/// The features on this OS that `reaches` admits.
fn available_where(reaches: impl Fn(Self) -> bool) -> impl Iterator<Item = Self> {
Self::ALL
.into_iter()
.filter(move |feature| feature.on_this_os() && reaches(*feature))
}
/// Whether this build has the feature: its audience reaches a dev or
/// stable build.
pub fn shipped(self) -> bool {
self.audience().reaches(crate::dev_build::is_dev_build())
}
/// Who the feature is for. Every feature picks one.
pub const fn audience(self) -> Audience {
match self {
Self::Meetings
| Self::VoiceFilter
| Self::Playground
| Self::LiveText
| Self::LiveChapters
| Self::VocabularyBiasing
| Self::TerminalPaste
| Self::KeyboardModelSwitching
| Self::MouseShortcuts
| Self::PauseBrowser
| Self::ShareShortcut
| Self::UnloadIdle
| Self::RestoreShortcutDefault
| Self::KeepOnClipboard
| Self::CopyOnly
| Self::SpokenFormatting
| Self::FillerWords
| Self::SubtitleExport
| Self::SecondDictationShortcut
| Self::SmartSpacing
| Self::SpokenSymbols
| Self::PickerSortFilter
| Self::SidedChords
| Self::TapOrHold
| Self::BenchmarkDetails
| Self::ParakeetUltra
| Self::StandaloneSpecialKeys
| Self::HistoryStats
| Self::RecentDictations
| Self::SkipPauses
| Self::StopWhenCallEnds
| Self::OutputFixes
| Self::PickerActiveFirst
| Self::ModelInPlace
| Self::PickerDownloaded
| Self::SectionKeyAlone
| Self::KeepRecordings
| Self::HideMenuBarIcon => Audience::Everyone,
}
}
/// Why turning this feature off is refused now: Parakeet Ultra stays on
/// while it is the dictation model, until a switch to another succeeds.
pub fn off_refusal(self, settings: &AppSettings) -> Option<&'static str> {
(self == Self::ParakeetUltra
&& settings.transcription.model
== crate::transcription::models::TranscriptionModelId::ParakeetUltra)
.then_some(
"Parakeet Ultra is the dictation model; choose another model before turning it off",
)
}
/// The feature `hex settings` key `key` switches (its toggle, or
/// Unload when idle's minutes).
pub fn for_settings_key(key: &str) -> Option<Self> {
if key == "labs.unload_idle_minutes" {
return Some(Self::UnloadIdle);
}
Self::ALL
.into_iter()
.find(|feature| feature.settings_key() == key)
}
fn on_this_os(self) -> bool {
match self {
Self::Meetings | Self::LiveChapters | Self::SubtitleExport | Self::StopWhenCallEnds => {
cfg!(target_os = "macos")
}
Self::VoiceFilter => cfg!(any(target_os = "macos", target_os = "linux")),
Self::TerminalPaste | Self::ShareShortcut => cfg!(target_os = "windows"),
Self::SectionKeyAlone => cfg!(target_os = "linux"),
Self::StandaloneSpecialKeys | Self::SkipPauses => {
cfg!(any(target_os = "linux", target_os = "windows"))
}
Self::MouseShortcuts
| Self::PauseBrowser
| Self::KeepOnClipboard
| Self::CopyOnly
| Self::SecondDictationShortcut
| Self::SmartSpacing
| Self::SidedChords
| Self::TapOrHold
| Self::RecentDictations
| Self::HideMenuBarIcon => cfg!(target_os = "macos"),
Self::KeyboardModelSwitching => crate::keyboard_input_sources::available(),
Self::Playground
| Self::LiveText
| Self::VocabularyBiasing
| Self::UnloadIdle
| Self::RestoreShortcutDefault
| Self::SpokenFormatting
| Self::SpokenSymbols
| Self::PickerSortFilter
| Self::BenchmarkDetails
| Self::ParakeetUltra
| Self::HistoryStats
| Self::OutputFixes
| Self::PickerActiveFirst
| Self::ModelInPlace
| Self::PickerDownloaded
| Self::KeepRecordings
| Self::FillerWords => true,
}
}
/// The name `hex labs on|off` takes.
pub const fn name(self) -> &'static str {
match self {
Self::Meetings => "meetings",
Self::VoiceFilter => "voice-filter",
Self::Playground => "playground",
Self::LiveText => "live-text",
Self::LiveChapters => "live-chapters",
Self::VocabularyBiasing => "vocabulary-biasing",
Self::TerminalPaste => "terminal-paste",
Self::KeyboardModelSwitching => "keyboard-model-switching",
Self::MouseShortcuts => "mouse-shortcuts",
Self::PauseBrowser => "pause-browser",
Self::ShareShortcut => "share-shortcut",
Self::UnloadIdle => "unload-idle",
Self::RestoreShortcutDefault => "restore-shortcut-default",
Self::KeepOnClipboard => "keep-on-clipboard",
Self::CopyOnly => "copy-only",
Self::SpokenFormatting => "spoken-formatting",
Self::FillerWords => "filler-words",
Self::SubtitleExport => "subtitle-export",
Self::SecondDictationShortcut => "second-dictation-shortcut",
Self::SmartSpacing => "smart-spacing",
Self::SpokenSymbols => "spoken-symbols",
Self::PickerSortFilter => "picker-sort-filter",
Self::SidedChords => "sided-modifier-chords",
Self::TapOrHold => "tap-or-hold",
Self::BenchmarkDetails => "benchmark-details",
Self::ParakeetUltra => "parakeet-ultra",
Self::StandaloneSpecialKeys => "special-keys",
Self::HistoryStats => "history-stats",
Self::RecentDictations => "recent-dictations",
Self::SkipPauses => "skip-pauses",
Self::StopWhenCallEnds => "stop-when-call-ends",
Self::OutputFixes => "output-fixes",
Self::PickerActiveFirst => "picker-active-first",
Self::ModelInPlace => "model-in-place",
Self::PickerDownloaded => "picker-downloaded",
Self::SectionKeyAlone => "section-key",
Self::KeepRecordings => "keep-recordings",
Self::HideMenuBarIcon => "hide-menu-bar-icon",
}
}
/// Its `hex settings` key.
pub const fn settings_key(self) -> &'static str {
match self {
Self::Meetings => "meetings.enabled",
Self::VoiceFilter => "experimental.hex_microphone",
Self::Playground => "labs.playground",
Self::LiveText => "labs.live_text",
Self::LiveChapters => "labs.live_chapters",
Self::VocabularyBiasing => "labs.vocabulary_biasing",
Self::TerminalPaste => "paste_with_shift",
Self::KeyboardModelSwitching => "keyboard_model_switching.enabled",
Self::MouseShortcuts => "labs.mouse_shortcuts",
Self::PauseBrowser => "pause_browser_media",
Self::ShareShortcut => "share_dictation_shortcut",
Self::UnloadIdle => "labs.unload_idle",
Self::RestoreShortcutDefault => "labs.restore_shortcut_default",
Self::KeepOnClipboard => "labs.keep_on_clipboard",
Self::CopyOnly => "labs.copy_only",
Self::SpokenFormatting => "labs.spoken_formatting",
Self::FillerWords => "labs.filler_words",
Self::SubtitleExport => "labs.subtitle_export",
Self::SecondDictationShortcut => "labs.second_dictation_shortcut",
Self::SmartSpacing => "labs.smart_spacing",
Self::SpokenSymbols => "labs.spoken_symbols",
Self::PickerSortFilter => "labs.picker_sort_filter",
Self::SidedChords => "labs.sided_modifier_chords",
Self::TapOrHold => "labs.tap_or_hold",
Self::BenchmarkDetails => "labs.benchmark_details",
Self::ParakeetUltra => "labs.parakeet_ultra",
Self::StandaloneSpecialKeys => "labs.standalone_special_keys",
Self::HistoryStats => "labs.history_stats",
Self::RecentDictations => "labs.recent_dictations",
Self::SkipPauses => "labs.skip_pauses",
Self::StopWhenCallEnds => "labs.stop_when_call_ends",
Self::OutputFixes => "labs.output_fixes",
Self::PickerActiveFirst => "labs.picker_active_first",
Self::ModelInPlace => "labs.model_in_place",
Self::PickerDownloaded => "labs.picker_downloaded",
Self::SectionKeyAlone => "labs.section_key_alone",
Self::KeepRecordings => "labs.keep_recordings",
Self::HideMenuBarIcon => "labs.hide_menu_bar_icon",
}
}
/// The English one-line description the CLI prints; the window shows
/// its translated row.
pub const fn description(self) -> &'static str {
match self {
Self::Meetings => "Record calls and keep transcripts (its own pane)",
Self::VoiceFilter => {
"Hex Microphone virtual input and real-time voice filters (its own pane)"
}
Self::Playground => "Scene and story browser in the window",
Self::LiveText => "Show provisional words beside the HUD while dictating",
Self::LiveChapters => "Break meeting transcripts into chapters while recording",
Self::VocabularyBiasing => {
"Bias Parakeet transcription toward your vocabulary; rewriting and search use it either way"
}
Self::TerminalPaste => "Paste with Ctrl+Shift+V, for apps that ignore Ctrl+V",
Self::KeyboardModelSwitching => {
"Changing the keyboard language switches the speech model and language"
}
Self::MouseShortcuts => "Record mouse buttons as shortcuts",
Self::PauseBrowser => "Also pause the browser while dictating, with Pause media",
Self::ShareShortcut => "Let apps such as Discord see the dictation shortcut too",
Self::UnloadIdle => {
"Free the speech model's memory after a while unused (labs.unload_idle_minutes); the next dictation reloads it"
}
Self::RestoreShortcutDefault => {
"Offer Restore default next to Paste last dictation's shortcut"
}
Self::KeepOnClipboard => {
"Leave the dictation on the clipboard after pasting instead of restoring what was there"
}
Self::CopyOnly => "Put the dictation on the clipboard instead of pasting it",
Self::SpokenFormatting => {
"Turn spoken \"new line\", \"new paragraph\", and \"open/close quote\" into line breaks and quotation marks"
}
Self::FillerWords => {
"Remove filler words such as um and uh from dictations, without an AI model"
}
Self::SubtitleExport => {
"Export meeting transcripts as SRT or VTT subtitles with hex meetings show"
}
Self::SecondDictationShortcut => {
"Another shortcut that dictates like the main one (second_dictation_hotkey), such as a key on an external keyboard"
}
Self::SmartSpacing => "Add a space before a dictation pasted right after a word",
Self::SpokenSymbols => {
"Turn spoken \"comma\", \"colon\", \"hashtag\", \"underscore\", and similar words into symbols joined to their words"
}
Self::PickerSortFilter => {
"Sort the Local transcription picker by size or name and show only models for the saved language"
}
Self::SidedChords => {
"Record which side each modifier of a shortcut is on, such as Right Command + Right Option"
}
Self::TapOrHold => {
"In Toggle mode, hold the shortcut to dictate until you let go; a short tap still starts and stops"
}
Self::BenchmarkDetails => {
"Show each model's raw error rate, benchmark, and source in the Local transcription picker"
}
Self::ParakeetUltra => {
"Offer Parakeet Ultra, Moondream's post-trained Parakeet v3, in the Local transcription picker"
}
Self::StandaloneSpecialKeys if cfg!(target_os = "windows") => {
"Use Insert, Home, End, Page Up, or Page Down alone as a shortcut"
}
Self::StandaloneSpecialKeys => {
"Use Menu, Pause, or Scroll Lock alone as a shortcut, such as Caps Lock remapped to Menu"
}
Self::HistoryStats => {
"Show a summary of your retained dictations at the top of History, with hex history stats"
}
Self::RecentDictations => {
"Copy one of your last five dictations from the menu bar, under Paste Last Dictation"
}
Self::SkipPauses => {
"Shorten long pauses before a whole dictation goes to the model, so slow computers paste sooner"
}
Self::StopWhenCallEnds => {
"Stop a meeting recording Hex started on its own 30 s after the call app leaves the microphone and goes quiet"
}
Self::OutputFixes => {
"Offer Vocabulary and Fix this beside Output's Try result, to correct a wrong result"
}
Self::PickerActiveFirst => "The speech model picker lists the model you're using first",
Self::ModelInPlace => {
"Add a speech model file and use it where it is, without copying it, so several accounts can share one file"
}
Self::PickerDownloaded => {
"Show only downloaded speech models in the picker, with the space they take"
}
Self::SectionKeyAlone => {
"Use the § key, left of 1 on ISO keyboards, alone as a shortcut; Hex takes § from every app while it's bound"
}
Self::KeepRecordings => {
"Keep the audio of dictations saved to History, so you can transcribe them again with another model"
}
Self::HideMenuBarIcon => {
"Hide Hex's menu bar icon; shortcuts keep working, and opening Hex again shows Settings"
}
}
}
pub fn from_name(name: &str) -> Option<Self> {
Self::ALL.into_iter().find(|feature| feature.name() == name)
}
/// Whether `settings` turn it on.
pub fn on(self, settings: &AppSettings) -> bool {
match self {
Self::Meetings => settings.meetings.enabled,
Self::VoiceFilter => settings.experimental.hex_microphone,
Self::Playground => settings.labs.playground,
Self::LiveText => settings.labs.live_text,
Self::LiveChapters => settings.labs.live_chapters,
Self::VocabularyBiasing => settings.labs.vocabulary_biasing,
Self::TerminalPaste => settings.paste_with_shift,
Self::KeyboardModelSwitching => settings.keyboard_model_switching.enabled,
Self::MouseShortcuts => settings.labs.mouse_shortcuts,
Self::PauseBrowser => settings.pause_browser_media,
Self::ShareShortcut => settings.share_dictation_shortcut,
Self::UnloadIdle => settings.labs.unload_idle,
Self::RestoreShortcutDefault => settings.labs.restore_shortcut_default,
Self::KeepOnClipboard => settings.labs.keep_on_clipboard,
Self::CopyOnly => settings.labs.copy_only,
Self::SpokenFormatting => settings.labs.spoken_formatting,
Self::FillerWords => settings.labs.filler_words,
Self::SubtitleExport => settings.labs.subtitle_export,
Self::SecondDictationShortcut => settings.labs.second_dictation_shortcut,
Self::SmartSpacing => settings.labs.smart_spacing,
Self::SpokenSymbols => settings.labs.spoken_symbols,
Self::PickerSortFilter => settings.labs.picker_sort_filter,
Self::SidedChords => settings.labs.sided_modifier_chords,
Self::TapOrHold => settings.labs.tap_or_hold,
Self::BenchmarkDetails => settings.labs.benchmark_details,
Self::ParakeetUltra => settings.labs.parakeet_ultra,
Self::StandaloneSpecialKeys => settings.labs.standalone_special_keys,
Self::HistoryStats => settings.labs.history_stats,
Self::RecentDictations => settings.labs.recent_dictations,
Self::SkipPauses => settings.labs.skip_pauses,
Self::StopWhenCallEnds => settings.labs.stop_when_call_ends,
Self::OutputFixes => settings.labs.output_fixes,
Self::PickerActiveFirst => settings.labs.picker_active_first,
Self::ModelInPlace => settings.labs.model_in_place,
Self::PickerDownloaded => settings.labs.picker_downloaded,
Self::SectionKeyAlone => settings.labs.section_key_alone,
Self::KeepRecordings => settings.labs.keep_recordings,
Self::HideMenuBarIcon => settings.labs.hide_menu_bar_icon,
}
}
/// Every feature's switch in `settings`, for the Labs lock
/// (`crate::policy`).
pub fn switches(settings: &mut AppSettings) -> Vec<&mut bool> {
let labs = &mut settings.labs;
vec![
&mut settings.meetings.enabled,
&mut settings.experimental.hex_microphone,
&mut settings.paste_with_shift,
&mut settings.keyboard_model_switching.enabled,
&mut settings.pause_browser_media,
&mut settings.share_dictation_shortcut,
&mut labs.playground,
&mut labs.live_text,
&mut labs.live_chapters,
&mut labs.vocabulary_biasing,
&mut labs.mouse_shortcuts,
&mut labs.unload_idle,
&mut labs.restore_shortcut_default,
&mut labs.keep_on_clipboard,
&mut labs.copy_only,
&mut labs.spoken_formatting,
&mut labs.filler_words,
&mut labs.subtitle_export,
&mut labs.second_dictation_shortcut,
&mut labs.smart_spacing,
&mut labs.spoken_symbols,
&mut labs.picker_sort_filter,
&mut labs.sided_modifier_chords,
&mut labs.tap_or_hold,
&mut labs.benchmark_details,
&mut labs.parakeet_ultra,
&mut labs.standalone_special_keys,
&mut labs.history_stats,
&mut labs.recent_dictations,
&mut labs.skip_pauses,
&mut labs.stop_when_call_ends,
&mut labs.output_fixes,
&mut labs.picker_active_first,
&mut labs.model_in_place,
&mut labs.picker_downloaded,
&mut labs.section_key_alone,
&mut labs.keep_recordings,
&mut labs.hide_menu_bar_icon,
]
}
/// The managed lock that holds this feature off, if any.
pub fn managed(self) -> Option<crate::policy::Lock> {
crate::policy::Policy::current().labs_lock(self)
}
pub fn set(self, settings: &mut AppSettings, on: bool) {
match self {
Self::Meetings => settings.meetings.enabled = on,
Self::VoiceFilter => settings.experimental.hex_microphone = on,
Self::Playground => settings.labs.playground = on,
Self::LiveText => settings.labs.live_text = on,
Self::LiveChapters => settings.labs.live_chapters = on,
Self::VocabularyBiasing => settings.labs.vocabulary_biasing = on,
Self::TerminalPaste => settings.paste_with_shift = on,
Self::KeyboardModelSwitching => settings.keyboard_model_switching.enabled = on,
Self::MouseShortcuts => settings.labs.mouse_shortcuts = on,
Self::PauseBrowser => settings.pause_browser_media = on,
Self::ShareShortcut => settings.share_dictation_shortcut = on,
Self::UnloadIdle => settings.labs.unload_idle = on,
Self::RestoreShortcutDefault => settings.labs.restore_shortcut_default = on,
Self::KeepOnClipboard => settings.labs.keep_on_clipboard = on,
Self::CopyOnly => settings.labs.copy_only = on,
Self::SpokenFormatting => settings.labs.spoken_formatting = on,
Self::FillerWords => settings.labs.filler_words = on,
Self::SubtitleExport => settings.labs.subtitle_export = on,
Self::SecondDictationShortcut => settings.labs.second_dictation_shortcut = on,
Self::SmartSpacing => settings.labs.smart_spacing = on,
Self::SpokenSymbols => settings.labs.spoken_symbols = on,
Self::PickerSortFilter => settings.labs.picker_sort_filter = on,
Self::SidedChords => settings.labs.sided_modifier_chords = on,
Self::TapOrHold => settings.labs.tap_or_hold = on,
Self::BenchmarkDetails => settings.labs.benchmark_details = on,
Self::ParakeetUltra => settings.labs.parakeet_ultra = on,
Self::HistoryStats => settings.labs.history_stats = on,
Self::RecentDictations => settings.labs.recent_dictations = on,
Self::SkipPauses => settings.labs.skip_pauses = on,
Self::StopWhenCallEnds => settings.labs.stop_when_call_ends = on,
Self::OutputFixes => settings.labs.output_fixes = on,
Self::PickerActiveFirst => settings.labs.picker_active_first = on,
Self::ModelInPlace => settings.labs.model_in_place = on,
Self::PickerDownloaded => settings.labs.picker_downloaded = on,
Self::KeepRecordings => settings.labs.keep_recordings = on,
Self::HideMenuBarIcon => settings.labs.hide_menu_bar_icon = on,
// Off, no shortcut keeps a key only the feature allows.
Self::StandaloneSpecialKeys => {
settings.labs.standalone_special_keys = on;
settings.repair_special_keys();
}
Self::SectionKeyAlone => {
settings.labs.section_key_alone = on;
settings.repair_section_key();
}
}
}
}
/// Set once this process knows its settings.
const KNOWN: u64 = 1;
const LIVE_TEXT: u64 = 1 << 1;
const LIVE_CHAPTERS: u64 = 1 << 2;
const PLAYGROUND: u64 = 1 << 3;
const VOCABULARY_BIASING: u64 = 1 << 4;
const MOUSE_SHORTCUTS: u64 = 1 << 5;
const UNLOAD_IDLE: u64 = 1 << 6;
const KEEP_ON_CLIPBOARD: u64 = 1 << 7;
const COPY_ONLY: u64 = 1 << 8;
const SPOKEN_FORMATTING: u64 = 1 << 9;
const FILLER_WORDS: u64 = 1 << 10;
const SUBTITLE_EXPORT: u64 = 1 << 11;
const SMART_SPACING: u64 = 1 << 12;
const SPOKEN_SYMBOLS: u64 = 1 << 13;
const SIDED_CHORDS: u64 = 1 << 14;
const TAP_OR_HOLD: u64 = 1 << 15;
const SKIP_PAUSES: u64 = 1 << 16;
const PARAKEET_ULTRA: u64 = 1 << 17;
const HISTORY_STATS: u64 = 1 << 18;
const RECENT_DICTATIONS: u64 = 1 << 19;
const STOP_WHEN_CALL_ENDS: u64 = 1 << 20;
const KEEP_RECORDINGS: u64 = 1 << 21;
const HIDE_MENU_BAR_ICON: u64 = 1 << 22;
/// Unload-idle minutes (at most 1,440, 11 bits) sit above the switches.
const MINUTES_SHIFT: u64 = 32;
/// This process's `labs` switches: unknown until settings load or one is
/// first read.
static STATE: AtomicU64 = AtomicU64::new(0);
fn on(bit: u64) -> bool {
state() & bit != 0
}
fn state() -> u64 {
match STATE.load(Ordering::Acquire) {
0 => {
let saved = encode(&AppSettings::saved_labs());
let _ = STATE.compare_exchange(0, saved, Ordering::AcqRel, Ordering::Acquire);
STATE.load(Ordering::Acquire)
}
state => state,
}
}
/// Live text: provisional words beside the HUD (read as each dictation starts).
pub fn live_text() -> bool {
on(LIVE_TEXT)
}
/// Live chapters while a meeting records.
pub fn live_chapters() -> bool {
on(LIVE_CHAPTERS)
}
/// The playground in the window.
pub fn playground() -> bool {
on(PLAYGROUND)
}
/// Transcription biased toward the vocabulary (Parakeet).
pub fn vocabulary_biasing() -> bool {
on(VOCABULARY_BIASING)
}
/// Mouse buttons may be recorded as shortcuts (macOS).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn mouse_shortcuts() -> bool {
on(MOUSE_SHORTCUTS)
}
/// A pasted dictation stays on the clipboard rather than the previous
/// clipboard being restored (macOS; read as each paste commits).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn keep_on_clipboard() -> bool {
on(KEEP_ON_CLIPBOARD)
}
/// A dictation goes to the clipboard and is never pasted (macOS; read as
/// each dictation's output commits).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn copy_only() -> bool {
on(COPY_ONLY)
}
/// Spoken formatting phrases become line breaks and quotation marks (read
/// as each dictation's processing starts).
pub fn spoken_formatting() -> bool {
on(SPOKEN_FORMATTING)
}
/// Spoken punctuation and symbol words become characters joined to their
/// neighbours (read as each dictation's processing starts).
pub fn spoken_symbols() -> bool {
on(SPOKEN_SYMBOLS)
}
/// Filler words such as "um" and "uh" leave dictations (read as each
/// dictation's processing starts).
pub fn filler_words() -> bool {
on(FILLER_WORDS)
}
/// `hex meetings show --srt|--vtt` may export subtitles (read when the
/// command starts).
pub fn subtitle_export() -> bool {
on(SUBTITLE_EXPORT)
}
/// A pasted dictation gets one leading space when the character before the
/// cursor asks for one (macOS; read as each paste commits).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn smart_spacing() -> bool {
on(SMART_SPACING)
}
/// The shortcut recorder keeps each modifier's side in a modifier-only
/// chord of two or more keys (macOS; read as each recording starts).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn sided_modifier_chords() -> bool {
on(SIDED_CHORDS)
}
/// In Toggle mode, a press held past the hold threshold finishes its capture
/// when it lifts instead of locking it (macOS; read at each release).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn tap_or_hold() -> bool {
on(TAP_OR_HOLD)
}
/// Parakeet Ultra joins the catalog (read wherever a model is listed,
/// chosen, or run).
pub fn parakeet_ultra() -> bool {
on(PARAKEET_ULTRA)
}
/// History's summary of retained dictations and `hex history stats` (read
/// when the History pane reloads and when the command starts).
pub fn history_stats() -> bool {
on(HISTORY_STATS)
}
/// The menu bar's Copy Recent Dictation submenu (macOS; read each time the
/// menu opens).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn recent_dictations() -> bool {
on(RECENT_DICTATIONS)
}
/// A whole-clip dictation transcription hears only the head and tail of
/// each long pause (Linux and Windows; read as each whole-clip run starts).
#[cfg_attr(target_os = "macos", allow(dead_code))]
pub fn skip_pauses() -> bool {
on(SKIP_PAUSES) && Feature::SkipPauses.on_this_os()
}
/// A meeting recording Hex started on its own stops once its call app has
/// left the microphone and gone quiet for a grace period (macOS; read on
/// each pass of the meeting controller).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn stop_when_call_ends() -> bool {
on(STOP_WHEN_CALL_ENDS) && Feature::StopWhenCallEnds.on_this_os()
}
/// A dictation saved to History keeps its 16 kHz audio, and History offers
/// Transcribe again for it (read as each capture is handed to the engine;
/// the History pane reads the saved setting).
pub fn keep_recordings() -> bool {
on(KEEP_RECORDINGS)
}
/// The menu-bar icon is hidden while nothing records (macOS; read each
/// time the status item refreshes, about twice a second).
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn hide_menu_bar_icon() -> bool {
on(HIDE_MENU_BAR_ICON) && Feature::HideMenuBarIcon.on_this_os()
}
/// How long the speech model may sit unused before the engine unloads it,
/// while Labs › Unload model when idle is on.
pub fn unload_idle() -> Option<std::time::Duration> {
let state = state();
(state & UNLOAD_IDLE != 0)
.then(|| std::time::Duration::from_secs((state >> MINUTES_SHIFT) * 60))
}
/// Records the switches the loaded or saved settings hold.
pub(crate) fn apply(settings: &LabsSettings) {
STATE.store(encode(settings), Ordering::Release);
}
fn encode(settings: &LabsSettings) -> u64 {
let policy = crate::policy::Policy::current();
encode_where(settings, |feature| {
feature.shipped() && policy.labs_lock(feature).is_none()
})
}
/// The switches `settings` hold for the features `reaches` admits; the
/// rest read off while their saved setting stays as it is.
fn encode_where(settings: &LabsSettings, reaches: impl Fn(Feature) -> bool) -> u64 {
let minutes = u64::from(settings.unload_idle_minutes.clamp(1, 24 * 60)) << MINUTES_SHIFT;
[
(Feature::LiveText, settings.live_text, LIVE_TEXT),
(Feature::LiveChapters, settings.live_chapters, LIVE_CHAPTERS),
(Feature::Playground, settings.playground, PLAYGROUND),
(
Feature::VocabularyBiasing,
settings.vocabulary_biasing,
VOCABULARY_BIASING,
),
(
Feature::MouseShortcuts,
settings.mouse_shortcuts,
MOUSE_SHORTCUTS,
),
(Feature::UnloadIdle, settings.unload_idle, UNLOAD_IDLE),
(
Feature::KeepOnClipboard,
settings.keep_on_clipboard,
KEEP_ON_CLIPBOARD,
),
(Feature::CopyOnly, settings.copy_only, COPY_ONLY),
(
Feature::SpokenFormatting,
settings.spoken_formatting,
SPOKEN_FORMATTING,
),
(Feature::FillerWords, settings.filler_words, FILLER_WORDS),
(
Feature::SubtitleExport,
settings.subtitle_export,
SUBTITLE_EXPORT,
),
(Feature::SmartSpacing, settings.smart_spacing, SMART_SPACING),
(
Feature::SpokenSymbols,
settings.spoken_symbols,
SPOKEN_SYMBOLS,
),
(
Feature::SidedChords,
settings.sided_modifier_chords,
SIDED_CHORDS,
),
(Feature::TapOrHold, settings.tap_or_hold, TAP_OR_HOLD),
(
Feature::ParakeetUltra,
settings.parakeet_ultra,
PARAKEET_ULTRA,
),
(Feature::HistoryStats, settings.history_stats, HISTORY_STATS),
(
Feature::RecentDictations,
settings.recent_dictations,
RECENT_DICTATIONS,
),
(Feature::SkipPauses, settings.skip_pauses, SKIP_PAUSES),
(
Feature::StopWhenCallEnds,
settings.stop_when_call_ends,
STOP_WHEN_CALL_ENDS,
),
(
Feature::KeepRecordings,
settings.keep_recordings,
KEEP_RECORDINGS,
),
(
Feature::HideMenuBarIcon,
settings.hide_menu_bar_icon,
HIDE_MENU_BAR_ICON,
),
]
.into_iter()
.filter(|(feature, on, _)| *on && reaches(*feature))
.fold(KNOWN | minutes, |state, (_, _, bit)| state | bit)
}
/// The names of the features on, for `hex status`.
pub fn active_names(settings: &AppSettings) -> Vec<String> {
Feature::available()
.filter(|feature| feature.on(settings))
.map(|feature| feature.name().into())
.collect()
}
/// Logs the switches to process.log; call once logging is up in a long-lived Hex.
pub fn log_launch() {
tracing::info!(
live_text = live_text(),
live_chapters = live_chapters(),
playground = playground(),
vocabulary_biasing = vocabulary_biasing(),
"labs"
);
}
#[derive(Debug, Subcommand)]
pub enum LabsCommand {
/// List every Labs feature and whether it is on (the default).
List,
/// Turn a Labs feature on.
On { feature: String },
/// Turn a Labs feature off.
Off { feature: String },
/// Print the link that opens Hex's Labs page at a feature's row (macOS).
#[cfg(target_os = "macos")]
Link { feature: String },
}
/// `hex labs`: edits `settings.json`; a running Hex applies most changes
/// when it next starts.
pub fn run(command: Option<&LabsCommand>) -> Result<()> {
#[cfg(target_os = "macos")]
if let Some(LabsCommand::Link { feature }) = command {
println!(
"{}",
crate::rune_ui::deep_link::labs_link(
crate::rune_ui::story_link::scheme(),
resolve(feature, Feature::shipped)?
)
);
return Ok(());
}
// Listing, or handing the change to a running Hex, never writes the file.
let settings = AppSettings::read()?;
let (name, on) = match command {
None | Some(LabsCommand::List) => {
print!("{}", list(&settings));
return Ok(());
}
#[cfg(target_os = "macos")]
Some(LabsCommand::Link { .. }) => unreachable!("handled above"),
Some(LabsCommand::On { feature }) => (feature, true),
Some(LabsCommand::Off { feature }) => (feature, false),
};
if let Some((_, note)) = GRADUATED.iter().find(|(graduated, _)| *graduated == name) {
println!("{note}");
return Ok(());
}
let feature = resolve(name, Feature::shipped)?;
if let Some(lock) = feature.managed() {
return Err(eyre!(lock.refusal()));
}
if feature == Feature::VoiceFilter
&& !on
&& crate::audio::hex_microphone::driver_bundle_installed()
{
return Err(eyre!(
"voice-filter stays on while the Hex Microphone driver is installed; uninstall the driver in its pane to turn it off"
));
}
if !on && let Some(why) = feature.off_refusal(&settings) {
return Err(eyre!(why));
}
let state = if on { "on" } else { "off" };
// A running Hex saves and applies it at once, as its Labs row would.
if let Some(reply) = crate::control::cli::set_in_running_hex(
feature.settings_key(),
if on { "true" } else { "false" },
) {
return match reply {
crate::control::ControlReply::Error { message, .. } => Err(eyre!("{message}")),
_ => {
println!("Turned {} {state}.", feature.name());
Ok(())
}
};
}
let mut settings = AppSettings::load()?;
if feature.on(&settings) == on {
println!("{} is already {state}.", feature.name());
return Ok(());
}
feature.set(&mut settings, on);
settings.save()?;
println!("Turned {} {state}.", feature.name());
Ok(())
}
/// The feature `name` names, if this OS has it and `reaches` admits it.
/// Features that left Labs: `hex labs` still knows their names.
const GRADUATED: [(&str, &str); 1] = [(
"custom-models",
"custom-models graduated: adding a model file and models found on this computer are always on now",
)];
fn resolve(name: &str, reaches: impl Fn(Feature) -> bool + Copy) -> Result<Feature> {
if let Some((_, note)) = GRADUATED.iter().find(|(graduated, _)| *graduated == name) {