pub struct SessionManager { /* private fields */ }Expand description
Manages conversation sessions as append-only trees stored in JSONL files.
SessionManager handles session persistence, branching, and tree traversal. Each session is stored as a JSONL file where each line is a session entry. Entries form a tree structure allowing for session branching and history.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn create(cwd: &str, session_dir: Option<&str>) -> SessionManager
pub fn create(cwd: &str, session_dir: Option<&str>) -> SessionManager
Create a new session and persist it to disk.
Sourcepub fn open(
path: &str,
session_dir: Option<&str>,
cwd_override: Option<&str>,
) -> SessionManager
pub fn open( path: &str, session_dir: Option<&str>, cwd_override: Option<&str>, ) -> SessionManager
Open an existing session from a file path.
Sourcepub fn continue_recent(cwd: &str, session_dir: Option<&str>) -> SessionManager
pub fn continue_recent(cwd: &str, session_dir: Option<&str>) -> SessionManager
Continue the most recent session, or create a new one if none exists.
Sourcepub fn in_memory(cwd: &str) -> SessionManager
pub fn in_memory(cwd: &str) -> SessionManager
Create an in-memory session without file persistence.
Sourcepub fn set_session_file(&mut self, session_file: &str)
pub fn set_session_file(&mut self, session_file: &str)
Switch to a different session file
Sourcepub fn new_session(&mut self, options: Option<NewSessionOptions>)
pub fn new_session(&mut self, options: Option<NewSessionOptions>)
Create a new session with optional ID and parent
Sourcepub fn is_persisted(&self) -> bool
pub fn is_persisted(&self) -> bool
Check if session is persisted to disk
Sourcepub fn persisted_count(&self) -> usize
pub fn persisted_count(&self) -> usize
Get the number of agent messages that have already been persisted.
Sourcepub fn set_persisted_count(&self, count: usize)
pub fn set_persisted_count(&self, count: usize)
Set the number of agent messages that have been persisted.
Sourcepub fn get_session_dir(&self) -> String
pub fn get_session_dir(&self) -> String
Get session directory
Sourcepub fn get_session_id(&self) -> String
pub fn get_session_id(&self) -> String
Get session ID
Sourcepub fn get_session_file(&self) -> Option<String>
pub fn get_session_file(&self) -> Option<String>
Get session file path
Sourcepub fn append_message(&mut self, message: AgentMessage) -> String
pub fn append_message(&mut self, message: AgentMessage) -> String
Append a message as child of current leaf
Sourcepub fn append_thinking_level_change(&mut self, thinking_level: &str) -> String
pub fn append_thinking_level_change(&mut self, thinking_level: &str) -> String
Append a thinking level change
Sourcepub fn append_model_change(&mut self, provider: &str, model_id: &str) -> String
pub fn append_model_change(&mut self, provider: &str, model_id: &str) -> String
Append a model change
Sourcepub fn append_compaction(
&mut self,
summary: &str,
_first_kept_entry_id: &str,
tokens_before: i64,
_details: Option<Value>,
_from_hook: Option<bool>,
) -> String
pub fn append_compaction( &mut self, summary: &str, _first_kept_entry_id: &str, tokens_before: i64, _details: Option<Value>, _from_hook: Option<bool>, ) -> String
Append a compaction summary
Sourcepub fn append_custom_entry(
&mut self,
custom_type: &str,
data: Option<Value>,
) -> String
pub fn append_custom_entry( &mut self, custom_type: &str, data: Option<Value>, ) -> String
Append a custom entry (for extensions)
Sourcepub fn append_session_info(&mut self, name: &str) -> String
pub fn append_session_info(&mut self, name: &str) -> String
Append a session info entry (e.g., display name)
Sourcepub fn get_session_name(&self) -> Option<String>
pub fn get_session_name(&self) -> Option<String>
Get the current session name from the latest session_info entry
Sourcepub fn append_custom_message_entry(
&mut self,
custom_type: &str,
content: ContentValue,
display: bool,
details: Option<Value>,
) -> String
pub fn append_custom_message_entry( &mut self, custom_type: &str, content: ContentValue, display: bool, details: Option<Value>, ) -> String
Append a custom message entry (for extensions) that participates in LLM context
Sourcepub fn get_leaf_id(&self) -> Option<String>
pub fn get_leaf_id(&self) -> Option<String>
Get the current leaf ID
Sourcepub fn get_leaf_entry(&self) -> Option<SessionEntry>
pub fn get_leaf_entry(&self) -> Option<SessionEntry>
Get the current leaf entry
Sourcepub fn get_entry(&self, id: &str) -> Option<SessionEntry>
pub fn get_entry(&self, id: &str) -> Option<SessionEntry>
Get an entry by ID
Sourcepub fn get_children(&self, parent_id: &str) -> Vec<SessionEntry>
pub fn get_children(&self, parent_id: &str) -> Vec<SessionEntry>
Get all direct children of an entry
Sourcepub fn get_parent(&self, id: &str) -> Option<SessionEntry>
pub fn get_parent(&self, id: &str) -> Option<SessionEntry>
Get the parent of an entry
Sourcepub fn append_label_change(
&mut self,
target_id: &str,
label: Option<&str>,
) -> Result<String, String>
pub fn append_label_change( &mut self, target_id: &str, label: Option<&str>, ) -> Result<String, String>
Set or clear a label on an entry
Sourcepub fn get_branch(&self, from_id: Option<&str>) -> Vec<SessionEntry>
pub fn get_branch(&self, from_id: Option<&str>) -> Vec<SessionEntry>
Walk from entry to root, returning all entries in path order
Sourcepub fn get_path_to_root(&self, from_id: &str) -> Vec<SessionEntry>
pub fn get_path_to_root(&self, from_id: &str) -> Vec<SessionEntry>
Get path to root for a given entry
Sourcepub fn get_ancestry(&self, from_id: &str) -> Vec<SessionEntry>
pub fn get_ancestry(&self, from_id: &str) -> Vec<SessionEntry>
Get ancestry (same as path to root)
Sourcepub fn build_session_context(&self) -> SessionContext
pub fn build_session_context(&self) -> SessionContext
Build the session context (what gets sent to the LLM)
Sourcepub fn get_header(&self) -> Option<SessionHeader>
pub fn get_header(&self) -> Option<SessionHeader>
Get session header
Sourcepub fn get_entries(&self) -> Vec<SessionEntry>
pub fn get_entries(&self) -> Vec<SessionEntry>
Get all session entries (excludes header)
Sourcepub fn get_tree(&self, _id: Uuid) -> Result<Vec<SessionTreeNode>, Error>
pub fn get_tree(&self, _id: Uuid) -> Result<Vec<SessionTreeNode>, Error>
Get the session as a tree structure If id is provided, returns tree for that session (backward compat)
Sourcepub fn branch(&mut self, branch_from_id: &str) -> Result<(), String>
pub fn branch(&mut self, branch_from_id: &str) -> Result<(), String>
Start a new branch from an earlier entry
Sourcepub fn reset_leaf(&mut self)
pub fn reset_leaf(&mut self)
Reset the leaf pointer to null (before any entries)
Sourcepub fn branch_with_summary(
&mut self,
branch_from_id: Option<&str>,
summary: &str,
_details: Option<Value>,
_from_hook: Option<bool>,
) -> String
pub fn branch_with_summary( &mut self, branch_from_id: Option<&str>, summary: &str, _details: Option<Value>, _from_hook: Option<bool>, ) -> String
Start a new branch with a summary of the abandoned path
Sourcepub fn add_label(
&mut self,
target_id: &str,
label: &str,
) -> Result<String, String>
pub fn add_label( &mut self, target_id: &str, label: &str, ) -> Result<String, String>
Add a label to the session
Sourcepub fn remove_label(&mut self, target_id: &str) -> Result<String, String>
pub fn remove_label(&mut self, target_id: &str) -> Result<String, String>
Remove a label from an entry
Sourcepub fn get_latest_compaction_entry(&self) -> Option<SessionEntry>
pub fn get_latest_compaction_entry(&self) -> Option<SessionEntry>
Get the latest compaction entry
Sourcepub fn get_compaction_entries(&self) -> Vec<SessionEntry>
pub fn get_compaction_entries(&self) -> Vec<SessionEntry>
Get all compaction entries
Sourcepub fn get_session_stats(&self) -> SessionStats
pub fn get_session_stats(&self) -> SessionStats
Get session statistics
Sourcepub async fn list(
cwd: &str,
session_dir: Option<&str>,
) -> Result<Vec<SessionInfo>, Error>
pub async fn list( cwd: &str, session_dir: Option<&str>, ) -> Result<Vec<SessionInfo>, Error>
List all sessions for a directory
Sourcepub async fn list_all() -> Result<Vec<SessionInfo>, Error>
pub async fn list_all() -> Result<Vec<SessionInfo>, Error>
List all sessions across all project directories
Sourcepub fn fork_from(
source_path: &str,
target_cwd: &str,
session_dir: Option<&str>,
) -> Result<SessionManager, String>
pub fn fork_from( source_path: &str, target_cwd: &str, session_dir: Option<&str>, ) -> Result<SessionManager, String>
Fork a session from another project directory into the current project
Sourcepub fn rename_session(&mut self, name: &str) -> String
pub fn rename_session(&mut self, name: &str) -> String
Rename a session (set its display name)
Sourcepub async fn new() -> Result<SessionManager, Error>
pub async fn new() -> Result<SessionManager, Error>
Create a new SessionManager (async for backward compatibility)
Sourcepub async fn new_async() -> Result<SessionManager, Error>
pub async fn new_async() -> Result<SessionManager, Error>
Create a new SessionManager (async for backward compatibility)
Sourcepub fn session_path(&self, id: &Uuid) -> PathBuf
pub fn session_path(&self, id: &Uuid) -> PathBuf
Get the session file path for a given session ID
Sourcepub async fn list_sessions(&self) -> Result<Vec<SessionMeta>, Error>
pub async fn list_sessions(&self) -> Result<Vec<SessionMeta>, Error>
List all sessions (backward compat)
Sourcepub async fn save(
&self,
_id: Uuid,
_entries: &[SessionEntry],
) -> Result<(), Error>
pub async fn save( &self, _id: Uuid, _entries: &[SessionEntry], ) -> Result<(), Error>
Save entries (backward compat)
Sourcepub async fn load(&self, _id: Uuid) -> Result<Vec<SessionEntry>, Error>
pub async fn load(&self, _id: Uuid) -> Result<Vec<SessionEntry>, Error>
Load entries (backward compat)
Sourcepub async fn branch_from(
&self,
parent_id: Uuid,
entry_id: Uuid,
) -> Result<(Uuid, Vec<SessionEntry>), Error>
pub async fn branch_from( &self, parent_id: Uuid, entry_id: Uuid, ) -> Result<(Uuid, Vec<SessionEntry>), Error>
Create a branch from an existing session at a given entry
Sourcepub async fn get_branch_info(
&self,
_id: Uuid,
) -> Result<Option<BranchInfo>, Error>
pub async fn get_branch_info( &self, _id: Uuid, ) -> Result<Option<BranchInfo>, Error>
Get branch info for a session
Sourcepub async fn get_tree_async(
&self,
_id: Uuid,
) -> Result<Vec<SessionTreeNode>, Error>
pub async fn get_tree_async( &self, _id: Uuid, ) -> Result<Vec<SessionTreeNode>, Error>
Get tree for a specific session (backward compat)
Sourcepub async fn save_meta(&self, _meta: &SessionMeta) -> Result<(), Error>
pub async fn save_meta(&self, _meta: &SessionMeta) -> Result<(), Error>
Save metadata (backward compat)
Sourcepub async fn load_meta(&self, _id: Uuid) -> Result<Option<SessionMeta>, Error>
pub async fn load_meta(&self, _id: Uuid) -> Result<Option<SessionMeta>, Error>
Load metadata (backward compat)
Sourcepub async fn create_session(&mut self) -> Result<SessionMeta, Error>
pub async fn create_session(&mut self) -> Result<SessionMeta, Error>
Create a new session (backward compat)
Trait Implementations§
Source§impl Clone for SessionManager
impl Clone for SessionManager
Source§fn clone(&self) -> SessionManager
fn clone(&self) -> SessionManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
impl UnwindSafe for SessionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more