-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmain.rs
More file actions
826 lines (802 loc) · 27.2 KB
/
Copy pathmain.rs
File metadata and controls
826 lines (802 loc) · 27.2 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
#[cfg(target_os = "macos")]
mod accessibility;
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod app_paths;
#[cfg(target_os = "macos")]
mod app_settings;
#[cfg(target_os = "macos")]
mod app_window;
#[cfg(target_os = "macos")]
mod apple_speech;
#[cfg(target_os = "macos")]
mod application_catalog;
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod audio;
#[cfg(target_os = "macos")]
mod command_grammar;
#[cfg(target_os = "macos")]
mod commands;
#[cfg(target_os = "macos")]
mod config;
#[cfg(target_os = "macos")]
mod context;
#[cfg(all(debug_assertions, target_os = "macos"))]
mod dashboard;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod desktop_activity;
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod desktop_host;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod desktop_transcription_picker;
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod desktop_ui;
#[cfg(target_os = "macos")]
mod developer_control;
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod dictation;
#[cfg(target_os = "macos")]
mod dictation_audio;
#[cfg(target_os = "macos")]
mod dictation_diagnostics;
#[cfg(target_os = "macos")]
mod dictation_indicator;
#[cfg(target_os = "macos")]
pub mod dictation_processor;
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod events;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod feedback;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod gguf_session;
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod history;
mod instance;
#[cfg(target_os = "macos")]
mod keyboard;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
mod linux_app;
#[cfg(target_os = "linux")]
mod linux_desktop;
#[cfg(target_os = "linux")]
mod linux_dictation;
#[cfg(target_os = "linux")]
mod linux_input;
#[cfg(target_os = "linux")]
mod linux_paste;
#[cfg(target_os = "linux")]
mod linux_service;
#[cfg(target_os = "linux")]
mod linux_session;
#[cfg(target_os = "linux")]
mod linux_settings;
#[cfg(target_os = "linux")]
mod linux_transcriber;
#[cfg(target_os = "linux")]
mod linux_updater;
#[cfg(target_os = "linux")]
mod linux_wayland_input;
#[cfg(target_os = "macos")]
mod local_api;
#[cfg(target_os = "macos")]
mod login_item;
#[cfg(target_os = "macos")]
mod meeting;
#[cfg(target_os = "macos")]
mod meeting_detection;
#[cfg(target_os = "macos")]
mod meeting_watcher;
#[cfg(target_os = "macos")]
mod microphone_activity;
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod moonshine;
#[cfg(all(target_os = "macos", debug_assertions))]
mod moonshine_lab;
#[cfg(target_os = "macos")]
mod onboarding;
#[cfg(target_os = "macos")]
mod parakeet;
#[cfg(target_os = "macos")]
mod paste;
#[cfg(target_os = "macos")]
mod permission_guide;
#[cfg(target_os = "macos")]
mod personal_commands;
#[cfg(target_os = "macos")]
mod recognition;
#[cfg(target_os = "macos")]
mod recording_environment;
#[cfg(target_os = "macos")]
mod sparkle;
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod spoken_text;
#[cfg(target_os = "macos")]
mod status_item;
#[cfg(target_os = "macos")]
mod suppression;
#[cfg(target_os = "macos")]
mod text_input;
#[cfg(target_os = "macos")]
mod text_replacements;
#[cfg(target_os = "macos")]
mod transcription;
#[cfg(target_os = "macos")]
mod transcription_benchmark;
#[cfg_attr(target_os = "linux", allow(dead_code))]
mod transcription_models;
#[cfg(target_os = "macos")]
mod transcription_preparation;
#[cfg(target_os = "macos")]
mod transcription_service;
#[cfg(target_os = "macos")]
use std::fs::{self, OpenOptions};
#[cfg(target_os = "macos")]
use std::io::{Read, Write};
#[cfg(target_os = "macos")]
use std::path::PathBuf;
#[cfg(target_os = "macos")]
use std::sync::Mutex;
use std::sync::atomic::AtomicBool;
#[cfg(target_os = "macos")]
use std::sync::atomic::Ordering;
#[cfg(target_os = "macos")]
use clap::{Parser, Subcommand, ValueEnum};
use color_eyre::Result;
#[cfg(target_os = "macos")]
use color_eyre::eyre::eyre;
#[cfg(target_os = "macos")]
use tracing_subscriber::fmt::writer::MakeWriterExt;
#[cfg(target_os = "macos")]
#[derive(Parser)]
#[command(version, about = "Local, observable voice control")]
struct Cli {
#[command(subcommand)]
command: Option<Command>,
}
static SHUTDOWN: AtomicBool = AtomicBool::new(false);
#[cfg(target_os = "macos")]
pub(crate) const DEVELOPER_FEATURES_ENABLED: bool = cfg!(debug_assertions);
#[cfg(target_os = "macos")]
#[derive(Subcommand)]
enum Command {
/// Run the GPUI desktop app with local dictation.
App {
/// Override the configured microphone preference order.
#[arg(long)]
device: Option<String>,
/// Preview the dictation HUD without starting recognition.
#[arg(long)]
preview_dictation: bool,
},
/// Launch an isolated, deterministic UI preview without app services.
Preview {
/// Production UI surface to open.
#[arg(value_enum)]
target: AppPreviewTarget,
/// Language selected in the transcription picker.
#[arg(long, default_value = "en")]
language: String,
/// Deterministic model installation state shown by the picker.
#[arg(long, value_enum, default_value = "actual")]
model_state: AppPreviewModelState,
/// Collapse OpenCode settings in the representative Modes preview.
#[arg(long)]
collapse_mode_processing: bool,
/// Open the transformation picker in the representative Modes preview.
#[arg(long)]
open_transformation_picker: bool,
/// Select the Global row in the representative Modes preview.
#[arg(long)]
select_global_mode: bool,
/// Enable Voice Action in the preview; it is off by default.
#[arg(long)]
voice_action_enabled: bool,
/// Preview OpenCode-dependent controls without an available installation.
#[arg(long)]
opencode_unavailable: bool,
/// Show missing post-onboarding permissions in Settings.
#[arg(long)]
permissions_missing: bool,
/// Show the selected dictation model as missing without changing local files.
#[arg(long)]
model_missing: bool,
/// Show command-model recovery while dictation remains ready.
#[arg(long)]
command_model_missing: bool,
/// Open the explicit history retention choices in the History preview.
#[arg(long)]
open_history_retention: bool,
/// Show the idle microphone release confirmation with Commands enabled.
#[arg(long)]
confirm_release_microphone: bool,
/// Show the sidebar update action without starting the updater.
#[arg(long)]
update_available: bool,
},
/// Listen and transcribe until interrupted.
Listen {
/// Override the configured microphone preference order.
#[arg(long)]
device: Option<String>,
},
/// Manage the personal command workspace.
Commands {
#[command(subcommand)]
command: CommandsCommand,
},
/// Run the headless local API service.
#[command(hide = true)]
Service {
/// Run as a direct child whose stdin is owned by the host application.
#[arg(long)]
embedded: bool,
},
#[cfg(debug_assertions)]
/// Show the developer recognition dashboard.
Status,
#[cfg(debug_assertions)]
/// Inspect and control the running desktop app.
Dev {
#[command(subcommand)]
command: DevCommand,
},
#[cfg(debug_assertions)]
/// Record, transcribe, and browse local meetings.
Meeting {
#[command(subcommand)]
command: MeetingCommand,
},
/// Measure the local transcription runtime against a fixed WAV corpus.
#[command(hide = true)]
BenchmarkTranscription {
/// JSON manifest containing audio paths and reference transcripts.
manifest: PathBuf,
/// Runtime to measure.
#[arg(long, value_enum, default_value = "transcribe-cpp")]
backend: TranscriptionBenchmarkBackend,
/// Override the default GGUF model path for the transcribe.cpp backend.
#[arg(long)]
model: Option<PathBuf>,
/// Full-corpus passes discarded before measurement.
#[arg(long, default_value_t = 1)]
warmups: usize,
/// Full-corpus measured passes.
#[arg(long, default_value_t = 7)]
runs: usize,
},
#[cfg(debug_assertions)]
/// Record and evaluate command-recognition fixtures interactively.
MoonshineLab {
/// Corpus directory containing manifest.json and audio/*.wav.
#[arg(default_value = "perf/moonshine-corpus")]
directory: PathBuf,
/// Override the configured microphone preference order.
#[arg(long)]
device: Option<String>,
/// Evaluate every recorded fixture across every Moonshine profile.
#[arg(long)]
batch: bool,
},
}
#[cfg(target_os = "macos")]
#[derive(Clone, Copy, ValueEnum)]
enum TranscriptionBenchmarkBackend {
Onnx,
TranscribeCpp,
}
#[cfg(target_os = "macos")]
#[derive(Subcommand)]
enum CommandsCommand {
/// Create or refresh ~/.config/hex and install its pinned dependencies.
Init,
}
#[cfg(debug_assertions)]
#[cfg(target_os = "macos")]
#[derive(Subcommand)]
enum DevCommand {
/// Inspect the running app and window state.
Status,
/// Drive a deterministic HUD state.
Hud {
#[arg(value_enum)]
state: DevHudState,
},
/// Open the app and select a pane.
Show {
#[arg(value_enum)]
pane: DevPane,
},
/// Enable or disable voice commands.
Commands {
#[arg(value_enum)]
state: DevToggle,
},
}
#[cfg(debug_assertions)]
#[cfg(target_os = "macos")]
#[derive(Clone, Copy, ValueEnum)]
enum DevHudState {
Reset,
Recording,
Transcribing,
Processing,
}
#[cfg(debug_assertions)]
#[cfg(target_os = "macos")]
#[derive(Clone, Copy, ValueEnum)]
enum DevPane {
Settings,
Modes,
VoiceAction,
Replacements,
HudLab,
Commands,
Meetings,
Activity,
}
#[cfg(debug_assertions)]
#[cfg(target_os = "macos")]
#[derive(Clone, Copy, ValueEnum)]
enum DevToggle {
On,
Off,
}
#[cfg(target_os = "macos")]
#[derive(Clone, Copy, ValueEnum)]
enum AppPreviewTarget {
DictationHud,
HudLab,
Onboarding,
Settings,
Modes,
VoiceAction,
Replacements,
Commands,
Meetings,
Activity,
History,
TranscriptionPicker,
}
#[cfg(target_os = "macos")]
#[derive(Clone, Copy, ValueEnum)]
enum AppPreviewModelState {
Actual,
Installed,
Missing,
Downloading,
Error,
}
#[cfg(debug_assertions)]
#[cfg(target_os = "macos")]
#[derive(Subcommand)]
enum MeetingCommand {
/// Record microphone and system audio until Ctrl-C.
Record {
/// Human-readable meeting title.
#[arg(long)]
title: Option<String>,
},
/// List recorded meetings.
List,
/// Print one meeting transcript.
Show { id: String },
/// Watch supported meeting applications and offer local recording.
Watch {
/// Show a non-recording UI preview immediately.
#[arg(long)]
preview: bool,
},
/// Print applications currently using microphone input.
Probe,
}
#[cfg(target_os = "macos")]
fn main() -> Result<()> {
color_eyre::install()?;
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let log_dir = app_paths::logs_dir()?;
fs::create_dir_all(&log_dir)?;
let process_log = OpenOptions::new()
.create(true)
.append(true)
.open(log_dir.join("process.log"))?;
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("voice_control=info"));
tracing_subscriber::fmt()
.with_env_filter(filter)
.with_writer(std::io::stderr.and(Mutex::new(process_log)))
.init();
ctrlc::set_handler(|| SHUTDOWN.store(true, Ordering::Relaxed))?;
let event_path = log_dir.join("live.ndjson");
let cli = Cli::parse();
let executable_name = std::env::current_exe()
.ok()
.and_then(|path| path.file_stem().map(ToOwned::to_owned));
let bundled_watcher = is_bundled_app_executable(executable_name.as_deref());
let bundled_service = executable_name.as_deref() == Some(std::ffi::OsStr::new("hex-service"));
let command = cli.command.unwrap_or({
if bundled_watcher {
Command::App {
device: None,
preview_dictation: false,
}
} else if bundled_service {
Command::Service { embedded: false }
} else {
Command::Listen { device: None }
}
});
match command {
Command::App {
device,
preview_dictation,
} => {
let _instance = instance::acquire("listener")?;
meeting_watcher::run(
&SHUTDOWN,
false,
(!preview_dictation).then_some(meeting_watcher::ListenerConfig {
project_root: root,
event_path,
device,
}),
preview_dictation,
)
}
Command::Preview {
target,
language,
model_state,
collapse_mode_processing,
open_transformation_picker,
select_global_mode,
voice_action_enabled,
opencode_unavailable,
permissions_missing,
model_missing,
command_model_missing,
open_history_retention,
confirm_release_microphone,
update_available,
} => {
if matches!(target, AppPreviewTarget::DictationHud) {
return meeting_watcher::run(&SHUTDOWN, false, None, true);
}
if !transcription_models::LANGUAGES
.iter()
.any(|(code, _)| *code == language)
{
return Err(eyre!("unsupported preview language: {language}"));
}
let pane = match target {
AppPreviewTarget::HudLab => app_window::PreviewPane::HudLab,
AppPreviewTarget::Onboarding
| AppPreviewTarget::Settings
| AppPreviewTarget::TranscriptionPicker => app_window::PreviewPane::Settings,
AppPreviewTarget::Modes => app_window::PreviewPane::Modes,
AppPreviewTarget::VoiceAction => app_window::PreviewPane::VoiceAction,
AppPreviewTarget::Replacements => app_window::PreviewPane::Replacements,
AppPreviewTarget::Commands => app_window::PreviewPane::Commands,
AppPreviewTarget::Meetings => app_window::PreviewPane::Meetings,
AppPreviewTarget::Activity => app_window::PreviewPane::Activity,
AppPreviewTarget::History => app_window::PreviewPane::History,
AppPreviewTarget::DictationHud => unreachable!(),
};
let model_state = match model_state {
AppPreviewModelState::Actual => app_window::PreviewModelState::Actual,
AppPreviewModelState::Installed => app_window::PreviewModelState::Installed,
AppPreviewModelState::Missing => app_window::PreviewModelState::Missing,
AppPreviewModelState::Downloading => app_window::PreviewModelState::Downloading,
AppPreviewModelState::Error => app_window::PreviewModelState::Error,
};
meeting_watcher::preview_shell(
&SHUTDOWN,
app_window::AppWindowPreview {
pane,
transcription_picker: matches!(target, AppPreviewTarget::TranscriptionPicker)
.then_some((language, model_state)),
onboarding: matches!(target, AppPreviewTarget::Onboarding),
collapse_mode_processing,
open_transformation_picker,
select_global_mode,
voice_action_enabled,
opencode_unavailable,
permissions_missing,
model_missing,
command_model_missing,
open_history_retention,
confirm_release_microphone,
update_available,
},
)
}
Command::Listen { device } => {
let _instance = instance::acquire("listener")?;
let settings = app_settings::AppSettings::load()?;
let events = events::EventLog::create(&event_path)?;
let history = match history::History::open_default(settings.history_retention) {
Ok(history) => Some(history),
Err(error) => {
tracing::warn!(%error, "dictation history is unavailable");
None
}
};
recognition::listen(
&root,
events,
device.as_deref(),
config::voice_control(),
&SHUTDOWN,
None,
None,
history,
None,
)
}
Command::Service { embedded } => {
if !embedded {
app_settings::AppSettings::load()?;
}
let service_event_path = if embedded {
log_dir.join(format!("embedded-{}.ndjson", std::process::id()))
} else {
event_path
};
let events = events::EventLog::create(&service_event_path)?;
let local_api = if embedded {
let api = local_api::LocalApi::start_embedded(events)?;
std::thread::Builder::new()
.name("embedded-host-lease".into())
.spawn(|| {
let mut stdin = std::io::stdin().lock();
let mut buffer = [0_u8; 1];
loop {
match stdin.read(&mut buffer) {
Ok(0) => {
SHUTDOWN.store(true, Ordering::Release);
std::thread::sleep(std::time::Duration::from_secs(5));
tracing::warn!(
"forcing embedded service shutdown after host lease closed"
);
std::process::exit(0);
}
Ok(_) => {}
Err(error) if error.kind() == std::io::ErrorKind::Interrupted => {}
Err(error) => {
tracing::warn!(%error, "embedded host lease failed");
SHUTDOWN.store(true, Ordering::Release);
break;
}
}
}
})?;
let mut stdout = std::io::stdout().lock();
serde_json::to_writer(&mut stdout, &api.embedded_endpoint())?;
stdout.write_all(b"\n")?;
stdout.flush()?;
drop(stdout);
api
} else {
local_api::LocalApi::start(events)?
};
while !SHUTDOWN.load(Ordering::Relaxed) {
std::thread::sleep(std::time::Duration::from_millis(100));
}
drop(local_api);
if embedded
&& let Err(error) = fs::remove_file(&service_event_path)
&& error.kind() != std::io::ErrorKind::NotFound
{
tracing::warn!(%error, "could not remove embedded service event log");
}
Ok(())
}
Command::Commands {
command: CommandsCommand::Init,
} => {
let workspace = personal_commands::initialize_workspace()?;
println!("{}", workspace.display());
Ok(())
}
#[cfg(debug_assertions)]
Command::Status => dashboard::run(event_path, config::voice_control()),
#[cfg(debug_assertions)]
Command::Dev { command } => {
use developer_control::{
DeveloperCommand, DeveloperHudState as RpcHudState, DeveloperPane as RpcPane,
DeveloperReply,
};
let command = match command {
DevCommand::Status => DeveloperCommand::Status,
DevCommand::Hud { state } => DeveloperCommand::Hud {
state: match state {
DevHudState::Reset => RpcHudState::Reset,
DevHudState::Recording => RpcHudState::Recording,
DevHudState::Transcribing => RpcHudState::Transcribing,
DevHudState::Processing => RpcHudState::Processing,
},
},
DevCommand::Show { pane } => DeveloperCommand::ShowPane {
pane: match pane {
DevPane::Settings => RpcPane::Settings,
DevPane::Modes => RpcPane::Modes,
DevPane::VoiceAction => RpcPane::VoiceAction,
DevPane::Replacements => RpcPane::Replacements,
DevPane::HudLab => RpcPane::HudLab,
DevPane::Commands => RpcPane::Commands,
DevPane::Meetings => RpcPane::Meetings,
DevPane::Activity => RpcPane::Activity,
},
},
DevCommand::Commands { state } => DeveloperCommand::SetCommandsEnabled {
enabled: matches!(state, DevToggle::On),
},
};
let reply = local_api::call_developer(&command)?;
if let DeveloperReply::Error { code, message } = &reply {
return Err(eyre!("{code}: {message}"));
}
println!("{}", serde_json::to_string_pretty(&reply)?);
Ok(())
}
#[cfg(debug_assertions)]
Command::Meeting {
command: MeetingCommand::Record { title },
} => {
app_settings::AppSettings::load()?;
meeting::record(title, &SHUTDOWN, &root, None).map(|_| ())
}
#[cfg(debug_assertions)]
Command::Meeting {
command: MeetingCommand::List,
} => {
for meeting in meeting::list()? {
println!(
"{}\t{:?}\t{}ms\t{}",
meeting.id,
meeting.status,
meeting.duration_ms.unwrap_or_default(),
meeting.title
);
}
Ok(())
}
#[cfg(debug_assertions)]
Command::Meeting {
command: MeetingCommand::Show { id },
} => {
print!("{}", meeting::show(&id)?);
Ok(())
}
#[cfg(debug_assertions)]
Command::Meeting {
command: MeetingCommand::Watch { preview },
} => meeting_watcher::run(&SHUTDOWN, preview, None, false),
#[cfg(debug_assertions)]
Command::Meeting {
command: MeetingCommand::Probe,
} => meeting_watcher::probe(),
Command::BenchmarkTranscription {
manifest,
backend,
model,
warmups,
runs,
} => {
let backend = match backend {
TranscriptionBenchmarkBackend::Onnx => transcription_benchmark::Backend::Onnx,
TranscriptionBenchmarkBackend::TranscribeCpp => {
transcription_benchmark::Backend::TranscribeCpp {
model: match model {
Some(model) => model,
None => parakeet::default_model_path()?,
},
}
}
};
transcription_benchmark::run(&manifest, warmups, runs, backend)
}
#[cfg(debug_assertions)]
Command::MoonshineLab {
directory,
device,
batch,
} => match batch {
true => moonshine_lab::run_batch(&root, &directory),
false => moonshine_lab::run(&root, &directory, device.as_deref()),
},
}
}
#[cfg(target_os = "macos")]
fn is_bundled_app_executable(name: Option<&std::ffi::OsStr>) -> bool {
name.is_some_and(|name| name == "voice-control-watch" || name == "hex")
}
#[cfg(all(test, target_os = "macos"))]
mod tests {
use super::{Cli, Command, is_bundled_app_executable};
use clap::Parser;
#[test]
fn voice_action_preview_requires_explicit_opt_in() {
let cli = Cli::try_parse_from(["hex", "preview", "voice-action"]).unwrap();
assert!(matches!(
cli.command,
Some(Command::Preview {
voice_action_enabled: false,
opencode_unavailable: false,
..
})
));
let cli = Cli::try_parse_from([
"hex",
"preview",
"voice-action",
"--voice-action-enabled",
"--opencode-unavailable",
])
.unwrap();
assert!(matches!(
cli.command,
Some(Command::Preview {
voice_action_enabled: true,
opencode_unavailable: true,
..
})
));
}
#[test]
fn microphone_confirmation_requires_an_explicit_preview_flag() {
for (args, expected) in [
(vec!["hex", "preview", "settings"], false),
(
vec!["hex", "preview", "settings", "--confirm-release-microphone"],
true,
),
] {
let cli = Cli::try_parse_from(args).unwrap();
let Some(Command::Preview {
confirm_release_microphone,
..
}) = cli.command
else {
panic!("expected preview command");
};
assert_eq!(confirm_release_microphone, expected);
}
assert!(Cli::try_parse_from(["hex", "app", "--confirm-release-microphone"]).is_err());
}
#[test]
fn available_update_requires_an_explicit_preview_flag() {
for (args, expected) in [
(vec!["hex", "preview", "settings"], false),
(
vec!["hex", "preview", "settings", "--update-available"],
true,
),
] {
let cli = Cli::try_parse_from(args).unwrap();
let Some(Command::Preview {
update_available, ..
}) = cli.command
else {
panic!("expected preview command");
};
assert_eq!(update_available, expected);
}
assert!(Cli::try_parse_from(["hex", "app", "--update-available"]).is_err());
}
#[test]
fn both_packaged_executable_names_launch_the_app() {
assert!(is_bundled_app_executable(Some(
"voice-control-watch".as_ref()
)));
assert!(is_bundled_app_executable(Some("hex".as_ref())));
assert!(!is_bundled_app_executable(Some("voice-control".as_ref())));
assert!(!is_bundled_app_executable(Some("hex-service".as_ref())));
}
}
#[cfg(target_os = "linux")]
fn main() -> Result<()> {
linux::run(&SHUTDOWN)
}