ContextStore

Struct ContextStore 

Source
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

Source

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

Open or create a context store at the given path.

Source

pub fn in_memory() -> Result<Self>

Create an in-memory context store (for testing).

Source

pub fn with_git_repo(self, repo_path: impl AsRef<Path>) -> Result<Self>

Initialize git-aware invalidation from a repository.

Source

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

Refresh the git state for invalidation checks.

Source

pub fn get(&self, key: &str) -> Result<Option<ContextEntry>>

Get a value by key.

Source

pub fn get_if_valid(&self, key: &str) -> Result<Option<ContextEntry>>

Get a value, returning None if invalid (without deleting).

Source

pub fn set(&self, entry: ContextEntry) -> Result<()>

Set a value.

Source

pub fn set_value(&self, key: &str, value: Value) -> Result<()>

Set a simple key-value pair.

Source

pub fn delete(&self, key: &str) -> Result<bool>

Delete a value by key.

Source

pub fn delete_prefix(&self, prefix: &str) -> Result<usize>

Delete all entries matching a prefix.

Source

pub fn exists(&self, key: &str) -> Result<bool>

Check if a key exists.

Source

pub fn list(&self, query: &ContextQuery) -> Result<Vec<ContextEntry>>

List entries matching a query.

Source

pub fn keys(&self, namespace: Namespace) -> Result<Vec<String>>

List all keys in a namespace.

Source

pub fn get_file_context(&self, path: &str) -> Result<Option<FileContext>>

Get file context.

Source

pub fn set_file_context(&self, path: &str, ctx: &FileContext) -> Result<()>

Set file context with automatic mtime tracking.

Source

pub fn get_file_attr(&self, path: &str, attr: &str) -> Result<Option<Value>>

Get a specific attribute of file context.

Source

pub fn set_file_attr(&self, path: &str, attr: &str, value: Value) -> Result<()>

Set a specific attribute of file context.

Source

pub fn get_symbol(&self, name: &str) -> Result<Option<SymbolInfo>>

Get symbol information.

Source

pub fn set_symbol( &self, info: &SymbolInfo, file_path: Option<&str>, ) -> Result<()>

Set symbol information.

Source

pub fn find_symbols(&self, prefix: &str) -> Result<Vec<SymbolInfo>>

Find symbols by prefix.

Source

pub fn get_project_context(&self) -> Result<Option<ProjectContext>>

Get project context.

Source

pub fn set_project_context(&self, ctx: &ProjectContext) -> Result<()>

Set project context.

Source

pub fn get_project_attr(&self, attr: &str) -> Result<Option<Value>>

Get a project attribute.

Source

pub fn set_project_attr(&self, attr: &str, value: Value) -> Result<()>

Set a project attribute.

Source

pub fn get_session(&self, session_id: &str) -> Result<Option<SessionContext>>

Get session context.

Source

pub fn set_session(&self, ctx: &SessionContext) -> Result<()>

Set session context.

Source

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

Update session’s working files.

Source

pub fn add_decision( &self, session_id: &str, decision: &str, rationale: Option<&str>, context: Vec<String>, ) -> Result<()>

Add a decision to session context.

Source

pub fn get_batch( &self, keys: &[String], ) -> Result<HashMap<String, ContextEntry>>

Get multiple values by keys.

Source

pub fn set_batch(&self, entries: Vec<ContextEntry>) -> Result<()>

Set multiple entries.

Source

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

Delete all expired entries.

Source

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

Delete all invalid entries based on git state.

Source

pub fn stats(&self) -> Result<ContextStats>

Get statistics about the context store.

Source

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

Clear all entries (for testing).

Source

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

Clear all entries and return count.

Source

pub fn clear_namespace(&self, namespace: Namespace) -> Result<usize>

Clear entries in a specific namespace.

Source

pub fn get_file_mtime(&self, path: &str) -> Option<i64>

Get the modification time of a file.

Source

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

Refresh invalidation state from git.

Source

pub fn list_simple( &self, namespace: Option<Namespace>, prefix: Option<&str>, ) -> Result<Vec<ContextEntry>>

List entries with simplified parameters.

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> 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<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