pub struct SessionManager {
pub log: SessionLog,
pub history: Vec<ChatMessage>,
}Expand description
Manages the storage and retrieval of session logs.
Creates the log file that the current run writes to, and loads the transcript of the session being resumed, if any.
Fields§
§log: SessionLogThe session log this run writes to (null when no session-logs directory was given).
history: Vec<ChatMessage>Transcript of the session being resumed; empty when starting fresh.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(session_logs: Option<&Path>, resume: &Resume) -> Result<Self>
pub fn new(session_logs: Option<&Path>, resume: &Resume) -> Result<Self>
Create the session log for this run and, if requested, load the transcript of the session to resume.
The resume target is resolved before the new log file is created, so the file created by this call can never be picked as the newest log.
A Resume::File whose path is a bare file name (no directory part) and not found in the
current directory is looked up in the session-logs directory, if one was given, also
trying <name>.jsonl when the name has no extension.
Sourcefn newest_log(dir: &Path) -> Result<PathBuf>
fn newest_log(dir: &Path) -> Result<PathBuf>
Find the newest non-empty session log in dir, by modification time (ties broken by name,
which is timestamped).
Sourcefn resolve_resume_file(
file: &Path,
session_logs: Option<&Path>,
) -> Result<PathBuf>
fn resolve_resume_file( file: &Path, session_logs: Option<&Path>, ) -> Result<PathBuf>
Resolve the file to resume from.
A bare file name (no directory part, i.e. no slash) that does not exist in the current
directory is looked up in the session-logs directory, if one was given, also trying
<name>.jsonl when the name has no extension. Anything else is used as-is: a path that
exists nowhere then fails with the natural load error, unless a directory was given and
the bare name is in neither place, which is its own error.
Sourcefn is_bare_name(file: &Path) -> bool
fn is_bare_name(file: &Path) -> bool
A bare file name: exactly one path component, so no directory part (no slash).
Sourcefn new_log_name() -> String
fn new_log_name() -> String
A session log file name, timestamped so that names sort chronologically.