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(&self) -> &Session

Get the current session name. 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_children(&self, parent_id: &str) -> Vec<SessionEntry>

Get all direct children of an entry (pi-compatible).

Source

pub fn get_header(&self) -> Option<SessionHeader>

Get the session header (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_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.

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.

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