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 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) -> &str

Source

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

Source

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

Source

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

Get the current session name from the latest session_info entry.

Source

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

Append a message as child of current leaf, then advance leaf. Returns the entry id.

Source

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

Append a thinking level change.

Source

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

Append a model change.

Source

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

Append a session info entry (display name).

Source

pub fn append_compaction( &mut self, summary: &str, first_kept_entry_id: &str, tokens_before: u64, ) -> String

Append a compaction summary.

Source

pub fn append_branch_summary(&mut self, from_id: &str, summary: &str) -> String

Append a branch summary.

Source

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

Append a label change (bookmark/unbookmark).

Source

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

Append a custom entry (extension data).

Source

pub fn entries(&self) -> &[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).

Source

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

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).

Source

pub fn reset_leaf(&mut self)

Reset leaf pointer to null (before any entries).

Source

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

Create a new session.

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.

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