pub struct SessionJournal {
pub entries: Vec<SessionEntry>,
pub leaf_id: Option<EntryId>,
pub schema_version: u32,
pub spawn_depth: u32,
}Fields§
§entries: Vec<SessionEntry>§leaf_id: Option<EntryId>§schema_version: u32§spawn_depth: u32Implementations§
Source§impl SessionJournal
impl SessionJournal
pub fn new() -> Self
pub fn with_spawn_depth(depth: u32) -> Self
pub fn append(&mut self, kind: SessionEntryKind) -> EntryId
Sourcepub fn append_stamped(
&mut self,
kind: SessionEntryKind,
created_at: DateTime<Utc>,
) -> EntryId
pub fn append_stamped( &mut self, kind: SessionEntryKind, created_at: DateTime<Utc>, ) -> EntryId
Append an entry carrying the time the underlying event happened, not
the time the save ran. created_at is the journal’s timeline; stamping
it at append is what keeps a rebuilt journal honest — a save must never
rewrite an entry’s time to the moment it was written.
pub fn append_message(&mut self, message: Message) -> EntryId
pub fn append_compaction( &mut self, summary: String, tokens_before: Option<u64>, tokens_after: Option<u64>, model: Option<String>, ) -> EntryId
pub fn append_branch_summary( &mut self, branch_id: String, summary: String, parent_branch_id: Option<String>, ) -> EntryId
pub fn branch_to(&mut self, entry_id: &str) -> Result<(), String>
pub fn fork_from(&self, from_entry_id: Option<&str>) -> Result<Self, String>
pub fn index(&self) -> HashMap<&str, &SessionEntry>
pub fn children_of(&self, parent_id: Option<&str>) -> Vec<&SessionEntry>
pub fn contains(&self, entry_id: &str) -> bool
pub fn leaf(&self) -> Option<&SessionEntry>
pub fn root_to_leaf(&self) -> Vec<&SessionEntry>
pub fn active_messages(&self, include_system: bool) -> Vec<Message>
pub fn leaves(&self) -> Vec<&SessionEntry>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn validate(&self) -> Result<(), String>
pub fn from_messages(messages: Vec<Message>, spawn_depth: u32) -> Self
Sourcepub fn from_messages_stamped(
messages: Vec<Message>,
stamps: &[DateTime<Utc>],
spawn_depth: u32,
) -> Self
pub fn from_messages_stamped( messages: Vec<Message>, stamps: &[DateTime<Utc>], spawn_depth: u32, ) -> Self
Build the journal honoring a per-message append stamp. stamps[i] is
the time messages[i] entered the conversation; a missing stamp falls
back to now, so a drifted caller degrades to save-time ordering rather
than dropping the message.
pub fn to_messages(&self) -> Vec<Message>
Sourcepub fn rebranch_active_messages(&mut self, messages: &[Message])
pub fn rebranch_active_messages(&mut self, messages: &[Message])
Make messages the active projection without rewriting the journal.
The existing active branch remains as evidence. We reuse its longest unchanged prefix, then append the repaired suffix as a sibling branch.
Sourcepub fn rebranch_active_messages_stamped(
&mut self,
messages: &[Message],
stamps: &[DateTime<Utc>],
)
pub fn rebranch_active_messages_stamped( &mut self, messages: &[Message], stamps: &[DateTime<Utc>], )
Preserve existing entry identity and timestamps; only append the changed suffix, keeping the previous branch reachable.
Sourcepub fn prune_plan(
&self,
dead_threshold: usize,
dead_budget: usize,
) -> Vec<EntryId> ⓘ
pub fn prune_plan( &self, dead_threshold: usize, dead_budget: usize, ) -> Vec<EntryId> ⓘ
Ids a bounded save may move out of this journal, in journal order.
Empty until more than dead_threshold entries sit off the active
branch — superseded versions left behind by compaction, undo and
edits (#6842). Past it, the plan keeps the root→leaf path, then whole
off-branch chains (an entry with every ancestor) newest first, with
Compaction/BranchSummary chains ahead of plain leaves, while the
kept off-branch total stays within dead_budget. A kept entry never
loses its parent, so the remainder always passes Self::validate.
Pure: callers archive the planned entries durably before removing
them with Self::remove_entries. Known limit: the active branch
itself is never pruned, so a session that never compacts stays as
long as its conversation.