mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* feat(i18n): translate every shared window string and offer Interface language on every OS Settings, Modes, Voice Action, History, Commands, Meetings, permissions, the model picker, the Windows tray, and the Linux HUD now translate into Polish, Chinese, Japanese, German, and Spanish. Templates with values use tr_fill and the new tr_named, so each language orders them itself. A test reads the shared sources and fails if any translated string lacks a language. AppSettings applies the interface language in every process, and the row now shows on macOS and Linux too. * fix(macos): permission copy is translated at run time
1047 lines
36 KiB
Rust
1047 lines
36 KiB
Rust
#[cfg(target_os = "macos")]
|
|
mod accessibility;
|
|
#[cfg_attr(target_os = "windows", allow(dead_code))]
|
|
mod app_paths;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod app_settings;
|
|
mod app_window;
|
|
#[cfg(target_os = "macos")]
|
|
mod apple_intelligence;
|
|
#[cfg(target_os = "macos")]
|
|
mod apple_speech;
|
|
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
mod application_catalog;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod audio;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod command_grammar;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod commands;
|
|
#[cfg(target_os = "macos")]
|
|
mod config;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod context;
|
|
#[cfg(all(debug_assertions, target_os = "macos"))]
|
|
mod dashboard;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod design_tokens;
|
|
mod desktop_activity;
|
|
#[cfg(target_os = "linux")]
|
|
mod desktop_host;
|
|
#[cfg_attr(target_os = "windows", allow(dead_code))]
|
|
mod desktop_transcription_picker;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod desktop_ui;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod developer_control;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), 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_attr(target_os = "macos", allow(dead_code))]
|
|
mod dictation_modes;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod dictation_processor;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod events;
|
|
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
|
mod feedback;
|
|
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
|
|
mod gguf_session;
|
|
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
mod history;
|
|
mod instance;
|
|
#[cfg(target_os = "macos")]
|
|
mod keyboard;
|
|
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
mod keys;
|
|
#[cfg(target_os = "linux")]
|
|
mod linux;
|
|
#[cfg(target_os = "linux")]
|
|
mod linux_app;
|
|
#[cfg(target_os = "linux")]
|
|
mod linux_audio_control;
|
|
#[cfg(target_os = "linux")]
|
|
mod linux_context;
|
|
#[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_migration;
|
|
#[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_updater;
|
|
#[cfg(target_os = "linux")]
|
|
mod linux_wayland_input;
|
|
#[cfg(target_os = "macos")]
|
|
mod local_api;
|
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
#[cfg_attr(target_os = "windows", allow(dead_code))]
|
|
mod local_transcriber;
|
|
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
mod login_item;
|
|
#[cfg(target_os = "macos")]
|
|
mod meeting;
|
|
#[cfg(target_os = "macos")]
|
|
mod meeting_detection;
|
|
#[cfg(target_os = "macos")]
|
|
mod meeting_mcp;
|
|
#[cfg(target_os = "macos")]
|
|
mod meeting_watcher;
|
|
#[cfg(target_os = "macos")]
|
|
mod microphone_activity;
|
|
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
|
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
mod moonshine;
|
|
#[cfg(all(target_os = "macos", debug_assertions))]
|
|
mod moonshine_lab;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod onboarding;
|
|
#[cfg(target_os = "macos")]
|
|
mod parakeet;
|
|
#[cfg(target_os = "macos")]
|
|
mod paste;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod pause_segmenter;
|
|
#[cfg(target_os = "macos")]
|
|
mod permission_guide;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
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", target_os = "windows"))]
|
|
mod spoken_text;
|
|
#[cfg(target_os = "macos")]
|
|
mod status_item;
|
|
#[cfg(target_os = "macos")]
|
|
mod suppression;
|
|
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
mod text_input;
|
|
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
mod text_replacements;
|
|
#[cfg(target_os = "macos")]
|
|
mod transcription;
|
|
#[cfg(target_os = "macos")]
|
|
mod transcription_benchmark;
|
|
mod transcription_engine;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod transcription_models;
|
|
#[cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))]
|
|
mod transcription_preparation;
|
|
#[cfg(target_os = "macos")]
|
|
mod transcription_service;
|
|
|
|
// The Windows shell and the shared desktop layer it was built on. These
|
|
// modules come from the `windows-shell` branch and stay Windows-only until
|
|
// the macOS and Linux shells adopt them.
|
|
mod desktop_i18n;
|
|
#[cfg(target_os = "windows")]
|
|
mod desktop_indicator_model;
|
|
#[cfg(target_os = "windows")]
|
|
mod desktop_indicator_shader;
|
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
mod self_update;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_app;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_audio_control;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_context;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_dictation;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_indicator;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_input;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_login_item;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_migration;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_paste;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_ui;
|
|
#[cfg(target_os = "windows")]
|
|
mod windows_updater;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
use std::fs;
|
|
#[cfg(target_os = "macos")]
|
|
use std::io::{Read, Write};
|
|
#[cfg(target_os = "macos")]
|
|
use std::path::PathBuf;
|
|
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")]
|
|
#[derive(Parser)]
|
|
#[command(version, about = "Local, observable voice control")]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Option<Command>,
|
|
}
|
|
|
|
static SHUTDOWN: AtomicBool = AtomicBool::new(false);
|
|
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,
|
|
/// Ask to delete the first deletable model in the transcription picker.
|
|
#[arg(long)]
|
|
confirm_model_deletion: bool,
|
|
/// 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,
|
|
/// Opt in to Meetings so Settings shows its section and the pane.
|
|
#[arg(long)]
|
|
meetings_enabled: bool,
|
|
/// Show missing Screen & System Audio Recording permission for Meetings.
|
|
#[arg(long)]
|
|
screen_recording_missing: bool,
|
|
/// For `meetings`: select the meeting that is still recording.
|
|
#[arg(long)]
|
|
meeting_recording: bool,
|
|
/// For `meetings`: ask to delete the selected meeting.
|
|
#[arg(long)]
|
|
confirm_meeting_delete: bool,
|
|
/// For `meetings`: open the selected meeting's overflow menu.
|
|
#[arg(long)]
|
|
open_meeting_actions: bool,
|
|
/// For `meetings`: show the pane before any meeting was recorded.
|
|
#[arg(long)]
|
|
meetings_empty: bool,
|
|
/// For `meeting-offer`: show the call-ended or transcript-ready capsule.
|
|
#[arg(long, value_enum, default_value = "offer")]
|
|
meeting_panel: MeetingPanelPreview,
|
|
},
|
|
/// Listen and transcribe until interrupted.
|
|
Listen {
|
|
/// Override the configured microphone preference order.
|
|
#[arg(long)]
|
|
device: Option<String>,
|
|
},
|
|
/// Serve recorded meetings to agents over MCP (stdio). Read-only.
|
|
Mcp {
|
|
/// Read meetings from this folder instead of Application Support, such
|
|
/// as a mirrored copy on another Mac.
|
|
#[arg(long)]
|
|
meetings_dir: Option<PathBuf>,
|
|
},
|
|
/// 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: developer_control::DeveloperHudState,
|
|
},
|
|
/// Open the app and select a pane.
|
|
Show {
|
|
#[arg(value_enum)]
|
|
pane: developer_control::DeveloperPane,
|
|
},
|
|
/// Enable or disable voice commands.
|
|
Commands {
|
|
#[arg(value_enum)]
|
|
state: DevToggle,
|
|
},
|
|
}
|
|
|
|
#[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,
|
|
#[value(alias = "replacements")]
|
|
Modes,
|
|
VoiceAction,
|
|
Commands,
|
|
Meetings,
|
|
Activity,
|
|
History,
|
|
TranscriptionPicker,
|
|
MeetingOffer,
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
#[derive(Clone, Copy, ValueEnum)]
|
|
enum MeetingPanelPreview {
|
|
Offer,
|
|
CallEnded,
|
|
Ready,
|
|
}
|
|
|
|
#[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,
|
|
/// Write an Apple Intelligence title and summary for a meeting id, or
|
|
/// time the provisional title and the final title and summary for a
|
|
/// transcript Markdown file without saving them.
|
|
Summarize {
|
|
target: String,
|
|
/// Override the excerpt character budget (file targets only).
|
|
#[arg(long)]
|
|
excerpt_chars: Option<usize>,
|
|
},
|
|
/// Replay a meeting folder's tracks and report which microphone lines
|
|
/// echo suppression keeps.
|
|
Echo {
|
|
directory: PathBuf,
|
|
/// Microphone start after the system track, when the manifest has
|
|
/// no arrival times.
|
|
#[arg(long)]
|
|
microphone_offset_ms: Option<u64>,
|
|
/// Also transcribe both tracks with the selected model.
|
|
#[arg(long)]
|
|
transcribe: bool,
|
|
},
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
fn main() -> Result<()> {
|
|
moonshine::run_sessions_single_threaded();
|
|
color_eyre::install()?;
|
|
let cli = Cli::parse_from(mcp_alias_arguments(std::env::args_os().collect()));
|
|
// Before process logging, the instance lock, or any GUI or permission
|
|
// setup: an agent may start this over SSH while the app is running.
|
|
if let Some(Command::Mcp { meetings_dir }) = &cli.command {
|
|
return run_mcp(meetings_dir.clone());
|
|
}
|
|
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
let log_dir = app_paths::init_process_logging(&SHUTDOWN)?;
|
|
|
|
let event_path = log_dir.join("live.ndjson");
|
|
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")?;
|
|
let launch = if preview_dictation {
|
|
meeting_watcher::Launch::DictationHudPreview
|
|
} else {
|
|
meeting_watcher::Launch::App(meeting_watcher::ListenerConfig {
|
|
project_root: root,
|
|
event_path,
|
|
device,
|
|
})
|
|
};
|
|
meeting_watcher::run(&SHUTDOWN, launch)
|
|
}
|
|
Command::Preview {
|
|
target,
|
|
language,
|
|
model_state,
|
|
confirm_model_deletion,
|
|
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,
|
|
meetings_enabled,
|
|
screen_recording_missing,
|
|
meeting_recording,
|
|
confirm_meeting_delete,
|
|
open_meeting_actions,
|
|
meetings_empty,
|
|
meeting_panel,
|
|
} => {
|
|
if matches!(target, AppPreviewTarget::MeetingOffer) {
|
|
return meeting_watcher::run(
|
|
&SHUTDOWN,
|
|
meeting_watcher::Launch::MeetingPanelPreview(match meeting_panel {
|
|
MeetingPanelPreview::Offer => meeting_watcher::PanelPreview::Offer,
|
|
MeetingPanelPreview::CallEnded => meeting_watcher::PanelPreview::CallEnded,
|
|
MeetingPanelPreview::Ready => meeting_watcher::PanelPreview::Ready,
|
|
}),
|
|
);
|
|
}
|
|
if matches!(target, AppPreviewTarget::DictationHud) {
|
|
return meeting_watcher::run(
|
|
&SHUTDOWN,
|
|
meeting_watcher::Launch::DictationHudPreview,
|
|
);
|
|
}
|
|
if !transcription_models::LANGUAGES
|
|
.iter()
|
|
.any(|(code, _)| *code == language)
|
|
{
|
|
return Err(eyre!("unsupported preview language: {language}"));
|
|
}
|
|
let pane = match target {
|
|
AppPreviewTarget::HudLab => developer_control::DeveloperPane::HudLab,
|
|
AppPreviewTarget::Onboarding
|
|
| AppPreviewTarget::Settings
|
|
| AppPreviewTarget::TranscriptionPicker => {
|
|
developer_control::DeveloperPane::Settings
|
|
}
|
|
AppPreviewTarget::Modes => developer_control::DeveloperPane::Modes,
|
|
AppPreviewTarget::VoiceAction => developer_control::DeveloperPane::VoiceAction,
|
|
AppPreviewTarget::Commands => developer_control::DeveloperPane::Commands,
|
|
AppPreviewTarget::Meetings => developer_control::DeveloperPane::Meetings,
|
|
AppPreviewTarget::Activity => developer_control::DeveloperPane::Activity,
|
|
AppPreviewTarget::History => developer_control::DeveloperPane::History,
|
|
AppPreviewTarget::DictationHud | AppPreviewTarget::MeetingOffer => 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::run(
|
|
&SHUTDOWN,
|
|
meeting_watcher::Launch::Shell(app_window::AppWindowPreview {
|
|
pane,
|
|
transcription_picker: matches!(target, AppPreviewTarget::TranscriptionPicker)
|
|
.then_some((language, model_state)),
|
|
onboarding: matches!(target, AppPreviewTarget::Onboarding),
|
|
confirm_model_deletion,
|
|
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,
|
|
meetings_enabled,
|
|
screen_recording_missing,
|
|
meeting_recording,
|
|
confirm_meeting_delete,
|
|
open_meeting_actions,
|
|
meetings_empty,
|
|
}),
|
|
)
|
|
}
|
|
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, local_api::LocalApiOptions::default())?
|
|
};
|
|
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::Mcp { .. } => unreachable!("handled before startup"),
|
|
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, DeveloperReply};
|
|
let command = match command {
|
|
DevCommand::Status => DeveloperCommand::Status,
|
|
DevCommand::Hud { state } => DeveloperCommand::Hud { state },
|
|
DevCommand::Show { pane } => DeveloperCommand::ShowPane { pane },
|
|
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(
|
|
meeting::MeetingStart { title, app: None },
|
|
&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,
|
|
meeting_watcher::Launch::MeetingWatch {
|
|
offer_preview: preview,
|
|
},
|
|
),
|
|
#[cfg(debug_assertions)]
|
|
Command::Meeting {
|
|
command: MeetingCommand::Probe,
|
|
} => meeting_watcher::probe(),
|
|
#[cfg(debug_assertions)]
|
|
Command::Meeting {
|
|
command:
|
|
MeetingCommand::Summarize {
|
|
target,
|
|
excerpt_chars,
|
|
},
|
|
} => {
|
|
let path = PathBuf::from(&target);
|
|
if path.is_file() {
|
|
print!("{}", meeting::summarize_file(&path, excerpt_chars)?);
|
|
} else {
|
|
app_settings::AppSettings::load()?;
|
|
let manifest = meeting::summarize(&target)?;
|
|
println!("{}", meeting::display_title(&manifest));
|
|
if let Some(path) = manifest.export_path {
|
|
println!("{}", path.display());
|
|
}
|
|
if let Some(error) = manifest.notes_error {
|
|
println!("{error}");
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
#[cfg(debug_assertions)]
|
|
Command::Meeting {
|
|
command:
|
|
MeetingCommand::Echo {
|
|
directory,
|
|
microphone_offset_ms,
|
|
transcribe,
|
|
},
|
|
} => {
|
|
if transcribe {
|
|
app_settings::AppSettings::load()?;
|
|
}
|
|
print!(
|
|
"{}",
|
|
meeting::echo_report(&directory, microphone_offset_ms, transcribe)?
|
|
);
|
|
Ok(())
|
|
}
|
|
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()),
|
|
},
|
|
}
|
|
}
|
|
|
|
/// Logs to stderr only (stdout carries MCP messages) and touches no app state.
|
|
#[cfg(target_os = "macos")]
|
|
fn run_mcp(meetings_dir: Option<PathBuf>) -> Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_writer(std::io::stderr)
|
|
.with_ansi(false)
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_env("HEX_MCP_LOG")
|
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn")),
|
|
)
|
|
.init();
|
|
let root = match meetings_dir {
|
|
Some(directory) => directory,
|
|
None => meeting::root()?,
|
|
};
|
|
meeting_mcp::run(root)
|
|
}
|
|
|
|
/// A copy installed as `hex-meetings-mcp` only serves meetings: its
|
|
/// arguments are those of `hex mcp`, and it never falls back to listening.
|
|
#[cfg(target_os = "macos")]
|
|
fn mcp_alias_arguments(mut arguments: Vec<std::ffi::OsString>) -> Vec<std::ffi::OsString> {
|
|
let alias = arguments
|
|
.first()
|
|
.and_then(|program| std::path::Path::new(program).file_stem())
|
|
.is_some_and(|stem| stem == "hex-meetings-mcp");
|
|
if alias && arguments.get(1).is_none_or(|argument| argument != "mcp") {
|
|
arguments.insert(1, "mcp".into());
|
|
}
|
|
arguments
|
|
}
|
|
|
|
#[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, mcp_alias_arguments};
|
|
use clap::Parser;
|
|
|
|
#[test]
|
|
fn the_meetings_mcp_alias_always_serves_meetings() {
|
|
let parse = |arguments: &[&str]| {
|
|
Cli::parse_from(mcp_alias_arguments(
|
|
arguments.iter().map(Into::into).collect(),
|
|
))
|
|
.command
|
|
};
|
|
assert!(matches!(
|
|
parse(&["/Users/kit/.local/bin/hex-meetings-mcp"]),
|
|
Some(Command::Mcp { meetings_dir: None })
|
|
));
|
|
assert!(matches!(
|
|
parse(&["hex-meetings-mcp", "--meetings-dir", "/tmp/mirror"]),
|
|
Some(Command::Mcp { meetings_dir: Some(directory) }) if directory.ends_with("mirror")
|
|
));
|
|
assert!(matches!(
|
|
parse(&["hex-meetings-mcp", "mcp"]),
|
|
Some(Command::Mcp { .. })
|
|
));
|
|
assert!(parse(&["hex"]).is_none());
|
|
}
|
|
|
|
#[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,
|
|
..
|
|
})
|
|
));
|
|
}
|
|
|
|
#[cfg(debug_assertions)]
|
|
#[test]
|
|
fn developer_show_accepts_every_developer_pane_spelling() {
|
|
use super::{DevCommand, developer_control::DeveloperPane};
|
|
|
|
for (pane, expected) in [
|
|
("hud-lab", DeveloperPane::HudLab),
|
|
("voice-action", DeveloperPane::VoiceAction),
|
|
("history", DeveloperPane::History),
|
|
] {
|
|
let cli = Cli::try_parse_from(["hex", "dev", "show", pane]).unwrap();
|
|
let Some(Command::Dev {
|
|
command: DevCommand::Show { pane },
|
|
}) = cli.command
|
|
else {
|
|
panic!("expected dev show command");
|
|
};
|
|
assert_eq!(pane, expected);
|
|
}
|
|
assert!(Cli::try_parse_from(["hex", "dev", "show", "hudlab"]).is_err());
|
|
assert!(Cli::try_parse_from(["hex", "dev", "hud", "recording"]).is_ok());
|
|
}
|
|
|
|
#[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)
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
fn main() -> Result<()> {
|
|
windows::run(&SHUTDOWN)
|
|
}
|