---
name: Profiles
type: architecture-map-page
slice: 02-tauri-runtime
last_verified: 2026/05/09
---

# `commands::profiles`

> **Where you are:** [Architecture map](../../README.md) → [Tauri runtime](../README.md) → [Commands](README.md) → Profiles

**Plain English summary.** Task 12 storage-backed profiles + per-profile vocabulary terms. Profiles are the unit that scopes a Whisper initial_prompt, a vocabulary list (biases the decoder toward correct spellings), HITL feedback exemplars, and transcripts. Nine commands: profile CRUD (5), profile-term CRUD (3), and the auto-learn pass that diffs an original transcript against an edited transcript and persists likely vocabulary corrections.

## At a glance

- Path: `src-tauri/src/commands/profiles.rs`.
- LOC: 185.
- Tauri commands exposed (9 total):
  - `list_profiles_cmd(state) -> Result<Vec<ProfileDto>, String>`.
  - `get_profile_cmd(state, id) -> Result<Option<ProfileDto>, String>`.
  - `create_profile_cmd(state, name, initial_prompt) -> Result<ProfileDto, String>`.
  - `update_profile_cmd(state, id, name, initial_prompt) -> Result<(), String>`.
  - `delete_profile_cmd(state, id) -> Result<(), String>`. The Default profile is guarded at the storage layer (SQLite triggers + Rust pre-checks).
  - `list_profile_terms_cmd(state, profile_id) -> Result<Vec<ProfileTermDto>, String>`.
  - `add_profile_term_cmd(state, profile_id, term, note) -> Result<ProfileTermDto, String>`.
  - `learn_profile_terms_from_edit_cmd(state, profile_id, original_text, edited_text) -> Result<Vec<ProfileTermDto>, String>`.
  - `delete_profile_term_cmd(state, id) -> Result<(), String>`.
- Events emitted: none.
- Depends on: `lumotia_storage::{create_profile, update_profile, delete_profile, list_profiles, get_profile, add_profile_term, list_profile_terms, delete_profile_term, ProfileRow, ProfileTermRow}`, `lumotia_ai_formatting::extract_corrections`.
- Called from frontend at: Settings → Profiles (full CRUD), profile picker, History viewer (the auto-learn flow runs after the user saves an edit).

## What's in here

### `ProfileDto` and `ProfileTermDto` (`src-tauri/src/commands/profiles.rs:31`, `:51`)

camelCase mirrors of the storage rows. `ProfileDto.initialPrompt` is the saved Whisper prompt; `ProfileTermDto.term` is the vocabulary entry, `note` is a freeform note (used to mark `"Auto-learned from transcript edit"` for the auto-learn flow).

### `AUTO_LEARNED_NOTE` (`:25`)

Constant so the auto-learn rows are uniformly tagged.

### CRUD wrappers

- `list_profiles_cmd` (`:72`), `get_profile_cmd` (`:82`), `create_profile_cmd` (`:93`), `update_profile_cmd` (`:105`), `delete_profile_cmd` (`:117`). Pure passthroughs to storage.
- `list_profile_terms_cmd` (`:127`), `add_profile_term_cmd` (`:138`), `delete_profile_term_cmd` (`:177`). Same pattern.

### `learn_profile_terms_from_edit_cmd` (`:151`)

1. Pull the existing terms (so the diff doesn't propose duplicates).
2. Call `lumotia_ai_formatting::extract_corrections(&original, &edited, &existing_terms)`.
3. Persist each new term via `add_profile_term` with the `AUTO_LEARNED_NOTE`.
4. Return the freshly-inserted DTOs.

The actual diff heuristic lives in the formatting crate; the command file is just wiring.

## Data flow

```
Settings Profiles tab -> list_profiles_cmd -> [ProfileDto, ...]
profile picker -> get_profile_cmd(id)
add profile -> create_profile_cmd(name, prompt) -> ProfileDto
edit profile -> update_profile_cmd(id, name, prompt) -> ()
delete profile -> delete_profile_cmd(id) -> () (Default is rejected at storage)

Profile terms tab -> list_profile_terms_cmd(profile_id)
add term -> add_profile_term_cmd(profile_id, term, note) -> ProfileTermDto
delete term -> delete_profile_term_cmd(id) -> ()

History viewer save edit:
  -> learn_profile_terms_from_edit_cmd(profile_id, original, edited)
     -> existing terms from DB
     -> extract_corrections(original, edited, existing) -> [String]
     -> add each as a profile term tagged "Auto-learned from transcript edit"
     -> [ProfileTermDto, ...]
```

## Watch-outs

- **No `ensure_main_window` guard.** The History viewer is a secondary window (`transcript-viewer`) and needs to call `learn_profile_terms_from_edit_cmd` after a save. So the whole module is callable from anywhere with the secondary-windows capability. If you want to lock down profile *creation* / *deletion*, add `ensure_main_window` to the destructive ones.
- **No `PowerAssertion`.** No inference here.
- **`extract_corrections` runs synchronously (in the async fn).** Acceptable for the small-text shape of a single transcript edit.
- **The Default profile is unkillable.** SQLite trigger rejects the delete. Frontend should grey out the delete button when `profile.id == DEFAULT_PROFILE_ID`.
- **Auto-learned terms are recorded one at a time inside a loop** (`:166`). Each iteration is a separate insert. Acceptable; if a future heuristic produces dozens of terms per edit, batch.

## See also

- [`commands::mod`](mod.md) — `build_initial_prompt` consumes profile prompt + terms.
- [Transcription](transcription.md) — fetches profile + terms before transcribing.
- [Live transcription](live.md) — same upstream.
- [Tasks](tasks.md) — feedback exemplars are profile-scoped.
- [Transcripts](transcripts.md) — every transcript carries a `profileId`.
