pub struct StateManager { /* private fields */ }Expand description
Manages session state storage with per-session directory structure.
State is stored in: ~/.config/autom8/<project>/sessions/<session-id>/
Each session has:
state.json- The full run statemetadata.json- Quick metadata for session listing
The spec/ and runs/ directories remain at the project level (shared across sessions).
Implementations§
Source§impl StateManager
impl StateManager
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a StateManager using the config directory for the current project.
Auto-detects session ID from the current working directory.
Uses ~/.config/autom8/<project-name>/ as the base directory.
Sourcepub fn with_session(session_id: String) -> Result<Self>
pub fn with_session(session_id: String) -> Result<Self>
Create a StateManager for a specific session.
Uses ~/.config/autom8/<project-name>/ as the base directory.
Sourcepub fn for_project(project_name: &str) -> Result<Self>
pub fn for_project(project_name: &str) -> Result<Self>
Create a StateManager for a specific project name.
Auto-detects session ID from the current working directory.
Uses ~/.config/autom8/<project-name>/ as the base directory.
Sourcepub fn for_project_session(
project_name: &str,
session_id: String,
) -> Result<Self>
pub fn for_project_session( project_name: &str, session_id: String, ) -> Result<Self>
Create a StateManager for a specific project and session.
Uses ~/.config/autom8/<project-name>/ as the base directory.
Sourcepub fn with_dir(dir: PathBuf) -> Self
pub fn with_dir(dir: PathBuf) -> Self
Create a StateManager with a custom base directory (for testing).
Sourcepub fn with_dir_and_session(dir: PathBuf, session_id: String) -> Self
pub fn with_dir_and_session(dir: PathBuf, session_id: String) -> Self
Create a StateManager with a custom base directory and session ID (for testing).
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Get the session ID for this manager.
pub fn ensure_dirs(&self) -> Result<()>
Sourcepub fn ensure_spec_dir(&self) -> Result<PathBuf>
pub fn ensure_spec_dir(&self) -> Result<PathBuf>
Ensure spec directory exists
Sourcepub fn list_specs(&self) -> Result<Vec<PathBuf>>
pub fn list_specs(&self) -> Result<Vec<PathBuf>>
List all spec JSON files in the config directory’s spec/, sorted by modification time (newest first)
pub fn load_current(&self) -> Result<Option<RunState>>
Sourcepub fn load_metadata(&self) -> Result<Option<SessionMetadata>>
pub fn load_metadata(&self) -> Result<Option<SessionMetadata>>
Load the metadata for the current session.
Sourcepub fn save(&self, state: &RunState) -> Result<()>
pub fn save(&self, state: &RunState) -> Result<()>
Save the run state and update session metadata.
pub fn clear_current(&self) -> Result<()>
Sourcepub fn save_live(&self, live_state: &LiveState) -> Result<()>
pub fn save_live(&self, live_state: &LiveState) -> Result<()>
Save live state atomically (write to temp file, then rename).
Atomic writes prevent the monitor from reading a partial/corrupted file.
Sourcepub fn load_live(&self) -> Option<LiveState>
pub fn load_live(&self) -> Option<LiveState>
Load live state, returning None if file doesn’t exist or is corrupted.
Gracefully handles missing or malformed files so the monitor can recover without crashing.
Sourcepub fn clear_live(&self) -> Result<()>
pub fn clear_live(&self) -> Result<()>
Remove the live state file.
pub fn archive(&self, state: &RunState) -> Result<PathBuf>
pub fn list_archived(&self) -> Result<Vec<RunState>>
pub fn has_active_run(&self) -> Result<bool>
Sourcepub fn list_sessions(&self) -> Result<Vec<SessionMetadata>>
pub fn list_sessions(&self) -> Result<Vec<SessionMetadata>>
List all sessions for this project with their metadata.
Returns sessions sorted by last_active_at descending (most recent first). Sessions without valid metadata are skipped.
Sourcepub fn get_session(&self, session_id: &str) -> Option<StateManager>
pub fn get_session(&self, session_id: &str) -> Option<StateManager>
Get a specific session by ID.
Returns a new StateManager configured for the specified session. Returns None if the session doesn’t exist.
Sourcepub fn list_sessions_with_status(&self) -> Result<Vec<SessionStatus>>
pub fn list_sessions_with_status(&self) -> Result<Vec<SessionStatus>>
List all sessions with enriched status information.
Returns sessions sorted with current session first, then by last_active_at descending. Includes state details (machine state, current story) and marks stale sessions (deleted worktrees).
Sourcepub fn find_session_for_branch(
&self,
branch: &str,
) -> Result<Option<SessionMetadata>>
pub fn find_session_for_branch( &self, branch: &str, ) -> Result<Option<SessionMetadata>>
Find the most recent session that worked on the specified branch.
Searches all sessions in the project and returns the one with the most
recent last_active_at timestamp that matches the branch name. This is
used by the improve command to load accumulated knowledge from previous
runs on the same branch.
Both worktree sessions and main repo sessions are searched.
§Arguments
branch- The branch name to search for
§Returns
Ok(Some(metadata))- Found a session that worked on this branchOk(None)- No session found for this branch (graceful degradation)Err- Error reading session data
Sourcepub fn check_branch_conflict(
&self,
branch_name: &str,
) -> Result<Option<SessionMetadata>>
pub fn check_branch_conflict( &self, branch_name: &str, ) -> Result<Option<SessionMetadata>>
Check for branch conflicts with other active sessions.
Returns the conflicting session metadata if another session is already using the specified branch. A session “owns” a branch only while it is actively running (status == Running).
Stale sessions (where the worktree directory no longer exists) are automatically skipped and do not cause conflicts.
§Arguments
branch_name- The branch name to check for conflicts
§Returns
Ok(Some(metadata))- Another session is using this branchOk(None)- No conflict, branch is availableErr- Error reading session data
Auto Trait Implementations§
impl Freeze for StateManager
impl RefUnwindSafe for StateManager
impl Send for StateManager
impl Sync for StateManager
impl Unpin for StateManager
impl UnwindSafe for StateManager
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> 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