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
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.
pub fn session_id(&self) -> &str
pub fn session_file(&self) -> Option<&Path>
pub fn leaf_id(&self) -> Option<&str>
Sourcepub fn session_name(&self) -> Option<&str>
pub fn session_name(&self) -> Option<&str>
Get the current session name from the latest session_info entry.
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, then advance leaf. Returns the entry id.
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_session_info(&mut self, name: &str) -> String
pub fn append_session_info(&mut self, name: &str) -> String
Append a session info entry (display name).
Sourcepub fn append_compaction(
&mut self,
summary: &str,
first_kept_entry_id: &str,
tokens_before: u64,
) -> String
pub fn append_compaction( &mut self, summary: &str, first_kept_entry_id: &str, tokens_before: u64, ) -> String
Append a compaction summary.
Sourcepub fn append_branch_summary(&mut self, from_id: &str, summary: &str) -> String
pub fn append_branch_summary(&mut self, from_id: &str, summary: &str) -> String
Append a branch summary.
Sourcepub fn append_label_change(
&mut self,
target_id: &str,
label: Option<&str>,
) -> String
pub fn append_label_change( &mut self, target_id: &str, label: Option<&str>, ) -> String
Append a label change (bookmark/unbookmark).
Sourcepub fn append_custom_entry(&mut self, custom_type: &str, data: Value) -> String
pub fn append_custom_entry(&mut self, custom_type: &str, data: Value) -> String
Append a custom entry (extension data).
Sourcepub fn entries(&self) -> &[SessionEntry]
pub fn entries(&self) -> &[SessionEntry]
Get all entries (excludes header).
Sourcepub fn entry(&self, id: &str) -> Option<&SessionEntry>
pub fn entry(&self, id: &str) -> Option<&SessionEntry>
Look up an entry by id.
Sourcepub fn children(&self, parent_id: &str) -> Vec<&SessionEntry>
pub fn children(&self, parent_id: &str) -> Vec<&SessionEntry>
Get all direct children of an entry.
Sourcepub fn branch(&self, from_id: Option<&str>) -> Vec<&SessionEntry>
pub fn branch(&self, from_id: Option<&str>) -> Vec<&SessionEntry>
Walk from entry to root, returning all entries in path order.
Sourcepub fn build_session_context(&self) -> SessionContext
pub fn build_session_context(&self) -> SessionContext
Build the session context (messages for LLM).
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).
Sourcepub fn reset_leaf(&mut self)
pub fn reset_leaf(&mut self)
Reset leaf pointer to null (before any entries).
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.