Skip to main content

Session

Struct Session 

Source
pub struct Session {
    pub id: Uuid,
    pub project: String,
    pub workspace_root: String,
    pub created_at: DateTime<Utc>,
    pub file_path: PathBuf,
    pub current_branch: String,
    pub branches: HashMap<String, SessionBranch>,
    pub persisted: bool,
    /* private fields */
}
Expand description

A single session, backed by a JSONL file, with support for tree-branching.

Sessions maintain a collection of branches, each identified by a unique ID. The current_branch field tracks which branch is active for appending new entries.

Fields§

§id: Uuid§project: String§workspace_root: String§created_at: DateTime<Utc>§file_path: PathBuf§current_branch: String§branches: HashMap<String, SessionBranch>§persisted: bool

Implementations§

Source§

impl Session

Source

pub fn append(&self, message: &Message) -> Result<(), SessionError>

Source

pub fn append_with_metadata( &self, message: &Message, metadata: SessionMetadata, ) -> Result<(), SessionError>

Source

pub fn append_terminal_diagnostic( &self, diagnostic: &ProviderTerminalDiagnostic, ) -> Result<(), SessionError>

Source

pub fn read_terminal_diagnostics( &self, ) -> Result<Vec<ProviderTerminalDiagnostic>, SessionError>

Source

pub fn append_turn_transcript_outcome( &self, outcome: &TurnTranscriptOutcomeRecord, ) -> Result<(), SessionError>

Appends the authoritative terminal transcript outcome for one Turn.

Callers must write this marker only after every transcript message for the outcome has been durably appended. Recovery never infers Success from ordinary or partial message entries alone.

Source

pub fn read_turn_transcript_outcomes( &self, ) -> Result<Vec<TurnTranscriptOutcomeRecord>, SessionError>

Source

pub fn append_event(&self, event: &AgentEvent) -> Result<(), SessionError>

Source

pub fn read_entries(&self) -> Result<Vec<SessionEntry>, SessionError>

Source

pub fn read_messages(&self) -> Result<Vec<Message>, SessionError>

Source

pub fn read_events(&self) -> Result<Vec<AgentEvent>, SessionError>

Source§

impl Session

Source

pub fn compact_archived( &self, max_entries: usize, ) -> Result<CompactionResult, SessionError>

Archives the current log while holding the session write lock.

Source

pub fn new( id: Uuid, project: String, workspace_root: String, file_path: PathBuf, ) -> Self

Create a new session with a single empty root branch. The file path MUST already exist on disk.

Source

pub fn new_deferred( id: Uuid, project: String, workspace_root: String, file_path: PathBuf, ) -> Self

Create a deferred session — metadata only, no file on disk. The file is created lazily on the first ensure_persisted() call.

Source

pub fn with_store( id: Uuid, project: String, workspace_root: String, file_path: PathBuf, store: Arc<dyn SessionStore>, ) -> Self

Create a session with an explicit store, chosen by the caller. Used by SessionManager::get_session when loading an existing file whose format is determined by extension.

Source

pub fn ensure_persisted(&mut self) -> Result<(), SessionError>

Create the parent directory and empty JSONL file if not yet persisted. No-op if already persisted (e.g., resumed or forked sessions).

Source

pub fn fork(&mut self, from_entry_id: &str) -> Result<String, SessionError>

Fork the current session from a specific entry, creating a new branch.

Returns the ID of the newly created branch.

§Arguments
  • from_entry_id - The ID of the entry to fork from. This entry must exist in one of the existing branches.
§Errors

Returns SessionError::EntryNotFound if the entry ID doesn’t exist.

Source

pub fn with_fork_identity( &mut self, new_id: Uuid, new_file_path: PathBuf, branch_id: String, )

Atomically re-stamp a forked session with a new identity.

After fork creates a new branch in memory, callers typically write the branched entries to a fresh JSONL file under a new Uuid. This method updates the in-memory Session so that subsequent append and append_event calls write to the new file and so the SQLite index sees a coherent (id, file_path, branch_id) triple.

Without this, the original session’s id/file_path would survive a fork in memory while the on-disk file moved to a new UUID — the SQLite index would then either point at the wrong file or fail to locate the fork.

§Arguments
  • new_id - The new session Uuid (must match the JSONL filename).
  • new_file_path - The path to the new JSONL file the fork was written to.
  • branch_id - The branch ID to mark as currently active on the fork.
Source

pub fn get_branch(&self, branch_id: &str) -> Option<&SessionBranch>

Get a reference to a branch by its ID.

Returns None if the branch ID doesn’t exist.

Source

pub fn snapshot_bytes(&self) -> Result<Vec<u8>, SessionError>

Read the session JSONL file as raw bytes, holding the per-session write lock so concurrent append calls cannot produce a torn read.

Used by fork-style operations that need to copy the source file byte-for-byte without racing with in-flight event persistence.

Source

pub fn list_branches(&self) -> Vec<String>

List all branch IDs in this session.

Source

pub fn file_extension(&self) -> &'static str

Returns the file extension used by this session’s store.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.