Skip to main content

SqliteStorage

Struct SqliteStorage 

Source
pub struct SqliteStorage { /* private fields */ }
Expand description

SQLite-based storage backend.

Implementations§

Source§

impl SqliteStorage

Source

pub fn open(path: &Path) -> Result<Self>

Open a database at the given path.

Creates the database and applies schema if it doesn’t exist.

§Errors

Returns an error if the connection cannot be established or schema fails.

Source

pub fn open_with_timeout(path: &Path, timeout_ms: Option<u64>) -> Result<Self>

Open a database with an optional busy timeout.

§Errors

Returns an error if the connection cannot be established or schema fails.

Source

pub fn open_memory() -> Result<Self>

Open an in-memory database (for testing).

§Errors

Returns an error if the connection cannot be established.

Source

pub fn conn(&self) -> &Connection

Get a reference to the underlying connection (for read operations).

Source

pub fn checkpoint(&self) -> Result<()>

Flush the WAL journal into the main database file.

Runs PRAGMA wal_checkpoint(TRUNCATE) which moves all WAL content into the main DB file and then truncates the WAL to zero bytes. This ensures the .db file is self-contained for backup purposes.

Source

pub fn backup_to(&self, dest_path: &Path) -> Result<()>

Create a consistent backup of the database at dest_path.

First checkpoints the WAL, then uses SQLite’s Online Backup API to produce a point-in-time snapshot. Safe to call while the database is open and even during concurrent reads.

Source

pub fn mutate<F, R>(&mut self, op: &str, actor: &str, f: F) -> Result<R>
where F: FnOnce(&Transaction<'_>, &mut MutationContext) -> Result<R>,

Execute a mutation with the transaction protocol.

This method:

  1. Begins an IMMEDIATE transaction (for write locking)
  2. Executes the mutation closure
  3. Writes audit events
  4. Updates dirty tracking tables
  5. Commits (or rolls back on error)
§Errors

Returns an error if any step fails. The transaction is rolled back on error.

Source

pub fn create_session( &mut self, id: &str, name: &str, description: Option<&str>, project_path: Option<&str>, branch: Option<&str>, actor: &str, ) -> Result<()>

Create a new session.

§Errors

Returns an error if the insert fails.

Source

pub fn get_session(&self, id: &str) -> Result<Option<Session>>

Get a session by ID.

§Errors

Returns an error if the query fails.

Source

pub fn list_sessions( &self, project_path: Option<&str>, status: Option<&str>, limit: Option<u32>, ) -> Result<Vec<Session>>

List sessions with optional filters.

§Errors

Returns an error if the query fails.

List sessions with optional filters and search.

Uses the session_projects junction table for project path filtering, matching the MCP server’s listSessionsByPaths behavior.

§Errors

Returns an error if the query fails.

Source

pub fn update_session_status( &mut self, id: &str, status: &str, actor: &str, ) -> Result<()>

Update session status.

§Errors

Returns an error if the update fails or session not found.

Source

pub fn rename_session( &mut self, id: &str, new_name: &str, actor: &str, ) -> Result<()>

Rename a session.

§Errors

Returns an error if the update fails or session not found.

Source

pub fn delete_session(&mut self, id: &str, actor: &str) -> Result<()>

Delete a session and all related data.

This cascades to delete:

  • Context items in the session
  • Checkpoints for the session
  • Session project paths
§Errors

Returns an error if the session doesn’t exist or can’t be deleted.

Source

pub fn add_session_path( &mut self, session_id: &str, project_path: &str, actor: &str, ) -> Result<()>

Add a project path to a session (for multi-project sessions).

§Errors

Returns an error if the session doesn’t exist or the path is already added.

Source

pub fn remove_session_path( &mut self, session_id: &str, project_path: &str, actor: &str, ) -> Result<()>

Remove a project path from a session.

Cannot remove the last path (sessions must have at least the primary path).

§Errors

Returns an error if the session doesn’t exist or this is the last path.

Source

pub fn get_session_paths(&self, session_id: &str) -> Result<Vec<String>>

Get all project paths for a session.

Returns the primary path from the session plus any additional paths from session_projects.

Source

pub fn save_context_item( &mut self, id: &str, session_id: &str, key: &str, value: &str, category: Option<&str>, priority: Option<&str>, actor: &str, ) -> Result<()>

Save a context item (upsert).

§Errors

Returns an error if the operation fails.

Source

pub fn get_item_id_by_key( &self, session_id: &str, key: &str, ) -> Result<Option<String>>

Look up the actual item ID by session + key.

Needed after upserts where ON CONFLICT keeps the original ID.

Source

pub fn get_items_with_fast_embeddings( &self, session_id: &str, ) -> Result<Vec<(ContextItem, Option<Vec<f32>>)>>

Get all context items for a session with their fast-tier embeddings (if any).

Single LEFT JOIN query — items without embeddings get None. Only fetches chunk_index=0 (the primary embedding per item).

Source

pub fn get_context_items( &self, session_id: &str, category: Option<&str>, priority: Option<&str>, limit: Option<u32>, ) -> Result<Vec<ContextItem>>

Get context items for a session.

§Errors

Returns an error if the query fails.

Source

pub fn delete_context_item( &mut self, session_id: &str, key: &str, actor: &str, ) -> Result<()>

Delete a context item.

§Errors

Returns an error if the delete fails.

Source

pub fn update_context_item( &mut self, session_id: &str, key: &str, value: Option<&str>, category: Option<&str>, priority: Option<&str>, channel: Option<&str>, actor: &str, ) -> Result<()>

Update a context item’s value, category, priority, or channel.

§Errors

Returns an error if the update fails.

Source

pub fn add_tags_to_item( &mut self, session_id: &str, key: &str, tags_to_add: &[String], actor: &str, ) -> Result<()>

Add tags to a context item.

§Errors

Returns an error if the update fails.

Source

pub fn remove_tags_from_item( &mut self, session_id: &str, key: &str, tags_to_remove: &[String], actor: &str, ) -> Result<()>

Remove tags from a context item.

§Errors

Returns an error if the update fails.

Source

pub fn create_issue( &mut self, id: &str, short_id: Option<&str>, project_path: &str, title: &str, description: Option<&str>, details: Option<&str>, issue_type: Option<&str>, priority: Option<i32>, plan_id: Option<&str>, actor: &str, ) -> Result<()>

Create a new issue.

§Errors

Returns an error if the insert fails.

Source

pub fn get_issue( &self, id: &str, project_path: Option<&str>, ) -> Result<Option<Issue>>

Get an issue by ID (full ID or short ID).

§Errors

Returns an error if the query fails.

Source

pub fn list_issues( &self, project_path: &str, status: Option<&str>, issue_type: Option<&str>, limit: Option<u32>, ) -> Result<Vec<Issue>>

List issues with filters.

§Errors

Returns an error if the query fails.

Source

pub fn list_all_issues( &self, status: Option<&str>, issue_type: Option<&str>, limit: Option<u32>, ) -> Result<Vec<Issue>>

List issues across all projects.

§Errors

Returns an error if the query fails.

Source

pub fn update_issue_status( &mut self, id: &str, status: &str, actor: &str, ) -> Result<()>

Update issue status.

Accepts either full ID or short_id.

§Errors

Returns an error if the update fails.

Source

pub fn update_issue( &mut self, id: &str, title: Option<&str>, description: Option<&str>, details: Option<&str>, priority: Option<i32>, issue_type: Option<&str>, plan_id: Option<&str>, parent_id: Option<&str>, actor: &str, ) -> Result<()>

Update issue fields (title, description, details, priority, issue_type).

Only updates fields that are Some. Status is handled separately.

§Errors

Returns an error if the update fails.

Source

pub fn claim_issue(&mut self, id: &str, actor: &str) -> Result<()>

Claim an issue (assign to agent).

Accepts either full ID or short_id.

§Errors

Returns an error if the claim fails.

Source

pub fn release_issue(&mut self, id: &str, actor: &str) -> Result<()>

Release an issue (unassign).

Accepts either full ID or short_id.

§Errors

Returns an error if the release fails.

Source

pub fn delete_issue(&mut self, id: &str, actor: &str) -> Result<()>

Delete an issue.

Accepts either full ID or short_id.

§Errors

Returns an error if the delete fails.

Source

pub fn add_issue_labels( &mut self, id: &str, labels: &[String], actor: &str, ) -> Result<()>

Add labels to an issue.

§Errors

Returns an error if the operation fails.

Source

pub fn remove_issue_labels( &mut self, id: &str, labels: &[String], actor: &str, ) -> Result<()>

Remove labels from an issue.

§Errors

Returns an error if the operation fails.

Source

pub fn get_issue_labels(&self, id: &str) -> Result<Vec<String>>

Get labels for an issue.

§Errors

Returns an error if the query fails.

Source

pub fn issue_has_dependencies(&self, id: &str) -> Result<bool>

Check if an issue has any dependencies (depends on other issues).

Source

pub fn issue_has_subtasks(&self, id: &str) -> Result<bool>

Check if an issue has any subtasks (child issues via parent-child dependency).

Source

pub fn get_child_issue_ids(&self, parent_id: &str) -> Result<HashSet<String>>

Get the set of issue IDs that are children of a specific parent.

Returns IDs of issues that have a parent-child dependency on the given parent ID.

Source

pub fn add_issue_dependency( &mut self, issue_id: &str, depends_on_id: &str, dependency_type: &str, actor: &str, ) -> Result<()>

Add a dependency between issues.

§Errors

Returns an error if the operation fails.

Source

pub fn remove_issue_dependency( &mut self, issue_id: &str, depends_on_id: &str, actor: &str, ) -> Result<()>

Remove a dependency between issues.

§Errors

Returns an error if the operation fails.

Source

pub fn clone_issue( &mut self, id: &str, new_title: Option<&str>, actor: &str, ) -> Result<Issue>

Clone an issue.

§Errors

Returns an error if the operation fails.

Source

pub fn mark_issue_duplicate( &mut self, id: &str, duplicate_of_id: &str, actor: &str, ) -> Result<()>

Mark an issue as a duplicate of another.

§Errors

Returns an error if the operation fails.

Source

pub fn get_ready_issues( &self, project_path: &str, limit: u32, ) -> Result<Vec<Issue>>

Get issues that are ready to work on (open, no blocking dependencies, not assigned).

§Errors

Returns an error if the query fails.

Source

pub fn get_next_issue_block( &mut self, project_path: &str, count: u32, actor: &str, ) -> Result<Vec<Issue>>

Get and claim next block of ready issues.

§Errors

Returns an error if the operation fails.

Source

pub fn count_issues_grouped( &self, project_path: &str, group_by: &str, ) -> Result<Vec<(String, i64)>>

Count issues grouped by a field (status, type, priority, assignee).

Source

pub fn get_stale_issues( &self, project_path: &str, stale_days: u64, limit: u32, ) -> Result<Vec<Issue>>

Get stale issues (not updated in N days).

Source

pub fn get_blocked_issues( &self, project_path: &str, limit: u32, ) -> Result<Vec<(Issue, Vec<Issue>)>>

Get blocked issues with their blockers.

Source

pub fn get_epic_progress(&self, epic_id: &str) -> Result<EpicProgress>

Get epic progress (child issue counts by status).

Source

pub fn get_dependency_tree(&self, root_id: &str) -> Result<Vec<(Issue, i32)>>

Get dependency tree starting from a root issue. Returns (issue, depth) pairs in tree order.

Source

pub fn get_epics(&self, project_path: &str) -> Result<Vec<Issue>>

Get all epics for a project.

Source

pub fn set_close_reason( &mut self, id: &str, reason: &str, actor: &str, ) -> Result<()>

Update close_reason on an issue.

Source

pub fn get_close_reason(&self, id: &str) -> Result<Option<String>>

Get close_reason for an issue.

Source

pub fn create_checkpoint( &mut self, id: &str, session_id: &str, name: &str, description: Option<&str>, git_status: Option<&str>, git_branch: Option<&str>, actor: &str, ) -> Result<()>

Create a checkpoint.

§Errors

Returns an error if the insert fails.

Source

pub fn add_checkpoint_item( &mut self, checkpoint_id: &str, context_item_id: &str, actor: &str, ) -> Result<()>

Add an item to a checkpoint.

§Errors

Returns an error if the insert fails.

Source

pub fn count_items_since_last_checkpoint(&self, session_id: &str) -> Result<i64>

Count context items created since the most recent checkpoint for a session.

Returns 0 if no items exist. If no checkpoint exists, counts all items.

§Errors

Returns an error if the query fails.

Source

pub fn list_checkpoints( &self, session_id: &str, limit: Option<u32>, ) -> Result<Vec<Checkpoint>>

List checkpoints for a session.

§Errors

Returns an error if the query fails.

Source

pub fn get_checkpoint(&self, id: &str) -> Result<Option<Checkpoint>>

Get a checkpoint by ID.

§Errors

Returns an error if the query fails.

Source

pub fn delete_checkpoint(&mut self, id: &str, actor: &str) -> Result<()>

Delete a checkpoint.

§Errors

Returns an error if the delete fails.

Source

pub fn get_checkpoint_items( &self, checkpoint_id: &str, ) -> Result<Vec<ContextItem>>

Get context items in a checkpoint.

§Errors

Returns an error if the query fails.

Source

pub fn restore_checkpoint( &mut self, checkpoint_id: &str, target_session_id: &str, restore_categories: Option<&[String]>, restore_tags: Option<&[String]>, actor: &str, ) -> Result<usize>

Restore a checkpoint to a target session.

This clears existing context items in the target session and recreates them from the checkpoint. Optional filters can limit which items are restored.

§Errors

Returns an error if the restore fails.

Source

pub fn remove_checkpoint_item( &mut self, checkpoint_id: &str, context_item_id: &str, actor: &str, ) -> Result<()>

Remove an item from a checkpoint by context item ID.

§Errors

Returns an error if the delete fails.

Source

pub fn add_checkpoint_items_by_keys( &mut self, checkpoint_id: &str, session_id: &str, keys: &[String], actor: &str, ) -> Result<usize>

Add items to checkpoint by their keys (from current session).

§Errors

Returns an error if the operation fails.

Source

pub fn remove_checkpoint_items_by_keys( &mut self, checkpoint_id: &str, keys: &[String], actor: &str, ) -> Result<usize>

Remove items from checkpoint by their keys.

§Errors

Returns an error if the operation fails.

Source

pub fn save_memory( &mut self, id: &str, project_path: &str, key: &str, value: &str, category: &str, actor: &str, ) -> Result<()>

Save a memory item (project-level persistent storage).

§Errors

Returns an error if the operation fails.

Source

pub fn get_memory( &self, project_path: &str, key: &str, ) -> Result<Option<Memory>>

Get a memory item by key.

§Errors

Returns an error if the query fails.

Source

pub fn list_memory( &self, project_path: &str, category: Option<&str>, ) -> Result<Vec<Memory>>

List memory items for a project.

§Errors

Returns an error if the query fails.

Source

pub fn delete_memory( &mut self, project_path: &str, key: &str, actor: &str, ) -> Result<()>

Delete a memory item.

§Errors

Returns an error if the delete fails.

Source

pub fn get_dirty_sessions(&self) -> Result<Vec<String>>

Get IDs of all dirty sessions (pending export).

§Errors

Returns an error if the query fails.

Source

pub fn get_dirty_issues(&self) -> Result<Vec<String>>

Get IDs of all dirty issues (pending export).

§Errors

Returns an error if the query fails.

Source

pub fn get_dirty_context_items(&self) -> Result<Vec<String>>

Get IDs of all dirty context items (pending export).

§Errors

Returns an error if the query fails.

Source

pub fn clear_dirty_sessions(&mut self, ids: &[String]) -> Result<()>

Clear dirty flags for sessions after successful export.

§Errors

Returns an error if the delete fails.

Source

pub fn clear_dirty_issues(&mut self, ids: &[String]) -> Result<()>

Clear dirty flags for issues after successful export.

§Errors

Returns an error if the delete fails.

Source

pub fn clear_dirty_context_items(&mut self, ids: &[String]) -> Result<()>

Clear dirty flags for context items after successful export.

§Errors

Returns an error if the delete fails.

Source

pub fn get_export_hash( &self, entity_type: &str, entity_id: &str, ) -> Result<Option<String>>

Get the stored content hash for an entity (for incremental export).

§Errors

Returns an error if the query fails.

Source

pub fn set_export_hash( &mut self, entity_type: &str, entity_id: &str, hash: &str, ) -> Result<()>

Store a content hash after successful export.

§Errors

Returns an error if the upsert fails.

Source

pub fn record_deletion( &mut self, entity_type: &str, entity_id: &str, project_path: &str, actor: &str, ) -> Result<()>

Record a deletion for sync export.

This should be called when an entity is deleted so that the deletion can be exported and applied on other machines.

§Errors

Returns an error if the insert fails.

Source

pub fn get_pending_deletions( &self, project_path: &str, ) -> Result<Vec<SyncDeletion>>

Get pending deletions for a project that haven’t been exported yet.

§Errors

Returns an error if the query fails.

Source

pub fn get_all_deletions(&self, project_path: &str) -> Result<Vec<SyncDeletion>>

Get all deletions for a project (for full export).

§Errors

Returns an error if the query fails.

Source

pub fn mark_deletions_exported(&mut self, ids: &[i64]) -> Result<()>

Mark deletions as exported.

§Errors

Returns an error if the update fails.

Source

pub fn count_pending_deletions(&self, project_path: &str) -> Result<usize>

Count pending deletions for a project.

§Errors

Returns an error if the query fails.

Source

pub fn apply_deletion( &mut self, entity_type: &str, entity_id: &str, ) -> Result<bool>

Delete entity by ID for import (applies deletion from another machine).

§Errors

Returns an error if the delete fails.

Source

pub fn get_all_sessions(&self) -> Result<Vec<Session>>

Get all sessions (for full export).

§Errors

Returns an error if the query fails.

Source

pub fn get_all_issues(&self) -> Result<Vec<Issue>>

Get all issues (for full export).

§Errors

Returns an error if the query fails.

Source

pub fn get_all_context_items( &self, category: Option<&str>, priority: Option<&str>, limit: Option<u32>, ) -> Result<Vec<ContextItem>>

Get all context items (for full export).

§Errors

Returns an error if the query fails.

Source

pub fn get_all_memory(&self) -> Result<Vec<Memory>>

Get all memory items (for full export).

§Errors

Returns an error if the query fails.

Source

pub fn get_all_issue_short_ids(&self) -> Result<Vec<String>>

Get all issue short IDs (for Levenshtein suggestions).

Returns short_ids (e.g. “SC-a1b2”) for all issues, used by find_similar_ids() when an issue lookup fails.

Source

pub fn get_all_session_ids(&self) -> Result<Vec<String>>

Get all session IDs (for Levenshtein suggestions).

Source

pub fn get_all_checkpoint_ids(&self) -> Result<Vec<String>>

Get all checkpoint IDs (for Levenshtein suggestions).

Source

pub fn get_all_checkpoints(&self) -> Result<Vec<Checkpoint>>

Get all checkpoints (for full export).

§Errors

Returns an error if the query fails.

Source

pub fn get_context_item(&self, id: &str) -> Result<Option<ContextItem>>

Get a context item by ID.

§Errors

Returns an error if the query fails.

Source

pub fn get_sessions_by_project( &self, project_path: &str, ) -> Result<Vec<Session>>

Get all sessions for a specific project.

§Errors

Returns an error if the query fails.

Source

pub fn get_issues_by_project(&self, project_path: &str) -> Result<Vec<Issue>>

Get all issues for a specific project.

§Errors

Returns an error if the query fails.

Source

pub fn get_context_items_by_project( &self, project_path: &str, ) -> Result<Vec<ContextItem>>

Get all context items for sessions in a specific project.

Context items are linked to sessions, so we join on session_id and filter by the session’s project_path.

§Errors

Returns an error if the query fails.

Source

pub fn get_memory_by_project(&self, project_path: &str) -> Result<Vec<Memory>>

Get all memory items for a specific project.

§Errors

Returns an error if the query fails.

Source

pub fn get_checkpoints_by_project( &self, project_path: &str, ) -> Result<Vec<Checkpoint>>

Get all checkpoints for sessions in a specific project.

Checkpoints are linked to sessions, so we join on session_id and filter by the session’s project_path.

§Errors

Returns an error if the query fails.

Source

pub fn get_dirty_sessions_by_project( &self, project_path: &str, ) -> Result<Vec<String>>

Get dirty session IDs for a specific project.

§Errors

Returns an error if the query fails.

Source

pub fn get_dirty_issues_by_project( &self, project_path: &str, ) -> Result<Vec<String>>

Get dirty issue IDs for a specific project.

§Errors

Returns an error if the query fails.

Source

pub fn get_dirty_context_items_by_project( &self, project_path: &str, ) -> Result<Vec<String>>

Get dirty context item IDs for a specific project.

§Errors

Returns an error if the query fails.

Source

pub fn backfill_dirty_for_project( &mut self, project_path: &str, ) -> Result<BackfillStats>

Backfill dirty tables with all records for a project.

This is used on first sync export when no prior exports exist. It marks all existing records for the project as dirty so they get included in the initial export.

§Errors

Returns an error if the queries fail.

Source

pub fn get_project_counts(&self, project_path: &str) -> Result<ProjectCounts>

Get total record counts for a project (for status display).

§Errors

Returns an error if the query fails.

Source

pub fn upsert_session(&mut self, session: &Session) -> Result<()>

Upsert a session (for sync import).

This performs an INSERT OR REPLACE, preserving all fields from the imported record.

§Errors

Returns an error if the upsert fails.

Source

pub fn upsert_issue(&mut self, issue: &Issue) -> Result<()>

Upsert an issue (for sync import).

§Errors

Returns an error if the upsert fails.

Source

pub fn upsert_context_item(&mut self, item: &ContextItem) -> Result<()>

Upsert a context item (for sync import).

§Errors

Returns an error if the upsert fails.

Source

pub fn upsert_memory(&mut self, memory: &Memory) -> Result<()>

Upsert a memory item (for sync import).

§Errors

Returns an error if the upsert fails.

Source

pub fn upsert_checkpoint(&mut self, checkpoint: &Checkpoint) -> Result<()>

Upsert a checkpoint (for sync import).

Note: This does not import checkpoint items - those would need separate handling.

§Errors

Returns an error if the upsert fails.

Source

pub fn create_project(&mut self, project: &Project, actor: &str) -> Result<()>

Create a new project.

§Errors

Returns an error if the project already exists or the insert fails.

Source

pub fn get_project(&self, id: &str) -> Result<Option<Project>>

Get a project by ID.

§Errors

Returns an error if the query fails.

Source

pub fn get_project_by_path(&self, project_path: &str) -> Result<Option<Project>>

Get a project by path.

§Errors

Returns an error if the query fails.

Source

pub fn list_projects(&self, limit: usize) -> Result<Vec<Project>>

List all projects.

§Errors

Returns an error if the query fails.

Source

pub fn update_project( &mut self, id: &str, name: Option<&str>, description: Option<&str>, issue_prefix: Option<&str>, actor: &str, ) -> Result<()>

Update a project.

§Errors

Returns an error if the project doesn’t exist or the update fails.

Source

pub fn delete_project(&mut self, id: &str, actor: &str) -> Result<()>

Delete a project and all associated data.

This cascades to delete:

  • All sessions (and their context items, checkpoints)
  • All issues
  • All plans
  • All project memory
§Errors

Returns an error if the project doesn’t exist or deletion fails.

Source

pub fn get_or_create_project( &mut self, project_path: &str, actor: &str, ) -> Result<Project>

Get or create a project for the given path.

If a project already exists at the path, returns it. Otherwise, creates a new project with a name derived from the path.

§Errors

Returns an error if the database operation fails.

Source

pub fn get_next_issue_number(&mut self, project_path: &str) -> Result<i32>

Increment and return the next issue number for a project.

§Errors

Returns an error if the project doesn’t exist or the update fails.

Source

pub fn create_plan(&mut self, plan: &Plan, actor: &str) -> Result<()>

Create a new plan.

§Errors

Returns an error if the plan already exists or the insert fails.

Source

pub fn get_plan(&self, id: &str) -> Result<Option<Plan>>

Get a plan by ID.

§Errors

Returns an error if the query fails.

Source

pub fn list_plans( &self, project_path: &str, status: Option<&str>, limit: usize, ) -> Result<Vec<Plan>>

List plans for a project.

§Errors

Returns an error if the query fails.

Source

pub fn update_plan( &mut self, id: &str, title: Option<&str>, content: Option<&str>, status: Option<&str>, success_criteria: Option<&str>, actor: &str, ) -> Result<()>

Update a plan.

§Errors

Returns an error if the plan doesn’t exist or the update fails.

Source

pub fn get_plans_by_project(&self, project_path: &str) -> Result<Vec<Plan>>

Get all plans for a specific project (for JSONL sync export).

§Errors

Returns an error if the query fails.

Source

pub fn find_plan_by_source_hash( &self, source_hash: &str, ) -> Result<Option<Plan>>

Find a plan by source hash (for capture deduplication).

§Errors

Returns an error if the query fails.

Source

pub fn upsert_plan(&mut self, plan: &Plan) -> Result<()>

Upsert a plan (for sync import).

§Errors

Returns an error if the upsert fails.

Source

pub fn get_dirty_plans_by_project( &self, project_path: &str, ) -> Result<Vec<String>>

Get dirty plan IDs by project (for JSONL sync export).

§Errors

Returns an error if the query fails.

Source

pub fn clear_dirty_plans(&mut self, ids: &[String]) -> Result<()>

Clear dirty flags for plans after successful export.

§Errors

Returns an error if the delete fails.

Source

pub fn create_time_entry( &mut self, id: &str, short_id: Option<&str>, project_path: &str, hours: f64, description: &str, work_date: &str, issue_id: Option<&str>, period: Option<&str>, actor: &str, ) -> Result<()>

Create a new time entry.

Source

pub fn get_time_entry( &self, id: &str, project_path: Option<&str>, ) -> Result<Option<TimeEntry>>

Get a time entry by ID (full or short).

Source

pub fn list_time_entries( &self, project_path: &str, period: Option<&str>, status: Option<&str>, issue_id: Option<&str>, date_from: Option<&str>, date_to: Option<&str>, limit: Option<u32>, ) -> Result<Vec<TimeEntry>>

List time entries with optional filters.

Source

pub fn update_time_entry( &mut self, id: &str, project_path: &str, hours: Option<f64>, description: Option<&str>, period: Option<&str>, issue_id: Option<&str>, work_date: Option<&str>, actor: &str, ) -> Result<()>

Update a time entry (partial fields).

Source

pub fn update_time_entry_status( &mut self, id: &str, project_path: &str, status: &str, actor: &str, ) -> Result<()>

Update time entry status.

Source

pub fn invoice_time_entries( &mut self, project_path: &str, period: &str, from_status: &str, to_status: &str, actor: &str, ) -> Result<(usize, f64)>

Batch update time entries from one status to another for a period. Returns (count, total_hours).

Source

pub fn delete_time_entry( &mut self, id: &str, project_path: &str, actor: &str, ) -> Result<()>

Delete a time entry.

Source

pub fn get_time_total( &self, project_path: &str, period: Option<&str>, status: Option<&str>, ) -> Result<f64>

Get total hours for a project, optionally filtered by period and/or status.

Source

pub fn get_issue_time_total(&self, issue_id: &str) -> Result<f64>

Get total hours logged against a specific issue.

Source

pub fn get_time_entries_by_project( &self, project_path: &str, ) -> Result<Vec<TimeEntry>>

Get all time entries for a project (for sync export).

Source

pub fn get_dirty_time_entries_by_project( &self, project_path: &str, ) -> Result<Vec<String>>

Get dirty time entry IDs for a project.

Source

pub fn clear_dirty_time_entries(&mut self, ids: &[String]) -> Result<()>

Clear dirty flags for time entries after export.

Source

pub fn upsert_time_entry(&mut self, entry: &TimeEntry) -> Result<()>

Upsert a time entry (for sync import).

Source

pub fn store_embedding_chunk( &mut self, id: &str, item_id: &str, chunk_index: i32, chunk_text: &str, embedding: &[f32], provider: &str, model: &str, ) -> Result<()>

Store an embedding chunk for a context item.

Embeddings are stored as BLOBs (binary f32 arrays). Large items may have multiple chunks for full semantic coverage.

§Errors

Returns an error if the insert fails.

Source

pub fn get_embedding_chunks(&self, item_id: &str) -> Result<Vec<EmbeddingChunk>>

Get embedding chunks for a context item.

§Errors

Returns an error if the query fails.

Source

pub fn get_items_without_embeddings( &self, session_id: Option<&str>, limit: Option<u32>, ) -> Result<Vec<ContextItem>>

Get context items without embeddings (for backfill).

§Errors

Returns an error if the query fails.

Source

pub fn count_embedding_status( &self, session_id: Option<&str>, ) -> Result<EmbeddingStats>

Count items with and without embeddings.

§Errors

Returns an error if the query fails.

Source

pub fn resync_embedding_status(&self) -> Result<usize>

Resync embedding status for items claiming ‘complete’ but lacking actual data.

Migration 011 dropped the old vec_context_chunks table and reset statuses to ‘pending’, but subsequent logic set them back to ‘complete’ without actual embedding data. This method detects and fixes that mismatch.

Returns the number of items reset.

§Errors

Returns an error if the query fails.

Perform semantic search using cosine similarity.

This is a brute-force search that computes cosine similarity between the query embedding and all stored embeddings. Efficient for <50K items; use Hora for larger datasets.

§Errors

Returns an error if the query fails.

Source

pub fn delete_embeddings(&mut self, item_id: &str) -> Result<()>

Delete embeddings for a context item.

§Errors

Returns an error if the delete fails.

Source

pub fn get_embedding_meta(&self, key: &str) -> Result<Option<String>>

Get embedding metadata (provider, model, dimensions).

§Errors

Returns an error if the query fails.

Source

pub fn set_embedding_meta(&mut self, key: &str, value: &str) -> Result<()>

Set embedding metadata.

§Errors

Returns an error if the upsert fails.

Source

pub fn store_fast_embedding_chunk( &mut self, id: &str, item_id: &str, chunk_index: i32, chunk_text: &str, embedding: &[f32], model: &str, ) -> Result<()>

Store a fast-tier embedding chunk (Model2Vec).

Fast tier embeddings are stored separately for dimension isolation. These are generated inline on save for instant semantic search.

§Errors

Returns an error if the insert fails.

Source

pub fn search_fast_tier( &self, query_embedding: &[f32], session_id: Option<&str>, limit: usize, threshold: f32, ) -> Result<Vec<SemanticSearchResult>>

Search fast-tier embeddings only.

Returns candidates for tiered search or direct fast results. Fast tier is optimized for speed over accuracy.

§Errors

Returns an error if the query fails.

Source

pub fn get_items_needing_quality_upgrade( &self, session_id: Option<&str>, limit: Option<u32>, ) -> Result<Vec<ContextItem>>

Get context items with fast embeddings but no quality embeddings.

Used by background quality upgrade process.

§Errors

Returns an error if the query fails.

Source

pub fn delete_fast_embeddings(&mut self, item_id: &str) -> Result<()>

Delete fast-tier embeddings for a context item.

§Errors

Returns an error if the delete fails.

Source

pub fn count_fast_embedding_status( &self, session_id: Option<&str>, ) -> Result<EmbeddingStats>

Count fast embedding status.

§Errors

Returns an error if the query fails.

Trait Implementations§

Source§

impl Debug for SqliteStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more