feat(energy): Phase 3 — match-my-energy task sort + tri-state tag column
Closes Phase 3 of the 2026-04-23 feature-complete roadmap. Incorporates the Codex plan-review fixes from this session: profile-free index, tri- state update command, and de-prioritise-not-hide semantics. Storage (kon-storage): - Migration v11 adds `energy TEXT` to `tasks` with a CHECK constraint on `high | medium | brain_dead | NULL`. Index `(energy, created_at DESC)` — deliberately not per-profile because the tasks table carries no profile_id column yet (tracked as a separate gap in HANDOVER). - `TaskRow.energy: Option<String>` plus `task_row_from` read. - `insert_task` signature grows by one optional arg (`energy`). Allowed `too_many_arguments` with a rationale comment — the positional shape matches the column order and flipping to a params struct would have rippled through every caller for cosmetic benefit only. - New `set_task_energy(pool, id, Option<&str>) -> TaskRow`. Lives as its own function because `update_task` uses COALESCE to let `None` mean "preserve" — which would make clearing the tag impossible. - Two new tests: round-trip including explicit NULL clear, and CHECK constraint rejection of unknown values. - Tests updated for the v10 → v11 version bump. Tauri (src-tauri): - `TaskDto.energy`. `CreateTaskRequest.energy` (optional). Inline validation against the allowed set before hitting the DB, so frontend bugs surface as friendly errors instead of CHECK-constraint failures. - New `set_task_energy_cmd` command mirroring the storage tri-state API. Frontend (svelte): - `EnergyLevel` type added to `types/app.ts`. `TaskDto`, `TaskEntry`, and `TaskDraft` grow an `energy` field. - `SettingsState.currentEnergy` (persisted) + `matchMyEnergy` (persisted toggle). Defaults: null + false — no surface change until user opts in. - `setTaskEnergy(id, EnergyLevel | null)` action on the task store. Calls the dedicated Tauri command, updates local state, broadcasts to sibling windows. - `EnergyChip.svelte` — new component. Cycles unset → High → Medium → Brain-Dead → unset on click. Colour tokens: accent / warning / text-tertiary (deliberately not danger-red for Brain-Dead — the brief is explicit that this state must not feel pathologised). - Chip rendered on every task row in TasksPage and every row in WipTaskList. Hidden-until-hover when energy is unset so untagged rows stay calm; always visible once tagged because the colour is the signal. - Tasks page header gains a "I feel" segmented control and a "Match my energy" toggle. When both are active, matching tasks sort to the top — unset tasks are treated as Medium-equivalent. Nothing is ever hidden; this is a de-prioritisation, not a filter. Deferred / out of scope: - LLM-driven surfacing (brief says "The AI surfaces...") — deterministic client-side sort is v1; LLM layer is a later phase. - tasks.profile_id + per-profile energy sort — separate migration. All green: cargo build + 251 tests + clippy -D warnings (0 warnings) + fmt + svelte-check (0/0) + npm run build.
This commit is contained in:
@@ -12,8 +12,9 @@ use kon_storage::{
|
||||
delete_task as db_delete_task, get_task_by_id as db_get_task,
|
||||
insert_subtask as db_insert_subtask, insert_task as db_insert_task,
|
||||
list_feedback_examples as db_list_feedback_examples, list_subtasks as db_list_subtasks,
|
||||
list_tasks as db_list_tasks, uncomplete_task as db_uncomplete_task,
|
||||
update_task as db_update_task, FeedbackRow, FeedbackTargetType, TaskRow,
|
||||
list_tasks as db_list_tasks, set_task_energy as db_set_task_energy,
|
||||
uncomplete_task as db_uncomplete_task, update_task as db_update_task, FeedbackRow,
|
||||
FeedbackTargetType, TaskRow,
|
||||
};
|
||||
|
||||
use crate::AppState;
|
||||
@@ -33,6 +34,7 @@ pub struct TaskDto {
|
||||
pub created_at: String,
|
||||
pub source_transcript_id: Option<String>,
|
||||
pub parent_task_id: Option<String>,
|
||||
pub energy: Option<String>,
|
||||
}
|
||||
|
||||
impl From<TaskRow> for TaskDto {
|
||||
@@ -49,10 +51,27 @@ impl From<TaskRow> for TaskDto {
|
||||
created_at: r.created_at,
|
||||
source_transcript_id: r.source_transcript_id,
|
||||
parent_task_id: r.parent_task_id,
|
||||
energy: r.energy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Accepted energy tag values. Kept as a const so frontend and storage
|
||||
/// validate against the same list. Migration v11 enforces the same
|
||||
/// set via a CHECK constraint.
|
||||
const ENERGY_LEVELS: &[&str] = &["high", "medium", "brain_dead"];
|
||||
|
||||
fn validate_energy(raw: Option<&str>) -> Result<Option<&str>, String> {
|
||||
match raw {
|
||||
None => Ok(None),
|
||||
Some(s) if ENERGY_LEVELS.contains(&s) => Ok(Some(s)),
|
||||
Some(other) => Err(format!(
|
||||
"energy must be one of {:?} or null, got {:?}",
|
||||
ENERGY_LEVELS, other
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CreateTaskRequest {
|
||||
@@ -65,6 +84,8 @@ pub struct CreateTaskRequest {
|
||||
pub list_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub effort: Option<String>,
|
||||
#[serde(default)]
|
||||
pub energy: Option<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -72,6 +93,7 @@ pub async fn create_task_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
request: CreateTaskRequest,
|
||||
) -> Result<TaskDto, String> {
|
||||
let energy = validate_energy(request.energy.as_deref())?;
|
||||
db_insert_task(
|
||||
&state.db,
|
||||
&request.id,
|
||||
@@ -80,6 +102,7 @@ pub async fn create_task_cmd(
|
||||
request.source_transcript_id.as_deref(),
|
||||
request.list_id.as_deref(),
|
||||
request.effort.as_deref(),
|
||||
energy,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
@@ -168,6 +191,24 @@ pub async fn uncomplete_task_cmd(
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Phase 3: set or clear the `energy` tag on a task. Dedicated command
|
||||
/// rather than a field on `update_task_cmd` because the existing update
|
||||
/// path uses `COALESCE` semantics where `None` means "preserve" — which
|
||||
/// makes clearing the tag impossible. This command always writes exactly
|
||||
/// what you send, including `None` to explicitly clear.
|
||||
#[tauri::command]
|
||||
pub async fn set_task_energy_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
id: String,
|
||||
energy: Option<String>,
|
||||
) -> Result<TaskDto, String> {
|
||||
let validated = validate_energy(energy.as_deref())?;
|
||||
let row = db_set_task_energy(&state.db, &id, validated)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(TaskDto::from(row))
|
||||
}
|
||||
|
||||
/// Convert HITL feedback rows fetched from storage into the few-shot
|
||||
/// exemplar shape the LLM crate consumes. We reconstruct the `input`
|
||||
/// (parent task text, transcript chunk) from `context_json` where the
|
||||
|
||||
@@ -284,6 +284,7 @@ pub fn run() {
|
||||
commands::tasks::complete_task_cmd,
|
||||
commands::tasks::delete_task_cmd,
|
||||
commands::tasks::uncomplete_task_cmd,
|
||||
commands::tasks::set_task_energy_cmd,
|
||||
commands::tasks::decompose_and_store,
|
||||
commands::tasks::extract_tasks_from_transcript_cmd,
|
||||
commands::tasks::list_subtasks_cmd,
|
||||
|
||||
Reference in New Issue
Block a user