pub struct ConversationManager { /* private fields */ }Expand description
Manages conversation persistence for a project
Implementations§
Source§impl ConversationManager
impl ConversationManager
Sourcepub fn new(project_dir: impl AsRef<Path>) -> Result<Self>
pub fn new(project_dir: impl AsRef<Path>) -> Result<Self>
Create a new conversation manager for a project directory
§Errors
Creating .mermaid/conversations or .mermaid/compactions under
project_dir — a read-only or unwritable project. Both are created
here, so the later load and list paths can treat an unreadable
directory as “no conversations” rather than a failure.
Sourcepub fn save_conversation(
&self,
conversation: &ConversationHistory,
) -> Result<()>
pub fn save_conversation( &self, conversation: &ConversationHistory, ) -> Result<()>
Save a conversation to disk
§Errors
An id that would escape the conversations dir, serializing the
conversation, and the atomic 0600 write. Two cases that look like
failures are Ok: a message-less conversation is deliberately not
persisted, and a concurrent writer detected through the (mtime, len)
baseline diverts this copy to a .conflict sibling and warns instead
of overwriting. The .meta sidecar is best-effort and never fails the
save.
Sourcepub fn save_compaction_archive(
&self,
archive: &CompactionArchive,
) -> Result<PathBuf>
pub fn save_compaction_archive( &self, archive: &CompactionArchive, ) -> Result<PathBuf>
Save the raw messages removed by a compaction. Archives live
outside the hot conversation JSON so /load and /list don’t
parse old transcripts on every startup.
§Errors
A conversation id or archive id that would traverse, creating the per-conversation archive directory, serializing the archive, and the atomic 0600 write. Nothing here is best-effort: this is the only durable copy of the compacted-out messages, so a failed write must reach the caller rather than silently drop them.
Sourcepub fn load_conversation(&self, id: &str) -> Result<ConversationHistory>
pub fn load_conversation(&self, id: &str) -> Result<ConversationHistory>
Load a specific conversation by ID
§Errors
An id that would escape the conversations dir, a file that is
missing, unreadable, or past the size cap, JSON that does not parse,
and a parsed id that would itself traverse — checked separately,
because that field is on-disk state that drives later saves.
Sourcepub fn load_last_conversation(&self) -> Result<Option<ConversationHistory>>
pub fn load_last_conversation(&self) -> Result<Option<ConversationHistory>>
Load the most recent valid conversation.
Iterates files newest-first by mtime and returns the first that reads,
parses, and has a valid id — skipping (with a warning) any unreadable,
unparseable, or traversing-id file. Mirrors list_conversations’s
tolerance so one corrupt/partial file (e.g. a crash mid-write) can’t make
--continue hard-fail; it falls back to the next-newest valid conversation.
§Errors
In practice none: an unreadable conversations dir and every unreadable,
oversized, unparseable, or traversing-id file are skipped with a
warning, and running out of candidates is Ok(None). The Result is
kept for callers that already handle one and so this can grow a real
failure later.
Sourcepub fn list_conversations(&self) -> Result<Vec<ConversationHistory>>
pub fn list_conversations(&self) -> Result<Vec<ConversationHistory>>
List all conversations in the project
§Errors
In practice none, and deliberately: an unreadable directory yields an empty list, and any file that will not read or parse is skipped, so one corrupt transcript cannot empty the picker.
Sourcepub fn list_conversation_metas(&self) -> Result<Vec<ConversationMeta>>
pub fn list_conversation_metas(&self) -> Result<Vec<ConversationMeta>>
Fast session list: read each <id>.meta sidecar; for a session that
lacks a (valid) one — older, or written by a pre-sidecar build — fall
back to fully parsing its <id>.json. Message-less sessions are skipped.
Newest-first. Cheaper than Self::list_conversations for display-only paths.
§Errors
In practice none, matching Self::list_conversations: an unreadable
directory yields an empty list, and a sidecar that will not read or
parse falls through to parsing its <id>.json, which is itself skipped
if that fails too.
Sourcepub fn delete_conversation(&self, id: &str) -> Result<()>
pub fn delete_conversation(&self, id: &str) -> Result<()>
Delete a conversation (and its metadata sidecar).
§Errors
An id that would escape the conversations dir, and removing the
<id>.json itself. An id with no file is Ok, and the .meta sidecar
and the session scratch dir are cleaned up best-effort — neither can
fail the delete.
Sourcepub fn conversations_dir(&self) -> &Path
pub fn conversations_dir(&self) -> &Path
Get the conversations directory path
pub fn compactions_dir(&self) -> &Path
Trait Implementations§
Source§impl Clone for ConversationManager
impl Clone for ConversationManager
Source§fn clone(&self) -> ConversationManager
fn clone(&self) -> ConversationManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ConversationManager
impl RefUnwindSafe for ConversationManager
impl Send for ConversationManager
impl Sync for ConversationManager
impl Unpin for ConversationManager
impl UnsafeUnpin for ConversationManager
impl UnwindSafe for ConversationManager
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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