pub struct SessionManager { /* private fields */ }Expand description
Manages the memory graph lifecycle, file I/O, and session state.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn graph(&self) -> &MemoryGraph
pub fn graph(&self) -> &MemoryGraph
Get an immutable reference to the graph.
Sourcepub fn graph_mut(&mut self) -> &mut MemoryGraph
pub fn graph_mut(&mut self) -> &mut MemoryGraph
Get a mutable reference to the graph and mark as dirty.
Sourcepub fn query_engine(&self) -> &QueryEngine
pub fn query_engine(&self) -> &QueryEngine
Get the query engine.
Sourcepub fn write_engine(&self) -> &WriteEngine
pub fn write_engine(&self) -> &WriteEngine
Get the write engine.
Sourcepub fn workspace_manager(&self) -> &WorkspaceManager
pub fn workspace_manager(&self) -> &WorkspaceManager
Get the workspace manager (immutable).
Sourcepub fn workspace_manager_mut(&mut self) -> &mut WorkspaceManager
pub fn workspace_manager_mut(&mut self) -> &mut WorkspaceManager
Get the workspace manager (mutable).
Sourcepub fn current_session_id(&self) -> u32
pub fn current_session_id(&self) -> u32
Current session ID.
Sourcepub fn start_session(&mut self, explicit_id: Option<u32>) -> McpResult<u32>
pub fn start_session(&mut self, explicit_id: Option<u32>) -> McpResult<u32>
Start a new session, optionally with an explicit ID.
Sourcepub fn end_session_with_episode(
&mut self,
session_id: u32,
summary: &str,
) -> McpResult<u64>
pub fn end_session_with_episode( &mut self, session_id: u32, summary: &str, ) -> McpResult<u64>
End a session and optionally create an episode summary.
Sourcepub fn save(&mut self) -> McpResult<()>
pub fn save(&mut self) -> McpResult<()>
Save the graph to file with file-locking for concurrent session safety.
When multiple MCP instances share the same .amem file, this method:
- Acquires an exclusive file lock (sidecar
.amem.lock) - Checks if the file was modified externally (by another instance)
- If so, re-reads the disk graph and merges our session’s new nodes
- Writes the merged graph and releases the lock
Sourcepub fn maybe_auto_save(&mut self) -> McpResult<()>
pub fn maybe_auto_save(&mut self) -> McpResult<()>
Check if auto-save is needed and save if so.
Sourcepub fn run_maintenance_tick(&mut self) -> McpResult<()>
pub fn run_maintenance_tick(&mut self) -> McpResult<()>
Runs autonomous maintenance: sleep-cycle, auto-save, and periodic backup.
Sourcepub fn maybe_run_sleep_cycle(&mut self) -> McpResult<()>
pub fn maybe_run_sleep_cycle(&mut self) -> McpResult<()>
Run a periodic sleep-cycle: decay refresh + tier balancing + auto-archive.
Sourcepub fn maybe_auto_backup(&mut self) -> McpResult<()>
pub fn maybe_auto_backup(&mut self) -> McpResult<()>
Periodic backup of persisted state with retention pruning.
Sourcepub fn mark_dirty(&mut self)
pub fn mark_dirty(&mut self)
Mark the graph as dirty (needs saving).
Sourcepub fn last_temporal_node_id(&self) -> Option<u64>
pub fn last_temporal_node_id(&self) -> Option<u64>
The ID of the most recent node in the temporal chain for this session.
Sourcepub fn advance_temporal_chain(&mut self, node_id: u64)
pub fn advance_temporal_chain(&mut self, node_id: u64)
Advance the temporal chain pointer to the given node ID.
Sourcepub fn link_temporal(&mut self, prev_id: u64, next_id: u64) -> McpResult<()>
pub fn link_temporal(&mut self, prev_id: u64, next_id: u64) -> McpResult<()>
Create a TemporalNext edge from prev_id to next_id (forward in time).
Sourcepub fn maintenance_interval(&self) -> Duration
pub fn maintenance_interval(&self) -> Duration
Background maintenance loop interval.
Sourcepub fn capture_prompt_request(
&mut self,
prompt_name: &str,
arguments: Option<&Value>,
) -> McpResult<Option<u64>>
pub fn capture_prompt_request( &mut self, prompt_name: &str, arguments: Option<&Value>, ) -> McpResult<Option<u64>>
Capture a prompt template invocation (prompts/get) into memory.
Sourcepub fn capture_tool_call(
&mut self,
tool_name: &str,
arguments: Option<&Value>,
) -> McpResult<Option<u64>>
pub fn capture_tool_call( &mut self, tool_name: &str, arguments: Option<&Value>, ) -> McpResult<Option<u64>>
Capture a tool call input context into memory based on capture mode.