feat(tasks): B2a part 2 — task_lists CRUD + archive cmds + frontend wire
Storage: 5 task_lists CRUD functions (list/create/update/delete/ import) and 4 archive functions (list_archived_tasks/archive_task/ unarchive_task/archive_inbox_older_than). 8 new tests cover CRUD, import idempotency, atomic-failure rollback, dependent-task null-out, archive scope, archive_inbox_older_than Inbox-only invariant, and unarchive round-trip. Tauri: 9 new commands (5 task_lists + 4 archive) registered in the invoke_handler. New file commands/task_lists.rs mirroring tasks.rs structure. TaskDto extended with archived/archivedAt. Frontend: loadTaskLists rewired to read from SQLite via list_task_lists_cmd on Tauri runtime, with a one-time migration that imports kon_task_lists localStorage into SQLite via import_task_lists_cmd and clears localStorage only on success. mapTaskRow handles the new archived fields. TasksPage gets an Archived filter pill (hidden when empty) and a per-row archive icon. moveTaskList/sortTaskLists kept local pending a future order-column migration. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ pub mod power;
|
||||
pub mod profiles;
|
||||
pub mod rituals;
|
||||
pub mod security;
|
||||
pub mod task_lists;
|
||||
pub mod tasks;
|
||||
pub mod transcription;
|
||||
pub mod transcripts;
|
||||
|
||||
174
src-tauri/src/commands/task_lists.rs
Normal file
174
src-tauri/src/commands/task_lists.rs
Normal file
@@ -0,0 +1,174 @@
|
||||
// Tauri commands wrapping kon_storage task_lists CRUD.
|
||||
// Pattern mirrors tasks.rs — TaskListDto is the camelCase frontend shape,
|
||||
// storage functions are aliased with db_ prefix to avoid name collisions.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use kon_storage::{
|
||||
create_task_list as db_create_task_list, delete_task_list as db_delete_task_list,
|
||||
import_task_lists as db_import_task_lists, list_task_lists as db_list_task_lists,
|
||||
update_task_list as db_update_task_list, ImportSummary, TaskListRow,
|
||||
};
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TaskListDto {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub built_in: bool,
|
||||
pub profile_id: Option<String>,
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
impl From<TaskListRow> for TaskListDto {
|
||||
fn from(r: TaskListRow) -> Self {
|
||||
Self {
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
built_in: r.built_in,
|
||||
profile_id: r.profile_id,
|
||||
created_at: r.created_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CreateTaskListRequest {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub built_in: bool,
|
||||
#[serde(default)]
|
||||
pub profile_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UpdateTaskListPatch {
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
// Triple-Option to distinguish absent from null:
|
||||
// absent -> Option::None -> "leave profile_id alone"
|
||||
// null -> Some(None) -> "set profile_id to NULL"
|
||||
// "abc" -> Some(Some("abc")) -> "set profile_id to 'abc'"
|
||||
#[serde(default, deserialize_with = "deserialize_optional_field")]
|
||||
pub profile_id: Option<Option<String>>,
|
||||
}
|
||||
|
||||
// Helper for the triple-Option pattern. See https://serde.rs/field-attrs.html
|
||||
fn deserialize_optional_field<'de, T, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<Option<T>>, D::Error>
|
||||
where
|
||||
T: serde::Deserialize<'de>,
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
Ok(Some(Option::<T>::deserialize(deserializer)?))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TaskListImport {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub built_in: bool,
|
||||
#[serde(default)]
|
||||
pub profile_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub created_at: Option<String>, // accepted but ignored — DB sets datetime('now')
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ImportSummaryDto {
|
||||
pub imported: u32,
|
||||
pub skipped: u32,
|
||||
}
|
||||
|
||||
impl From<ImportSummary> for ImportSummaryDto {
|
||||
fn from(s: ImportSummary) -> Self {
|
||||
Self {
|
||||
imported: s.imported as u32,
|
||||
skipped: s.skipped as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_task_lists_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
) -> Result<Vec<TaskListDto>, String> {
|
||||
db_list_task_lists(&state.db)
|
||||
.await
|
||||
.map(|rows| rows.into_iter().map(TaskListDto::from).collect())
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn create_task_list_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
request: CreateTaskListRequest,
|
||||
) -> Result<TaskListDto, String> {
|
||||
db_create_task_list(
|
||||
&state.db,
|
||||
&request.id,
|
||||
&request.name,
|
||||
request.built_in,
|
||||
request.profile_id.as_deref(),
|
||||
)
|
||||
.await
|
||||
.map(TaskListDto::from)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_task_list_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
id: String,
|
||||
patch: UpdateTaskListPatch,
|
||||
) -> Result<TaskListDto, String> {
|
||||
let profile_id_arg = patch.profile_id.as_ref().map(|inner| inner.as_deref());
|
||||
db_update_task_list(&state.db, &id, patch.name.as_deref(), profile_id_arg)
|
||||
.await
|
||||
.map(TaskListDto::from)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn delete_task_list_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
id: String,
|
||||
) -> Result<(), String> {
|
||||
db_delete_task_list(&state.db, &id)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn import_task_lists_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
items: Vec<TaskListImport>,
|
||||
) -> Result<ImportSummaryDto, String> {
|
||||
let rows: Vec<TaskListRow> = items
|
||||
.into_iter()
|
||||
.map(|i| TaskListRow {
|
||||
id: i.id,
|
||||
name: i.name,
|
||||
built_in: i.built_in,
|
||||
profile_id: i.profile_id,
|
||||
// The DB column has DEFAULT datetime('now'); this field is
|
||||
// overwritten by the INSERT for the live row and is only
|
||||
// used to build the in-memory TaskListRow shape passed to
|
||||
// import_task_lists. Use empty string as a placeholder.
|
||||
created_at: i.created_at.unwrap_or_default(),
|
||||
})
|
||||
.collect();
|
||||
db_import_task_lists(&state.db, &rows)
|
||||
.await
|
||||
.map(ImportSummaryDto::from)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
@@ -8,14 +8,15 @@ use uuid::Uuid;
|
||||
|
||||
use kon_llm::prompts::FeedbackExample as LlmFeedbackExample;
|
||||
use kon_storage::{
|
||||
archive_inbox_older_than as db_archive_inbox_older_than, archive_task as db_archive_task,
|
||||
complete_subtask_and_check_parent as db_complete_subtask, complete_task as db_complete_task,
|
||||
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_archived_tasks as db_list_archived_tasks, list_feedback_examples as db_list_feedback_examples,
|
||||
list_recent_completions as db_list_recent_completions, list_subtasks as db_list_subtasks,
|
||||
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, DailyCompletionCount,
|
||||
FeedbackRow, FeedbackTargetType, TaskRow,
|
||||
unarchive_task as db_unarchive_task, uncomplete_task as db_uncomplete_task,
|
||||
update_task as db_update_task, DailyCompletionCount, FeedbackRow, FeedbackTargetType, TaskRow,
|
||||
};
|
||||
|
||||
use crate::AppState;
|
||||
@@ -36,6 +37,11 @@ pub struct TaskDto {
|
||||
pub source_transcript_id: Option<String>,
|
||||
pub parent_task_id: Option<String>,
|
||||
pub energy: Option<String>,
|
||||
/// B2a: archive flag mirrors `tasks.archived` (migration v16). The
|
||||
/// frontend uses this to render the Archived view and to filter the
|
||||
/// per-row archive button into showing "Unarchive" instead.
|
||||
pub archived: bool,
|
||||
pub archived_at: Option<String>,
|
||||
}
|
||||
|
||||
impl From<TaskRow> for TaskDto {
|
||||
@@ -53,6 +59,8 @@ impl From<TaskRow> for TaskDto {
|
||||
source_transcript_id: r.source_transcript_id,
|
||||
parent_task_id: r.parent_task_id,
|
||||
energy: r.energy,
|
||||
archived: r.archived,
|
||||
archived_at: r.archived_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,3 +423,51 @@ pub async fn list_recent_completions_cmd(
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
// --- B2a: archive commands ---
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_archived_tasks_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
) -> Result<Vec<TaskDto>, String> {
|
||||
db_list_archived_tasks(&state.db)
|
||||
.await
|
||||
.map(|rows| rows.into_iter().map(TaskDto::from).collect())
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn archive_task_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
id: String,
|
||||
) -> Result<TaskDto, String> {
|
||||
db_archive_task(&state.db, &id)
|
||||
.await
|
||||
.map(TaskDto::from)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn unarchive_task_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
id: String,
|
||||
) -> Result<TaskDto, String> {
|
||||
db_unarchive_task(&state.db, &id)
|
||||
.await
|
||||
.map(TaskDto::from)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Bulk auto-archive of stale Inbox rows. Returns rows_affected so
|
||||
/// the caller can show a toast like "5 old items archived". Inbox-only
|
||||
/// by design — see `archive_inbox_older_than` in storage.
|
||||
#[tauri::command]
|
||||
pub async fn archive_old_inbox_cmd(
|
||||
state: tauri::State<'_, AppState>,
|
||||
days: u32,
|
||||
) -> Result<u32, String> {
|
||||
db_archive_inbox_older_than(&state.db, days as i64)
|
||||
.await
|
||||
.map(|n| n as u32)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
@@ -362,6 +362,17 @@ pub fn run() {
|
||||
commands::tasks::list_subtasks_cmd,
|
||||
commands::tasks::complete_subtask_cmd,
|
||||
commands::tasks::list_recent_completions_cmd,
|
||||
// B2a — archive surface (Inbox-only auto-sweep + per-row toggle)
|
||||
commands::tasks::list_archived_tasks_cmd,
|
||||
commands::tasks::archive_task_cmd,
|
||||
commands::tasks::unarchive_task_cmd,
|
||||
commands::tasks::archive_old_inbox_cmd,
|
||||
// B2a — task_lists CRUD (replaces the localStorage source of truth)
|
||||
commands::task_lists::list_task_lists_cmd,
|
||||
commands::task_lists::create_task_list_cmd,
|
||||
commands::task_lists::update_task_list_cmd,
|
||||
commands::task_lists::delete_task_list_cmd,
|
||||
commands::task_lists::import_task_lists_cmd,
|
||||
// HITL feedback (Phase 2 roadmap)
|
||||
commands::feedback::record_feedback,
|
||||
commands::feedback::list_feedback_examples_cmd,
|
||||
|
||||
Reference in New Issue
Block a user