Skip to main content

SessionManager

Struct SessionManager 

Source
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

Source

pub fn with_session( session: Session, session_dir: PathBuf, cwd: PathBuf, persist: bool, ) -> Self

Create a SessionManager wrapping an existing Session.

Source

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.

Source

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.

Source

pub fn is_persisted(&self) -> bool

Source

pub fn cwd(&self) -> &Path

Source

pub fn session_dir(&self) -> &Path

Source

pub fn uses_default_session_dir(&self) -> bool

Returns true if using the default cwd-encoded session directory.

Source

pub fn session_id(&self) -> String

Source

pub fn session_file(&self) -> Option<PathBuf>

Source

pub fn leaf_id(&self) -> Option<String>

Source

pub fn session_name(&self) -> Option<String>

Get the current session name.

Source

pub fn session(&self) -> &Session

Get the underlying Session reference.

Source

pub fn session_mut(&mut self) -> &mut Session

Get the underlying Session mutable reference.

Source

pub fn into_session(self) -> Session

Consume and return the inner Session.

Source

pub fn get_leaf_entry(&self) -> Option<SessionEntry>

Get the current leaf entry (pi-compatible).

Source

pub fn get_tree(&self) -> Vec<SessionTreeNode>

Get the session as a tree structure with resolved children and labels (pi-compatible).

Source

pub fn get_entries(&self) -> Vec<SessionEntry>

Get all session entries (excludes header). Pi-compatible.

Source

pub fn append_message(&mut self, message: &AgentMessage) -> String

Source

pub fn append_thinking_level_change(&mut self, thinking_level: &str) -> String

Source

pub fn append_model_change(&mut self, provider: &str, model_id: &str) -> String

Source

pub fn append_session_info(&mut self, name: &str) -> String

Source

pub fn append_compaction( &mut self, summary: &str, first_kept_entry_id: &str, tokens_before: u64, details: Option<Value>, from_hook: Option<bool>, ) -> String

Source

pub fn append_branch_summary( &mut self, from_id: &str, summary: &str, details: Option<Value>, from_hook: Option<bool>, ) -> String

Source

pub fn append_label_change( &mut self, target_id: &str, label: Option<&str>, ) -> String

Source

pub fn append_custom_entry(&mut self, custom_type: &str, data: Value) -> String

Source

pub fn append_active_tools_change( &mut self, active_tool_names: &[String], ) -> String

Source

pub fn append_custom_message_entry( &mut self, custom_type: &str, content: Value, display: bool, details: Option<Value>, ) -> String

Source

pub fn find_entries_by_type(&self, type_name: &str) -> Vec<SessionEntry>

Find all entries of a given type (pi-compatible).

Source

pub fn entries(&self) -> Vec<SessionEntry>

Get all entries (excludes header).

Source

pub fn entry(&self, id: &str) -> Option<SessionEntry>

Look up an entry by id.

Source

pub fn children(&self, parent_id: &str) -> Vec<SessionEntry>

Get all direct children of an entry.

Source

pub fn branch(&self, from_id: Option<&str>) -> Vec<SessionEntry>

Walk from entry to root, returning all entries in path order.

Source

pub fn build_session_context(&self) -> SessionContext

Build the session context (messages for LLM with compaction handling). Pi-compatible: delegates to Session::build_context.

Source

pub fn label(&self, id: &str) -> Option<String>

Get the label for an entry, if any.

Source

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.

Source

pub fn reset_leaf(&mut self)

Reset leaf pointer to null (before any entries).

Source

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.

Source

pub fn create(cwd: &Path, session_dir: Option<&Path>) -> Self

Create a new session.

Source

pub fn create_with_options( cwd: &Path, session_dir: Option<&Path>, options: Option<&NewSessionOptions>, ) -> Self

Create a new session with options (pi-compatible).

Source

pub fn open( path: &Path, session_dir: Option<&Path>, cwd_override: Option<&Path>, ) -> Self

Open a specific session file.

Source

pub fn in_memory(cwd: &Path) -> Self

Create an in-memory session (no file persistence).

Source

pub fn continue_recent(cwd: &Path, session_dir: Option<&Path>) -> Self

Continue the most recent session, or create new if none.

Source

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.

Source

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.

Source

pub fn list_all(session_dir: Option<&Path>) -> Vec<SessionInfo>

List all sessions across all project directories (pi-compatible).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more