feat: OpenWhispr-inspired transcription polish pass
Some checks failed
check / cargo check (macos-latest) (push) Has been cancelled
check / cargo check (ubuntu-22.04) (push) Has been cancelled
check / cargo check (windows-latest) (push) Has been cancelled
check / svelte build + lint (push) Has been cancelled

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>
This commit is contained in:
2026-04-19 22:39:08 +01:00
parent 28acdcfa6d
commit 34fce3cf9e
39 changed files with 1581 additions and 554 deletions

View File

@@ -421,10 +421,13 @@
id: historyId,
date: new Date().toLocaleString("en-GB"),
source: "live",
profileId: profilesStore.activeProfileId,
preview: transcript.slice(0, 120),
text: transcript,
segments: segments,
duration: (Date.now() - startTime) / 1000,
engine: settings.engine,
modelId: selectedModelId(),
language: effectiveLanguage(),
template: activeTemplate || undefined,
audioPath,
@@ -537,6 +540,7 @@
id: crypto.randomUUID(),
date: new Date().toLocaleString("en-GB"),
source: "typed",
profileId: profilesStore.activeProfileId,
preview: transcript.slice(0, 120),
text: transcript,
segments: [],

View File

@@ -75,6 +75,7 @@
try {
const result = await invoke("transcribe_file", {
path,
engine: settings.engine,
language: settings.language,
initialPrompt: "",
profileId: profilesStore.activeProfileId,
@@ -98,11 +99,14 @@
id: crypto.randomUUID(),
date: new Date().toLocaleString("en-GB"),
source: fileName,
profileId: profilesStore.activeProfileId,
preview: text.slice(0, 120),
text,
segments: result.segments,
duration: result.duration,
language: result.language,
engine: result.engine ?? settings.engine,
modelId: result.modelId ?? null,
});
} catch (err) {
error = `Failed: ${fileName}${typeof err === "string" ? err : err.message}`;

View File

@@ -114,6 +114,7 @@ function mapTranscriptRow(row: TranscriptDto): TranscriptEntry {
id: row.id,
text,
source: row.source ?? "",
profileId: row.profileId ?? "00000000-0000-0000-0000-000000000001",
title: row.title ?? "",
audioPath: row.audioPath ?? null,
duration: Number(row.duration ?? 0),
@@ -136,6 +137,7 @@ function normaliseTranscriptEntry(entry: TranscriptWriteEntry): TranscriptEntry
id: String(entry.id),
text: entry.text ?? "",
source: entry.source ?? "microphone",
profileId: entry.profileId ?? "00000000-0000-0000-0000-000000000001",
title: entry.title ?? "",
audioPath: entry.audioPath ?? null,
duration: Number(entry.duration ?? 0),
@@ -187,6 +189,7 @@ export async function addToHistory(entry: TranscriptWriteEntry) {
id: normalised.id,
text: normalised.text,
source: normalised.source,
profileId: normalised.profileId,
title: normalised.title || null,
audioPath: normalised.audioPath ?? null,
duration: normalised.duration,

View File

@@ -78,6 +78,7 @@ export interface TranscriptDto {
id: string;
text: string;
source: string;
profileId: string;
title: string | null;
audioPath: string | null;
duration: number;
@@ -95,6 +96,7 @@ export interface TranscriptEntry {
id: string;
text: string;
source: string;
profileId: string;
title: string;
audioPath: string | null;
duration: number;

View File

@@ -8,6 +8,8 @@
import { errorMessage } from "$lib/utils/errors.js";
import { parseStoredJson } from "$lib/utils/storage.js";
import { saveTranscriptMeta } from "$lib/stores/page.svelte.js";
import { toasts } from "$lib/stores/toasts.svelte.ts";
import { DEFAULT_PROFILE_ID } from "$lib/stores/profiles.svelte.ts";
let item = $state<TranscriptEntry | null>(null);
let audioEl = $state<HTMLAudioElement | null>(null);
@@ -28,6 +30,7 @@
let textDirty = $state(false);
let textSaveTimer: ReturnType<typeof setTimeout> | null = null;
let editingTextareaEl = $state<HTMLTextAreaElement | null>(null);
let textLearnBase = $state("");
function stopAudio() {
if (audioEl) audioEl.pause();
@@ -59,6 +62,7 @@
function loadViewerItem(nextItem: TranscriptEntry | null) {
item = nextItem;
textDraft = nextItem?.text ?? "";
textLearnBase = nextItem?.text ?? "";
activeSegmentIdx = -1;
editingIdx = -1;
editingText = "";
@@ -83,9 +87,36 @@
clearTimeout(textSaveTimer);
textSaveTimer = null;
}
if (textDirty) commitTextEdit();
if (viewerMode === "edit") {
commitTextEdit(true);
} else if (textDirty) {
commitTextEdit();
}
});
async function maybeLearnCorrections(originalText: string, editedText: string) {
if (!item || !originalText.trim() || !editedText.trim() || originalText === editedText) {
return;
}
try {
const learned = await invoke<Array<{ term: string }>>("learn_profile_terms_from_edit_cmd", {
profileId: item.profileId || DEFAULT_PROFILE_ID,
originalText,
editedText,
});
if (learned.length > 0) {
const count = learned.length;
toasts.success(
count === 1 ? "Learned 1 profile term" : `Learned ${count} profile terms`,
learned.map((entry) => entry.term).join(", "),
);
}
} catch (err) {
console.warn("viewer maybeLearnCorrections failed", errorMessage(err));
}
}
function handleStorageChange(e: StorageEvent) {
if (e.key === "kon_viewer_item" && e.newValue) {
loadViewerItem(parseStoredJson<TranscriptEntry>(e.newValue));
@@ -193,14 +224,18 @@
function finishEditing() {
if (editingIdx >= 0 && item?.segments) {
const previousText = item.text;
item.segments[editingIdx].text = editingText.trim();
// Update full text
item.text = item.segments.map((s) => s.text).join(" ").trim();
textDraft = item.text;
saveItemToHistory();
// Task 2.5 — persist segment boundaries (text + starred flags) to
// SQLite via segments_json. update_transcript above only covers text
// and title; the segment array needs the dedicated meta command.
persistSegments();
void maybeLearnCorrections(previousText, item.text);
textLearnBase = item.text;
}
editingIdx = -1;
editingText = "";
@@ -281,18 +316,24 @@
}, 400);
}
function commitTextEdit() {
function commitTextEdit(learnCorrections = false) {
if (!item) return;
const next = textDraft;
if (next !== item.text) {
item.text = next;
// The compact preview in History is derived from `preview`; keep it
// roughly in sync so the list does not show stale copy after an edit.
item.preview = next.slice(0, 120);
saveItemToHistory();
}
if (learnCorrections && next !== textLearnBase) {
void maybeLearnCorrections(textLearnBase, next);
textLearnBase = next;
}
if (next === item.text) {
textDirty = false;
return;
}
item.text = next;
// The compact preview in History is derived from `preview`; keep it
// roughly in sync so the list does not show stale copy after an edit.
item.preview = next.slice(0, 120);
saveItemToHistory();
textDirty = false;
}
@@ -441,6 +482,7 @@
text-text leading-relaxed resize-none focus:outline-none focus:border-accent"
bind:value={textDraft}
oninput={scheduleTextSave}
onblur={() => commitTextEdit(true)}
data-no-transition
placeholder="Edit the transcript..."
></textarea>