pub struct SessionManager { /* private fields */ }Expand description
Manages sessions on disk.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new() -> Result<Self, SessionError>
pub fn new() -> Result<Self, SessionError>
Create a new SessionManager with the default sessions directory (~/.talos/sessions/).
Sourcepub fn default_sessions_dir() -> Result<PathBuf, SessionError>
pub fn default_sessions_dir() -> Result<PathBuf, SessionError>
Return the default sessions directory without opening indexes or reconciling state.
§Errors
Returns an error if no user home directory environment variable is available.
Sourcepub fn with_dir(sessions_dir: PathBuf) -> Self
pub fn with_dir(sessions_dir: PathBuf) -> Self
Create a new SessionManager with a custom sessions directory.
Sourcepub fn create_or_open_session(
&self,
external_id: &str,
) -> Result<DurableSession, SessionError>
pub fn create_or_open_session( &self, external_id: &str, ) -> Result<DurableSession, SessionError>
Creates or opens a UUID-backed durable session for a host logical ID.
The external ID is stored only in a colocated binding index; it is never used as a path component or filename.
Sourcepub fn get_session_by_external_id(
&self,
external_id: &str,
) -> Result<Option<DurableSession>, SessionError>
pub fn get_session_by_external_id( &self, external_id: &str, ) -> Result<Option<DurableSession>, SessionError>
Looks up a durable session by its host logical ID without creating one.
Sourcepub fn session_exists(&self, id: &Uuid) -> bool
pub fn session_exists(&self, id: &Uuid) -> bool
Returns whether a UUID-backed session exists without accepting a path.
Sourcepub fn read_session(&self, id: &Uuid) -> Result<Vec<SessionEntry>, SessionError>
pub fn read_session(&self, id: &Uuid) -> Result<Vec<SessionEntry>, SessionError>
Reads all normalized entries for a UUID-backed session.
Sourcepub fn session_size(&self, id: &Uuid) -> Result<u64, SessionError>
pub fn session_size(&self, id: &Uuid) -> Result<u64, SessionError>
Returns the byte size of a UUID-backed session file.
Sourcepub fn sessions_dir(&self) -> &Path
pub fn sessions_dir(&self) -> &Path
Return the root directory used for session JSONL files and the colocated index.
Sourcepub fn todo_repository(&self) -> Result<TodoRepository, TodoError>
pub fn todo_repository(&self) -> Result<TodoRepository, TodoError>
Open the colocated session todo repository and initialize its schema.
The repository is session-scoped by data, not by database file: all todo rows carry a
session_id and share one SQLite file under the sessions directory.
§Errors
Returns an error if the SQLite database cannot be opened or initialized.
Sourcepub fn create_session(
&self,
project: &str,
workspace_root: &str,
) -> Result<Session, SessionError>
pub fn create_session( &self, project: &str, workspace_root: &str, ) -> Result<Session, SessionError>
Create a new session for the given project and workspace.
The session file is created at ~/.talos/sessions/<workspace_dir>/<uuid>.tlog,
where workspace_dir is a hash of the workspace root path.
Sourcepub fn defer_create_session(
&self,
project: &str,
workspace_root: &str,
) -> Result<Session, SessionError>
pub fn defer_create_session( &self, project: &str, workspace_root: &str, ) -> Result<Session, SessionError>
Prepare a new session without creating the file on disk.
Returns a Session with persisted = false. The JSONL file is
not created until Session::ensure_persisted is called (triggered
automatically on the first message append).
Sourcepub fn get_session(&self, id: &Uuid) -> Result<Session, SessionError>
pub fn get_session(&self, id: &Uuid) -> Result<Session, SessionError>
Load an existing session by ID.
Scans all workspace directories for a file matching <id>.<ext>
where <ext> is any known session file extension (.tlog or .jsonl).
If both exist for the same UUID, returns a duplicate-format error.
Sourcepub fn list_sessions(&self) -> Result<Vec<SessionInfo>, SessionError>
pub fn list_sessions(&self) -> Result<Vec<SessionInfo>, SessionError>
List all sessions across all workspace directories.
Sourcepub fn list_workspace_sessions(
&self,
workspace_root: &str,
) -> Result<Vec<SessionInfo>, SessionError>
pub fn list_workspace_sessions( &self, workspace_root: &str, ) -> Result<Vec<SessionInfo>, SessionError>
List sessions for one workspace directory.
Sourcepub fn latest_workspace_session(
&self,
workspace_root: &str,
) -> Result<Option<SessionInfo>, SessionError>
pub fn latest_workspace_session( &self, workspace_root: &str, ) -> Result<Option<SessionInfo>, SessionError>
Return the most recently modified session for one workspace directory.
Sourcepub fn resume_session(&self, session_id: &str) -> Result<Session, SessionError>
pub fn resume_session(&self, session_id: &str) -> Result<Session, SessionError>
Resume a session by ID, loading all entries from the session file.
This is equivalent to SessionManager::get_session but with a clearer
name for the “resume” use case.
Sourcepub fn search(
&self,
query: &str,
limit: usize,
) -> Result<Vec<SearchResult>, IndexError>
pub fn search( &self, query: &str, limit: usize, ) -> Result<Vec<SearchResult>, IndexError>
Perform a full-text search across all indexed session messages.
Returns results ranked by relevance. The index is created lazily if it does not exist.
Sourcepub fn list_recent(&self, limit: usize) -> Result<Vec<SessionInfo>, IndexError>
pub fn list_recent(&self, limit: usize) -> Result<Vec<SessionInfo>, IndexError>
List the most recently updated sessions from the index.
Returns sessions ordered by last update time, descending.
Sourcepub fn update_index(&self, session: &Session) -> Result<(), IndexError>
pub fn update_index(&self, session: &Session) -> Result<(), IndexError>
Update the search index for a session.
If the index has not been initialized, this is a no-op.
Sourcepub fn checkpoint_index(&self) -> Result<(), IndexError>
pub fn checkpoint_index(&self) -> Result<(), IndexError>
Checkpoint the session index WAL and truncate it where possible.
Sourcepub fn vacuum_index(&self) -> Result<(), IndexError>
pub fn vacuum_index(&self) -> Result<(), IndexError>
Vacuum the session index database.
Sourcepub fn get_forks(&self, session_id: &str) -> Result<Vec<ForkInfo>, IndexError>
pub fn get_forks(&self, session_id: &str) -> Result<Vec<ForkInfo>, IndexError>
Return forks originating from the given session ID.
Sourcepub fn record_fork(
&self,
source_session_id: &Uuid,
forked_session_id: &Uuid,
fork_entry_id: &str,
) -> Result<(), IndexError>
pub fn record_fork( &self, source_session_id: &Uuid, forked_session_id: &Uuid, fork_entry_id: &str, ) -> Result<(), IndexError>
Record one source/child fork relationship through the manager-owned index.
pub fn reconcile_index(&self) -> Result<usize, IndexError>
Sourcepub fn delete_session(&self, id: &Uuid) -> Result<(), SessionError>
pub fn delete_session(&self, id: &Uuid) -> Result<(), SessionError>
Delete one discoverable Session through the retryable ownership boundary.
Sourcepub fn rollback_session_artifacts(
&self,
session: &Session,
) -> Result<SessionArtifactCleanupReport, SessionError>
pub fn rollback_session_artifacts( &self, session: &Session, ) -> Result<SessionArtifactCleanupReport, SessionError>
Roll back all artifacts owned by a prepared or partially created Session.
Unlike delete_session, this does not require the transcript to exist, so
post-identity initialization failures remain recoverable.
Sourcepub fn reconcile_orphan_sidecars(
&self,
policy: &OrphanSidecarReconciliationPolicy,
) -> Result<OrphanSidecarReconciliationReport, SessionError>
pub fn reconcile_orphan_sidecars( &self, policy: &OrphanSidecarReconciliationPolicy, ) -> Result<OrphanSidecarReconciliationReport, SessionError>
Discover and remove safe transcript-less pending SQLite artifacts.
Sourcepub fn cleanup_candidates(
&self,
policy: &SessionCleanupPolicy,
) -> Result<Vec<SessionCleanupCandidate>, SessionError>
pub fn cleanup_candidates( &self, policy: &SessionCleanupPolicy, ) -> Result<Vec<SessionCleanupCandidate>, SessionError>
Return sessions that would be removed by policy without deleting files.
Sourcepub fn apply_cleanup(
&self,
policy: &SessionCleanupPolicy,
) -> Result<SessionCleanupReport, SessionError>
pub fn apply_cleanup( &self, policy: &SessionCleanupPolicy, ) -> Result<SessionCleanupReport, SessionError>
Apply a cleanup policy by deleting selected sessions and index rows.
This is an explicit maintenance operation. It never removes IDs listed in
protected_session_ids, even if callers accidentally include an active
session in an otherwise matching policy.