pub struct Session {
pub id: String,
pub cwd: String,
pub messages: Vec<Value>,
/* private fields */
}Expand description
Manages session state and persistence.
Fields§
§id: String§cwd: String§messages: Vec<Value>Implementations§
Source§impl Session
impl Session
Sourcepub fn with_id(id: impl Into<String>, cwd: impl Into<String>) -> Self
pub fn with_id(id: impl Into<String>, cwd: impl Into<String>) -> Self
Create a session with a specific ID.
Sourcepub fn with_home(self, home: impl Into<PathBuf>) -> Self
pub fn with_home(self, home: impl Into<PathBuf>) -> Self
Set an explicit home directory override (useful for testing).
Sourcepub fn sessions_dir(cwd: &str) -> PathBuf
pub fn sessions_dir(cwd: &str) -> PathBuf
Get the path where sessions are stored for a given working directory.
Sourcepub fn sessions_dir_with_home(cwd: &str, home: PathBuf) -> PathBuf
pub fn sessions_dir_with_home(cwd: &str, home: PathBuf) -> PathBuf
Get the sessions directory using an explicit home path.
Sourcepub fn transcript_path(&self) -> PathBuf
pub fn transcript_path(&self) -> PathBuf
Get the file path for this session’s transcript.
Sourcepub async fn append_message(&self, message: &Value) -> Result<()>
pub async fn append_message(&self, message: &Value) -> Result<()>
Append a JSON message to the transcript file on disk.
Creates the sessions directory and file if they don’t exist. The message is serialized as a single JSON line followed by a newline.
Sourcepub async fn load_messages(&self) -> Result<Vec<Value>>
pub async fn load_messages(&self) -> Result<Vec<Value>>
Load all messages from the transcript file.
Returns an empty vec if the file does not exist. Skips any lines that fail to parse as JSON, logging a warning.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
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
Mutably borrows from an owned value. Read more
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>
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 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>
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 moreCreates a shared type from an unshared type.