pub struct SessionStore { /* private fields */ }Expand description
Thread-safe persistent session store backed by a JSON file.
Manages active Claude Code sessions, tracking which Slack threads correspond to which agent sessions. Persists to disk atomically to survive restarts.
§Thread Safety
All methods are async and internally use RwLock for concurrent access. Multiple readers can access simultaneously; writes are exclusive.
Implementations§
Source§impl SessionStore
impl SessionStore
Sourcepub fn new(path: PathBuf) -> Self
pub fn new(path: PathBuf) -> Self
Creates a new session store, loading existing sessions from disk if present.
§Arguments
path- Path to the JSON file for persisting sessions
§Returns
A new SessionStore instance. If the file doesn’t exist or is invalid,
starts with an empty session map (does not error).
Creates a new session store using blocking I/O for initial load.
Sourcepub async fn insert(&self, session: SessionInfo) -> Result<()>
pub async fn insert(&self, session: SessionInfo) -> Result<()>
Sourcepub async fn get_by_thread(&self, thread_ts: &str) -> Option<SessionInfo>
pub async fn get_by_thread(&self, thread_ts: &str) -> Option<SessionInfo>
Sourcepub async fn update<F>(&self, thread_ts: &str, f: F) -> Result<()>where
F: FnOnce(&mut SessionInfo),
pub async fn update<F>(&self, thread_ts: &str, f: F) -> Result<()>where
F: FnOnce(&mut SessionInfo),
Updates a session in-place and persists to disk atomically.
§Arguments
thread_ts- Thread timestamp of the session to updatef- Closure that modifies the session
§Errors
Returns SessionNotFound if the thread doesn’t exist, or a write error
if persistence fails.
§Example
store.update("1234.5678", |session| {
session.total_turns += 1;
session.last_active = Utc::now();
}).await?;pub async fn active_sessions(&self) -> Vec<SessionInfo>
Sourcepub async fn has_session_id(&self, session_id: &str) -> bool
pub async fn has_session_id(&self, session_id: &str) -> bool
Sourcepub async fn prune_stale_channels(
&self,
repo_channels: &HashMap<String, String>,
)
pub async fn prune_stale_channels( &self, repo_channels: &HashMap<String, String>, )
Remove sessions whose channel_id doesn’t match the current channel for their repo.
Sourcepub async fn prune_expired(&self, ttl_days: i64)
pub async fn prune_expired(&self, ttl_days: i64)
Remove sessions whose last_active is older than the TTL.
Trait Implementations§
Source§impl Clone for SessionStore
impl Clone for SessionStore
Source§fn clone(&self) -> SessionStore
fn clone(&self) -> SessionStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more