pub struct SessionManager { /* private fields */ }Expand description
Manages conversation sessions as append-only trees in JSONL files.
Each entry has an id and parentId forming a tree structure. Appending creates a child of the current leaf. Branching moves the leaf to an earlier entry, allowing new branches without modifying history.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn with_session(
session: Session,
session_dir: PathBuf,
cwd: PathBuf,
persist: bool,
) -> Self
pub fn with_session( session: Session, session_dir: PathBuf, cwd: PathBuf, persist: bool, ) -> Self
Create a SessionManager wrapping an existing Session.
Sourcepub fn new_session(&mut self, options: Option<&NewSessionOptions>)
pub fn new_session(&mut self, options: Option<&NewSessionOptions>)
Create a new session (overwrites current entries). Pi-compatible: defers writing to disk until first assistant message.
Sourcepub fn ensure_flushed(&mut self)
pub fn ensure_flushed(&mut self)
Ensure the session file has been written (lazy write). Migrates from in-memory to file-backed storage, writing header + all entries. Called before first assistant message.
pub fn is_persisted(&self) -> bool
pub fn cwd(&self) -> &Path
pub fn session_dir(&self) -> &Path
Sourcepub fn uses_default_session_dir(&self) -> bool
pub fn uses_default_session_dir(&self) -> bool
Returns true if using the default cwd-encoded session directory.
Sourcepub fn session(&self) -> &Session
pub fn session(&self) -> &Session
Get the current session name. Get the underlying Session reference.
Sourcepub fn session_mut(&mut self) -> &mut Session
pub fn session_mut(&mut self) -> &mut Session
Get the underlying Session mutable reference.
Sourcepub fn into_session(self) -> Session
pub fn into_session(self) -> Session
Consume and return the inner Session.
Sourcepub fn get_leaf_entry(&self) -> Option<SessionEntry>
pub fn get_leaf_entry(&self) -> Option<SessionEntry>
Get the current leaf entry (pi-compatible).
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 (pi-compatible).
Sourcepub fn get_header(&self) -> Option<SessionHeader>
pub fn get_header(&self) -> Option<SessionHeader>
Get the session header (pi-compatible).
Sourcepub fn get_tree(&self) -> Vec<SessionTreeNode>
pub fn get_tree(&self) -> Vec<SessionTreeNode>
Get the session as a tree structure with resolved children and labels (pi-compatible).
Sourcepub fn get_entries(&self) -> Vec<SessionEntry>
pub fn get_entries(&self) -> Vec<SessionEntry>
Get all session entries (excludes header). Pi-compatible.
pub fn append_message(&mut self, message: &AgentMessage) -> String
Sourcepub fn append_message_with_cost(
&mut self,
message: &AgentMessage,
cost: f64,
) -> String
pub fn append_message_with_cost( &mut self, message: &AgentMessage, cost: f64, ) -> String
Append a message with a pre-computed cost (pi-style). Pi-compatible lazy-write: defer file creation until first assistant message.
Sourcepub fn set_branch(&mut self, branch_from_id: &str) -> Result<(), String>
pub fn set_branch(&mut self, branch_from_id: &str) -> Result<(), String>
Move leaf pointer to an earlier entry (starts a new branch). Pi-compatible: delegates to Session::set_leaf_id.
Sourcepub fn reset_leaf(&mut self)
pub fn reset_leaf(&mut self)
Reset 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>,
) -> Result<String, String>
pub fn branch_with_summary( &mut self, branch_from_id: Option<&str>, summary: &str, details: Option<Value>, from_hook: Option<bool>, ) -> Result<String, String>
Move leaf pointer with a branch summary entry. Pi-compatible: delegates to Session::move_to.
Sourcepub fn create_with_options(
cwd: &Path,
session_dir: Option<&Path>,
options: Option<&NewSessionOptions>,
) -> Self
pub fn create_with_options( cwd: &Path, session_dir: Option<&Path>, options: Option<&NewSessionOptions>, ) -> Self
Create a new session with options (pi-compatible).
Sourcepub fn open(
path: &Path,
session_dir: Option<&Path>,
cwd_override: Option<&Path>,
) -> Self
pub fn open( path: &Path, session_dir: Option<&Path>, cwd_override: Option<&Path>, ) -> Self
Open a specific session file.
Sourcepub fn continue_recent(cwd: &Path, session_dir: Option<&Path>) -> Self
pub fn continue_recent(cwd: &Path, session_dir: Option<&Path>) -> Self
Continue the most recent session, or create new if none.
Sourcepub fn fork_from(
source_path: &Path,
target_cwd: &Path,
session_dir: Option<&Path>,
options: Option<&NewSessionOptions>,
) -> Result<Self>
pub fn fork_from( source_path: &Path, target_cwd: &Path, session_dir: Option<&Path>, options: Option<&NewSessionOptions>, ) -> Result<Self>
Fork a session from another project directory into the current one. Pi-compatible: creates a new session with the full history from the source session.
Sourcepub fn create_branched_session(&mut self, leaf_id: &str) -> Option<PathBuf>
pub fn create_branched_session(&mut self, leaf_id: &str) -> Option<PathBuf>
Create a branched session from a specific leaf path. Extracts the linear path from root to leaf into a new session file. Pi-compatible: creates a new session file, preserving labels.