include/entropic/storage/backend.h¶
include/entropic/storage/backend.h
entropic::SqliteStorageBackend
SQLite-based storage backend.
entropic::SqliteStorageBackend::SqliteStorageBackend(const std::filesystem::path &db_path)
Construct with database file path.
- Parameters
db_path— Path to SQLite database file.db_path— Path to SQLite file.
bool entropic::SqliteStorageBackend::initialize()
Initialize storage (open database, run migrations).
Initialize storage.
- Returns
- true on success.
void entropic::SqliteStorageBackend::close()
Close storage and database connection.
Close storage.
std::string entropic::SqliteStorageBackend::create_conversation(const std::string &title="New Conversation", const std::optional< std::string > &project_path=std::nullopt, const std::optional< std::string > &model_id=std::nullopt)
Create a new conversation.
- Parameters
title— Conversation title.project_path— Project path (optional).model_id— Model identifier (optional).project_path— Optional project path.model_id— Optional model identifier.
- Returns
- Conversation ID (UUID string).
- Conversation ID.
bool entropic::SqliteStorageBackend::save_messages(const std::string &conversation_id, const std::string &messages_json)
Save messages to a conversation.
- Parameters
conversation_id— Conversation ID.messages_json— JSON array of message objects.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::load_conversation(const std::string &conversation_id, std::string &result_json)
Load a conversation with messages.
Load a conversation with its messages.
- Parameters
conversation_id— Conversation ID.result_jsonout — JSON with "conversation" and "messages".result_jsonout — JSON result.
- Returns
- true if found.
bool entropic::SqliteStorageBackend::list_conversations(int limit, int offset, std::string &result_json)
List conversations with pagination.
- Parameters
limit— Maximum results.offset— Pagination offset.result_jsonout — JSON array of conversation summaries.limit— Max results.result_jsonout — JSON array of summaries.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::delete_conversation(const std::string &conversation_id)
Delete a conversation and all associated records.
Delete a conversation and all cascading records.
- Parameters
conversation_id— Conversation ID.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::update_title(const std::string &conversation_id, const std::string &title)
Update a conversation's title.
- Parameters
conversation_id— Conversation ID.title— New title.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::search_conversations(const std::string &query, int limit, std::string &result_json)
Full-text search across conversations.
Full-text search across conversations via FTS5.
- Parameters
query— FTS5 query string.limit— Maximum results.result_jsonout — JSON array of search results with snippets.limit— Max results.result_jsonout — JSON array of search results.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::create_delegation(const std::string &parent_conversation_id, const std::string &delegating_tier, const std::string &target_tier, const std::string &task, int max_turns, std::string &delegation_id, std::string &child_conversation_id)
Create a delegation record with a child conversation.
Create a delegation with a child conversation.
- Parameters
parent_conversation_id— Parent conversation ID.delegating_tier— Tier initiating delegation.target_tier— Target tier for child loop.task— Task description.max_turns— Max turns for child (0 = unlimited).delegation_idout — Created delegation ID.child_conversation_idout — Created child conversation ID.parent_conversation_id— Parent conversation.delegating_tier— Source tier.target_tier— Target tier.max_turns— Turn limit (0 = unlimited).
- Returns
- true on success.
bool entropic::SqliteStorageBackend::complete_delegation(const std::string &delegation_id, const std::string &status, const std::optional< std::string > &result_summary=std::nullopt)
Mark a delegation as completed or failed.
- Parameters
delegation_id— Delegation ID.status— "completed" or "failed".result_summary— Summary text (optional).result_summary— Optional summary text.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::get_delegations(const std::string &conversation_id, std::string &result_json)
Get delegations for a parent conversation.
- Parameters
conversation_id— Parent conversation ID.result_jsonout — JSON array of delegation records.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::get_delegation_by_id(const std::string &delegation_id, std::string &result_json)
Look up a single delegation record by id (gh#32, v2.1.6).
Used by entropic.followup and entropic.resume_delegation to resolve a delegation's target_tier and child_conversation_id without scanning all parents.
- Parameters
delegation_id— Delegation id.result_jsonout — Single-object JSON with the delegation row.result_jsonout — Object JSON of the delegation row.
- Returns
- true on success and a row was found; false on absence/error.
- true if found and parsed.
bool entropic::SqliteStorageBackend::latest_delegation_for_target(const std::string &target_tier, std::string &delegation_id)
Search delegations across all conversations (gh#32, v2.1.6).
Most recent completed delegation to a tier (gh#162). Substring match against result_summary (case-insensitive). Returns the top-N most recently completed delegations whose summary contains query. Most recent completed delegation to a tier (gh#162, v2.13.0). Backs entropic.resume_delegation's target form. Only completed rows are eligible: resuming a delegation that failed or is still running would seed the child with a broken conversation.
- Parameters
query— Keyword/phrase to match.max_results— Maximum records to return.result_jsonout — JSON array of matching delegation rows.target_tier— Tier to search for.delegation_idout — Resolved id on success.
- Returns
- true on success.
- true when such a delegation exists.
bool entropic::SqliteStorageBackend::search_delegations(const std::string &query, int max_results, std::string &result_json)
Substring-match delegations across all conversations.
Bound to top-N most recently completed records. Uses sqlite's LIKE for portability — FTS5 is wired for messages, not delegation summaries.
- Parameters
query— Substring to match (LIKE query%).max_results— Cap on returned rows.result_jsonout — JSON array of delegation rows.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::save_snapshot(const std::string &conversation_id, const std::string &messages_json)
Save a pre-compaction snapshot of full conversation history.
Save a pre-compaction snapshot.
- Parameters
conversation_id— Conversation ID.messages_json— JSON array of all messages before compaction.messages_json— JSON array of all messages.
- Returns
- true on success.
bool entropic::SqliteStorageBackend::get_stats(std::string &result_json)
Get storage statistics.
- Parameters
result_jsonout — JSON with total_conversations, total_messages, total_tokens.result_jsonout — JSON with counts.
- Returns
- true on success.