Major quality pass on top of Phase 2. Five substantive changes plus
cross-cutting touches across audio, hotkey, transcription, and Tauri
command layers.
Transcription quality
- Long-audio chunking in commands/transcription.rs: Parakeet and large
file transcription now chunk-and-recompose with overlap trimming, so
the live-path chunking advantage extends to file-based workflows.
- Stateful live speech gate in commands/live.rs on top of the earlier
duplicate-boundary filtering — distinguishes start-of-speech from
mid-speech and holds state across chunks.
Auto-learning corrections
- New crates/ai-formatting/src/correction_learning.rs: extracts user
text corrections from viewer edits and proposes additions to the
active profile's vocabulary.
- src-tauri/src/commands/profiles.rs bridge for frontend-driven
confirmation of learned terms.
- src/routes/viewer/+page.svelte hooks the learning path into the
segment-edit flow so corrections feed profile_terms without a
separate 'train this profile' UX.
Transcript profile provenance
- Migration v8 (crates/storage/src/migrations.rs) adds profile_id to
transcripts, defaulting to DEFAULT_PROFILE_ID so existing rows stay
valid.
- crates/storage/src/database.rs: TranscriptRow + CRUD carry profile_id.
- src-tauri/src/commands/transcripts.rs: add_transcript accepts and
persists profile_id.
- DictationPage.svelte + FilesPage.svelte send activeProfileId on
capture so learned corrections are attributed to the right profile.
Cleanup prompt contract
- crates/ai-formatting/src/llm_client.rs hardened: the CLEANUP_PROMPT
now specifies concrete do/do-not rules, ready for a real model-backed
cleanup pass. The llm_client is still a stub — kon-llm remains unwired
— but the prompt shape is final.
Cross-cutting polish
- Minor touches in audio (capture/decode/resample), hotkey (lib/linux/stub),
core, transcription (concurrency/model_manager/local_engine/whisper_rs),
and the rest of src-tauri/src/commands/*: error-path tightening, log
clarity, TS-migration follow-ups (@ts-nocheck additions for incremental
typing).
Verified locally: npm run check, cargo test -p kon-ai-formatting,
cargo test -p kon-storage, cargo test -p kon --lib commands::live::tests,
cargo check — all green.
Scope boundary: kon-llm crate is still a stub; task extraction remains
rule-based. Bundled local-LLM runtime is the next clean step and is not
in this commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
106 lines
2.9 KiB
Rust
106 lines
2.9 KiB
Rust
use std::sync::Arc;
|
|
|
|
use tauri::Emitter;
|
|
use tokio::sync::{mpsc, Mutex};
|
|
|
|
use kon_hotkey::{EvdevHotkeyListener, HotkeyCombo, HotkeyEvent};
|
|
|
|
/// Managed state for the evdev hotkey listener.
|
|
pub struct HotkeyState {
|
|
listener: Arc<Mutex<Option<EvdevHotkeyListener>>>,
|
|
}
|
|
|
|
impl HotkeyState {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
listener: Arc::new(Mutex::new(None)),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Check whether the current session is running on Wayland.
|
|
#[tauri::command]
|
|
pub fn is_wayland_session() -> bool {
|
|
std::env::var("WAYLAND_DISPLAY").is_ok()
|
|
|| std::env::var("XDG_SESSION_TYPE")
|
|
.map(|v| v == "wayland")
|
|
.unwrap_or(false)
|
|
}
|
|
|
|
/// Check whether evdev hotkey capture is available (user in `input` group, etc.).
|
|
#[tauri::command]
|
|
pub fn check_hotkey_access() -> Result<(), String> {
|
|
kon_hotkey::check_evdev_access()
|
|
}
|
|
|
|
/// Start the evdev global hotkey listener. Emits "kon:hotkey-pressed" and
|
|
/// "kon:hotkey-released" events to the frontend.
|
|
///
|
|
/// If a listener is already running, it is stopped first.
|
|
#[tauri::command]
|
|
pub async fn start_evdev_hotkey(
|
|
app: tauri::AppHandle,
|
|
state: tauri::State<'_, HotkeyState>,
|
|
hotkey: String,
|
|
) -> Result<(), String> {
|
|
let combo = HotkeyCombo::from_tauri_str(&hotkey)
|
|
.ok_or_else(|| format!("Cannot parse hotkey: {hotkey}"))?;
|
|
|
|
// Stop existing listener if any
|
|
let mut guard = state.listener.lock().await;
|
|
if let Some(existing) = guard.take() {
|
|
existing.stop().await;
|
|
}
|
|
|
|
let (event_tx, mut event_rx) = mpsc::channel::<HotkeyEvent>(64);
|
|
let listener = EvdevHotkeyListener::start(combo, event_tx);
|
|
|
|
*guard = Some(listener);
|
|
drop(guard);
|
|
|
|
// Forward evdev events to Tauri event bus
|
|
let app_clone = app.clone();
|
|
tokio::spawn(async move {
|
|
while let Some(event) = event_rx.recv().await {
|
|
match event {
|
|
HotkeyEvent::Pressed => {
|
|
let _ = app_clone.emit("kon:hotkey-pressed", ());
|
|
}
|
|
HotkeyEvent::Released => {
|
|
let _ = app_clone.emit("kon:hotkey-released", ());
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Update the hotkey combo on a running listener.
|
|
#[tauri::command]
|
|
pub async fn update_evdev_hotkey(
|
|
state: tauri::State<'_, HotkeyState>,
|
|
hotkey: String,
|
|
) -> Result<(), String> {
|
|
let combo = HotkeyCombo::from_tauri_str(&hotkey)
|
|
.ok_or_else(|| format!("Cannot parse hotkey: {hotkey}"))?;
|
|
|
|
let guard = state.listener.lock().await;
|
|
if let Some(ref listener) = *guard {
|
|
listener.set_hotkey(combo);
|
|
Ok(())
|
|
} else {
|
|
Err("Hotkey listener not running".to_string())
|
|
}
|
|
}
|
|
|
|
/// Stop the evdev hotkey listener.
|
|
#[tauri::command]
|
|
pub async fn stop_evdev_hotkey(state: tauri::State<'_, HotkeyState>) -> Result<(), String> {
|
|
let mut guard = state.listener.lock().await;
|
|
if let Some(listener) = guard.take() {
|
|
listener.stop().await;
|
|
}
|
|
Ok(())
|
|
}
|