Skip to main content

SessionManager

Struct SessionManager 

Source
pub struct SessionManager { /* private fields */ }
Expand description

Manages the memory graph lifecycle, file I/O, and session state.

Implementations§

Source§

impl SessionManager

Source

pub fn open(path: &str) -> McpResult<Self>

Open or create a memory file at the given path.

Source

pub fn graph(&self) -> &MemoryGraph

Get an immutable reference to the graph.

Source

pub fn graph_mut(&mut self) -> &mut MemoryGraph

Get a mutable reference to the graph and mark as dirty.

Source

pub fn query_engine(&self) -> &QueryEngine

Get the query engine.

Source

pub fn write_engine(&self) -> &WriteEngine

Get the write engine.

Source

pub fn workspace_manager(&self) -> &WorkspaceManager

Get the workspace manager (immutable).

Source

pub fn workspace_manager_mut(&mut self) -> &mut WorkspaceManager

Get the workspace manager (mutable).

Source

pub fn current_session_id(&self) -> u32

Current session ID.

Source

pub fn start_session(&mut self, explicit_id: Option<u32>) -> McpResult<u32>

Start a new session, optionally with an explicit ID.

Source

pub fn end_session_with_episode( &mut self, session_id: u32, summary: &str, ) -> McpResult<u64>

End a session and optionally create an episode summary.

Source

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:

  1. Acquires an exclusive file lock (sidecar .amem.lock)
  2. Checks if the file was modified externally (by another instance)
  3. If so, re-reads the disk graph and merges our session’s new nodes
  4. Writes the merged graph and releases the lock
Source

pub fn maybe_auto_save(&mut self) -> McpResult<()>

Check if auto-save is needed and save if so.

Source

pub fn run_maintenance_tick(&mut self) -> McpResult<()>

Runs autonomous maintenance: sleep-cycle, auto-save, and periodic backup.

Source

pub fn maybe_run_sleep_cycle(&mut self) -> McpResult<()>

Run a periodic sleep-cycle: decay refresh + tier balancing + auto-archive.

Source

pub fn maybe_auto_backup(&mut self) -> McpResult<()>

Periodic backup of persisted state with retention pruning.

Source

pub fn mark_dirty(&mut self)

Mark the graph as dirty (needs saving).

Source

pub fn file_path(&self) -> &PathBuf

Get the file path.

Source

pub fn last_temporal_node_id(&self) -> Option<u64>

The ID of the most recent node in the temporal chain for this session.

Source

pub fn advance_temporal_chain(&mut self, node_id: u64)

Advance the temporal chain pointer to the given node ID.

Create a TemporalNext edge from prev_id to next_id (forward in time).

Source

pub fn maintenance_interval(&self) -> Duration

Background maintenance loop interval.

Source

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.

Source

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.

Source

pub fn add_event( &mut self, event_type: EventType, content: &str, confidence: f32, edges: Vec<(u64, EdgeType, f32)>, ) -> McpResult<(u64, usize)>

Add a cognitive event to the graph.

Source

pub fn correct_node( &mut self, old_node_id: u64, new_content: &str, ) -> McpResult<u64>

Correct a previous belief.

Trait Implementations§

Source§

impl Drop for SessionManager

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more