Files
Lumotia/src-tauri/src/commands/mod.rs
Jake e4cbf62a20 feat(storage): B2b — settings/profile schema + templates SQLite persistence
Settings: 8 new fields (lastLaunchAt, reentryFreshStartUntil,
lastActiveProfileId, microStepGranularity, nudgeMode, nudgeDigestTimes,
sparklineRangeDays, energyLabels) with sane defaults; nudgesEnabled
auto-maps to nudgeMode on first load (true→immediate, false→off).

Profile: optional energyLabelsOverride field on the localStorage
Profile shape — when present, overrides the global energyLabels;
absent/null falls through to settings.energyLabels via the new
resolveEnergyLabels helper.

Templates: migration v17 adds the templates table (id PK, name,
sections JSON, created_at, updated_at). 5 storage CRUD functions
plus import_templates with idempotent duplicate-id handling. 5 Tauri
commands (list/create/update/delete/import) wired and registered.
Frontend store rewired to read from SQLite via list_templates_cmd;
one-time migration imports kon_templates localStorage and clears it
on success. Fresh installs only seed the new {Meeting notes, Daily
check-in} defaults. Existing user templates survive the migration
verbatim.

Test coverage: 5 new Rust tests (CRUD, import idempotency, atomic
failure, updated_at bump, missing-id delete is no-op).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 19:16:31 +01:00

117 lines
3.3 KiB
Rust

pub mod audio;
pub mod clipboard;
pub mod diagnostics;
pub mod feedback;
pub mod fs;
pub mod hardware;
pub mod hotkey;
pub mod intentions;
pub mod live;
pub mod llm;
pub mod meeting;
pub mod models;
pub mod nudges;
pub mod paste;
pub mod power;
pub mod profiles;
pub mod rituals;
pub mod security;
pub mod task_lists;
pub mod tasks;
pub mod templates;
pub mod transcription;
pub mod transcripts;
pub mod tts;
pub mod update;
pub mod windows;
/// Build the Whisper `initial_prompt` for a transcription request.
///
/// Precedence:
/// 1. Caller-supplied `request_prompt` (non-empty wins outright — the caller
/// has already made the decision).
/// 2. Profile's stored prompt + profile terms (joined: the prompt frames the
/// task, the vocabulary biases recognition toward domain terms).
/// 3. Profile prompt alone, or vocabulary alone.
/// 4. `None` if nothing is set.
///
/// Feeding `profile_terms` into `initial_prompt` (the OpenWhispr pattern) lets
/// whisper.cpp bias its decoder toward the correct spelling of user-specific
/// vocabulary at decode time, before any LLM cleanup pass.
pub fn build_initial_prompt(
request_prompt: &str,
profile_prompt: &str,
profile_terms: &[String],
) -> Option<String> {
let trimmed_request = request_prompt.trim();
if !trimmed_request.is_empty() {
return Some(trimmed_request.to_string());
}
let trimmed_profile = profile_prompt.trim();
let terms_list = profile_terms
.iter()
.map(|term| term.trim())
.filter(|term| !term.is_empty())
.collect::<Vec<_>>()
.join(", ");
match (trimmed_profile.is_empty(), terms_list.is_empty()) {
(true, true) => None,
(false, true) => Some(trimmed_profile.to_string()),
(true, false) => Some(format!("Vocabulary: {terms_list}.")),
(false, false) => Some(format!("{trimmed_profile} Vocabulary: {terms_list}.")),
}
}
#[cfg(test)]
mod tests {
use super::build_initial_prompt;
#[test]
fn caller_prompt_overrides_everything() {
let got = build_initial_prompt(
"caller wins",
"profile prompt",
&["Wren".into(), "CORBEL".into()],
);
assert_eq!(got.as_deref(), Some("caller wins"));
}
#[test]
fn profile_prompt_and_terms_are_joined() {
let got = build_initial_prompt(
"",
"You are a meeting notes assistant.",
&["Wren".into(), "CORBEL".into()],
);
assert_eq!(
got.as_deref(),
Some("You are a meeting notes assistant. Vocabulary: Wren, CORBEL."),
);
}
#[test]
fn terms_only_produces_vocabulary_sentence() {
let got = build_initial_prompt("", "", &["Wren".into(), "CORBEL".into()]);
assert_eq!(got.as_deref(), Some("Vocabulary: Wren, CORBEL."));
}
#[test]
fn profile_prompt_alone_is_passed_through() {
let got = build_initial_prompt("", "Be concise.", &[]);
assert_eq!(got.as_deref(), Some("Be concise."));
}
#[test]
fn all_empty_returns_none() {
assert_eq!(build_initial_prompt("", "", &[]), None);
}
#[test]
fn whitespace_only_terms_are_skipped() {
let got = build_initial_prompt("", "", &[" ".into(), "Wren".into(), "".into()]);
assert_eq!(got.as_deref(), Some("Vocabulary: Wren."));
}
}