pub struct ContextStore { /* private fields */ }Expand description
A key-value context store for AI coding agents.
Provides namespaced storage with git-aware invalidation for caching file summaries, symbol indexes, project metadata, and session context.
Implementations§
Source§impl ContextStore
impl ContextStore
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open or create a context store at the given path.
Sourcepub fn with_git_repo(self, repo_path: impl AsRef<Path>) -> Result<Self>
pub fn with_git_repo(self, repo_path: impl AsRef<Path>) -> Result<Self>
Initialize git-aware invalidation from a repository.
Sourcepub fn refresh_git_state(&self) -> Result<()>
pub fn refresh_git_state(&self) -> Result<()>
Refresh the git state for invalidation checks.
Sourcepub fn get_if_valid(&self, key: &str) -> Result<Option<ContextEntry>>
pub fn get_if_valid(&self, key: &str) -> Result<Option<ContextEntry>>
Get a value, returning None if invalid (without deleting).
Sourcepub fn set(&self, entry: ContextEntry) -> Result<()>
pub fn set(&self, entry: ContextEntry) -> Result<()>
Set a value.
Sourcepub fn delete_prefix(&self, prefix: &str) -> Result<usize>
pub fn delete_prefix(&self, prefix: &str) -> Result<usize>
Delete all entries matching a prefix.
Sourcepub fn list(&self, query: &ContextQuery) -> Result<Vec<ContextEntry>>
pub fn list(&self, query: &ContextQuery) -> Result<Vec<ContextEntry>>
List entries matching a query.
Sourcepub fn get_file_context(&self, path: &str) -> Result<Option<FileContext>>
pub fn get_file_context(&self, path: &str) -> Result<Option<FileContext>>
Get file context.
Sourcepub fn set_file_context(&self, path: &str, ctx: &FileContext) -> Result<()>
pub fn set_file_context(&self, path: &str, ctx: &FileContext) -> Result<()>
Set file context with automatic mtime tracking.
Sourcepub fn get_file_attr(&self, path: &str, attr: &str) -> Result<Option<Value>>
pub fn get_file_attr(&self, path: &str, attr: &str) -> Result<Option<Value>>
Get a specific attribute of file context.
Sourcepub fn set_file_attr(&self, path: &str, attr: &str, value: Value) -> Result<()>
pub fn set_file_attr(&self, path: &str, attr: &str, value: Value) -> Result<()>
Set a specific attribute of file context.
Sourcepub fn get_symbol(&self, name: &str) -> Result<Option<SymbolInfo>>
pub fn get_symbol(&self, name: &str) -> Result<Option<SymbolInfo>>
Get symbol information.
Sourcepub fn set_symbol(
&self,
info: &SymbolInfo,
file_path: Option<&str>,
) -> Result<()>
pub fn set_symbol( &self, info: &SymbolInfo, file_path: Option<&str>, ) -> Result<()>
Set symbol information.
Sourcepub fn find_symbols(&self, prefix: &str) -> Result<Vec<SymbolInfo>>
pub fn find_symbols(&self, prefix: &str) -> Result<Vec<SymbolInfo>>
Find symbols by prefix.
Sourcepub fn get_project_context(&self) -> Result<Option<ProjectContext>>
pub fn get_project_context(&self) -> Result<Option<ProjectContext>>
Get project context.
Sourcepub fn set_project_context(&self, ctx: &ProjectContext) -> Result<()>
pub fn set_project_context(&self, ctx: &ProjectContext) -> Result<()>
Set project context.
Sourcepub fn set_project_attr(&self, attr: &str, value: Value) -> Result<()>
pub fn set_project_attr(&self, attr: &str, value: Value) -> Result<()>
Set a project attribute.
Sourcepub fn get_session(&self, session_id: &str) -> Result<Option<SessionContext>>
pub fn get_session(&self, session_id: &str) -> Result<Option<SessionContext>>
Get session context.
Sourcepub fn set_session(&self, ctx: &SessionContext) -> Result<()>
pub fn set_session(&self, ctx: &SessionContext) -> Result<()>
Set session context.
Sourcepub fn update_working_files(
&self,
session_id: &str,
files: Vec<String>,
) -> Result<()>
pub fn update_working_files( &self, session_id: &str, files: Vec<String>, ) -> Result<()>
Update session’s working files.
Sourcepub fn add_decision(
&self,
session_id: &str,
decision: &str,
rationale: Option<&str>,
context: Vec<String>,
) -> Result<()>
pub fn add_decision( &self, session_id: &str, decision: &str, rationale: Option<&str>, context: Vec<String>, ) -> Result<()>
Add a decision to session context.
Sourcepub fn get_batch(
&self,
keys: &[String],
) -> Result<HashMap<String, ContextEntry>>
pub fn get_batch( &self, keys: &[String], ) -> Result<HashMap<String, ContextEntry>>
Get multiple values by keys.
Sourcepub fn cleanup_expired(&self) -> Result<usize>
pub fn cleanup_expired(&self) -> Result<usize>
Delete all expired entries.
Sourcepub fn cleanup_invalid(&self) -> Result<usize>
pub fn cleanup_invalid(&self) -> Result<usize>
Delete all invalid entries based on git state.
Sourcepub fn clear_namespace(&self, namespace: Namespace) -> Result<usize>
pub fn clear_namespace(&self, namespace: Namespace) -> Result<usize>
Clear entries in a specific namespace.
Sourcepub fn get_file_mtime(&self, path: &str) -> Option<i64>
pub fn get_file_mtime(&self, path: &str) -> Option<i64>
Get the modification time of a file.
Sourcepub fn refresh_invalidation(&self) -> Result<()>
pub fn refresh_invalidation(&self) -> Result<()>
Refresh invalidation state from git.
Sourcepub fn list_simple(
&self,
namespace: Option<Namespace>,
prefix: Option<&str>,
) -> Result<Vec<ContextEntry>>
pub fn list_simple( &self, namespace: Option<Namespace>, prefix: Option<&str>, ) -> Result<Vec<ContextEntry>>
List entries with simplified parameters.