pub struct SessionCoordinator { /* private fields */ }Implementations§
Source§impl SessionCoordinator
impl SessionCoordinator
pub fn new( dir: &Path, cwd: &str, compaction_config: CompactionConfig, model: impl Into<String>, ) -> Result<Self>
Sourcepub fn open_existing(
path: PathBuf,
session_id: String,
existing_entries: &[SessionEntry],
prior_agent_message_count: usize,
compaction_config: CompactionConfig,
model: impl Into<String>,
) -> Result<Self>
pub fn open_existing( path: PathBuf, session_id: String, existing_entries: &[SessionEntry], prior_agent_message_count: usize, compaction_config: CompactionConfig, model: impl Into<String>, ) -> Result<Self>
Open an existing session file for appending (resume).
existing_entries are the prior session entries already loaded by the
caller via SessionReader::read_all. Only entries on the active branch
(determined by the last Leaf pointer) are replayed into the internal
compaction buffer — matching the ordering used by reconstruct_context
for the Agent’s message buffer. Legacy sessions without Leaf entries
fall back to file-order replay.
Compaction entries are honored by replaying their semantics: the
kept tail (entries from first_kept_entry_id onward, persisted before
the marker) is preserved, the summary occupies a synthetic slot at
index 0 of the post-compaction agent buffer, and indices are rebuilt
to match the runtime layout [summary, ...kept_tail, ...post_marker].
If first_kept_entry_id cannot be located among the already-replayed
entries (corrupt or forward-incompatible session), the buffer is
reset entirely — matching the legacy defensive behavior.
Sourcepub fn on_turn_end(
&mut self,
new_messages: &[AgentMessage],
usage: &Usage,
turn_start_agent_index: usize,
) -> Result<Option<CompactionReason>, Error>
pub fn on_turn_end( &mut self, new_messages: &[AgentMessage], usage: &Usage, turn_start_agent_index: usize, ) -> Result<Option<CompactionReason>, Error>
Persist only the new messages from a completed turn.
new_messages should contain only the messages produced during this
turn (not the full conversation history). The caller is responsible for
slicing appropriately. turn_start_agent_index is the index in the
Agent’s full message buffer where new_messages[0] lives.
Returns Ok(Some(CompactionReason)) if compaction should be triggered
(the caller should emit CompactionStart, then call
execute_compaction). Returns Ok(None) if no compaction is needed.
Returns Err if a session write failed.
Sourcepub fn execute_compaction(
&mut self,
reason: CompactionReason,
) -> Result<Option<CompactionResultOutput>, Error>
pub fn execute_compaction( &mut self, reason: CompactionReason, ) -> Result<Option<CompactionResultOutput>, Error>
Execute compaction after on_turn_end returned Some(reason).
The caller should emit CompactionStart before calling this and
CompactionEnd afterwards.
Returns Err if the compaction marker could not be persisted — in this
case the in-memory state is left unchanged (no buffer replacement, no
watermark advance) so the session file stays consistent with the
runtime.
Sourcepub fn on_turn_end_simple(
&mut self,
new_messages: &[AgentMessage],
usage: &Usage,
) -> Result<Option<CompactionResultOutput>, Error>
pub fn on_turn_end_simple( &mut self, new_messages: &[AgentMessage], usage: &Usage, ) -> Result<Option<CompactionResultOutput>, Error>
Backwards-compatible variant used by tests that don’t track Agent indices.
Assumes new_messages are appended starting at the current message count.
Runs compaction inline if needed (no separate event emission).
pub fn session_id(&self) -> &str
pub fn session_path(&self) -> &Path
pub fn usage(&self) -> &CumulativeUsage
pub fn compaction_engine(&self) -> &CompactionEngine
Sourcepub fn compaction_entries(&self) -> &[Entry]
pub fn compaction_entries(&self) -> &[Entry]
Read-only view of the entries currently tracked for compaction. Exposed for tests that need to assert resume correctness.
Sourcepub fn append_leaf(&mut self, entry_id: &str) -> Result<(), Error>
pub fn append_leaf(&mut self, entry_id: &str) -> Result<(), Error>
Append a Leaf pointer marking the selected active branch tip.
Sourcepub fn cost_summary(&self) -> Option<CostBreakdown>
pub fn cost_summary(&self) -> Option<CostBreakdown>
Compute the cost summary from the accumulated usage and the model
pricing table. Returns None if no pricing is known for the model.
pub fn model(&self) -> &str
Auto Trait Implementations§
impl Freeze for SessionCoordinator
impl RefUnwindSafe for SessionCoordinator
impl Send for SessionCoordinator
impl Sync for SessionCoordinator
impl Unpin for SessionCoordinator
impl UnsafeUnpin for SessionCoordinator
impl UnwindSafe for SessionCoordinator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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