Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager { /* private fields */ }

Implementations§

Source§

impl SessionManager

Source

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

Source

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

Source

pub fn in_memory_with_entries(cwd: &Path, entries: Vec<SessionEntry>) -> Self

Restore an in-memory session from entries managed by an SDK caller.

Source

pub fn open(path: &Path) -> Result<Self>

Source

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

Source

pub fn create_sibling(&self) -> Result<Self>

Source

pub fn create_child(&self) -> Result<Self>

Create a child session in the same working directory and session store.

Source

pub fn fork_from( source: &Path, cwd: &Path, session_dir: Option<PathBuf>, ) -> Result<Self>

Fork: copy the source session’s entries into a new file for cwd.

Source

pub fn fork_active_branch( &self, through: Option<&str>, include_through: bool, ) -> Result<Self>

Copy one active branch into a new session file.

through selects the last entry to inspect. When include_through is false, the new session ends at that entry’s parent. This lets an interactive caller put a selected user message back in the editor.

Source

pub fn list(cwd: &Path, session_dir: &Path) -> Result<Vec<SessionListing>>

Source

pub fn list_all(session_dir: &Path) -> Result<Vec<SessionListing>>

Source

pub fn find_by_id(session_dir: &Path, partial: &str) -> Result<Option<PathBuf>>

Find a session file by partial UUID across all projects.

Source

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

Source

pub fn append_messages_with_session_info<I>( &mut self, messages: I, name: &str, ) -> Result<()>
where I: IntoIterator<Item = AgentMessage>,

Source

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

Source

pub fn append_thinking_level_change( &mut self, level: ThinkingLevel, ) -> Result<String>

Source

pub fn append_usage( &mut self, kind: &str, provider: &str, model: &str, usage: Usage, note: Option<String>, ) -> Result<String>

Source

pub fn append_compaction( &mut self, summary: String, tokens_before: u64, retained_tail: Vec<AgentMessage>, usage: Option<Usage>, details: Option<Value>, ) -> Result<String>

Source

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

Source

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

Source

pub fn append_custom( &mut self, custom_type: &str, data: Option<Value>, ) -> Result<String>

Source

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

Source

pub fn entries(&self) -> &[SessionEntry]

Source

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

Source

pub fn context_revision(&self) -> u64

Monotonic value for cache invalidation after context or tree changes.

Source

pub fn branch(&mut self, entry_id: &str) -> Result<()>

Move the leaf to an earlier entry (in-place branching).

Source

pub fn reset_leaf(&mut self)

Reset the leaf to before any entries.

Source

pub fn branch_with_summary( &mut self, entry_id: Option<&str>, from_id: &str, summary: String, usage: Option<Usage>, details: Option<Value>, ) -> Result<String>

Branch to entry_id and record a summary of the abandoned path.

Source

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

Source

pub fn branch_entries(&self, from: Option<&str>) -> Vec<&SessionEntry>

Walk leaf -> root. Returns entries in root-first order.

Source

pub fn branch_messages_after( &self, from: &str, ancestor: Option<&str>, ) -> Vec<AgentMessage>

LLM messages on one branch after an optional common ancestor.

Source

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

Latest session name on the active path.

Source

pub fn label_of(&self, target: &str) -> Option<String>

Source

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

Active-branch entries with compaction applied: on a compaction with a retained tail, the checkpoint replaces everything before it.

Source

pub fn build_session_context(&self) -> SessionContext

Messages + model + thinking level for the next LLM call.

Source

pub fn build_openai_compaction_context( &self, model: &Model, ) -> Option<OpenAICompactionContext>

Restore provider-native OpenAI history from the latest compaction on the active branch. Completed turns from another model are excluded.

Source

pub fn header(&self) -> &SessionHeader

Source

pub fn session_id(&self) -> &str

Source

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

Source

pub fn cwd(&self) -> &Path

Source

pub fn session_dir(&self) -> &Path

Source

pub fn is_persisted(&self) -> bool

Source

pub fn usage_totals(&self) -> Usage

Sum every provider operation recorded in this append-only session.

Source

pub fn to_jsonl(&self) -> Result<String>

Serialize the full append-only session file format.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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