Small if-then automation layer. Rules persist in SQLite; the runner lives on the frontend and binds to the Phase 6 event bus so the rule pipeline reuses the same delivery primitives (timer events, TTS, Tasks navigation). Storage: - Migration v12 adds implementation_rules (id, enabled, trigger_kind, trigger_value, actions_json, last_fired_key, created_at, updated_at) with enabled+trigger_kind index for the runner's hot path. - CRUD helpers: insert / list / get / set-enabled / mark-fired / delete, plus a round-trip test. Commands (all main-window-guarded via ensure_main_window): - list_implementation_rules - create_implementation_rule — validates HH:MM, checks the target task exists at save time for surface-task actions, caps speak-line at 240 chars, pins v1 timers to 5 minutes. - set_implementation_rule_enabled - mark_implementation_rule_fired — main-thread idempotency shim so the runner can atomically claim a fire. - delete_implementation_rule Runner (implementationIntentions.svelte.ts): - Subscribes to kon:task-completed and kon:morning-triage-finished (MorningTriageModal now emits on all three exit paths — empty, skipped, picked — so skip counts as finishing). - 30 s poll for time-of-day rules, plus an immediate check on startup so a rule whose time has already passed today catches up once. - Idempotency via last_fired_key composed as YYYY-MM-DD@HH:MM for time rules; new time rules whose HH:MM has already passed today are pre-seeded so they don't fire retroactively on save. - Rules are paused when Nudges "Mute for now" is on — a hard mute stops all rule delivery in addition to OS notifications. - Stale-task safety: if a surface-task action's target has been deleted, the runner opens Tasks and warns clearly rather than pretending to surface something that's gone. Editor (ImplementationRulesEditor.svelte): - Lives in Settings under a new "If-then rules" accordion section. - `If` picker: time of day (with time input), a task completes, morning triage finishes. - `Then` composer: optional surface (inbox / today / all tasks / specific task), optional 5-min timer, optional speak-aloud line. - Saved rules list with enable toggle + delete. Rules table integration for Phase 10b rename sweep: add implementation_rules to the kon.db → corbie.db migration shim when that phase lands. Gates: fmt, clippy -D warnings, cargo test 265/0, svelte-check 0/0, npm build green. Pre-existing Vite chunk warning on sounds.ts is unrelated to Phase 7.
114 lines
3.3 KiB
Rust
114 lines
3.3 KiB
Rust
pub mod audio;
|
|
pub mod clipboard;
|
|
pub mod diagnostics;
|
|
pub mod feedback;
|
|
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 tasks;
|
|
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."));
|
|
}
|
|
}
|