pub struct MemoryStore<P: Platform> { /* private fields */ }Expand description
Long-term and session memory store.
Wraps two markdown files (MEMORY.md and HISTORY.md) behind the
platform filesystem abstraction. Reads are lock-free (each call reads
the file); writes go through the platform’s append/write operations.
§Directory resolution
The constructor resolves the memory directory using the fallback chain:
~/.clawft/workspace/memory/~/.nanobot/workspace/memory/(legacy fallback)
If neither exists, the .clawft path is used and created on first write.
Implementations§
Source§impl<P: Platform> MemoryStore<P>
impl<P: Platform> MemoryStore<P>
Sourcepub fn new(platform: Arc<P>) -> Result<Self>
pub fn new(platform: Arc<P>) -> Result<Self>
Create a new memory store.
Resolves the workspace memory directory from the platform home
directory. Prefers ~/.clawft/workspace/memory/; falls back to
~/.nanobot/workspace/memory/ if the .clawft directory does
not exist but .nanobot does.
§Errors
Returns ClawftError::ConfigInvalid if no home directory can
be determined from the platform.
Sourcepub async fn read_long_term(&self) -> Result<String>
pub async fn read_long_term(&self) -> Result<String>
Read long-term memory (MEMORY.md).
Returns an empty string if the file does not exist yet, matching the Python nanobot behavior. I/O errors other than “not found” are propagated.
Sourcepub async fn write_long_term(&self, content: &str) -> Result<()>
pub async fn write_long_term(&self, content: &str) -> Result<()>
Write (overwrite) long-term memory.
Creates parent directories if they do not exist.
Sourcepub async fn append_long_term(&self, entry: &str) -> Result<()>
pub async fn append_long_term(&self, entry: &str) -> Result<()>
Append an entry to long-term memory.
Each entry is terminated with a double newline to form distinct paragraphs for later search.
Sourcepub async fn read_history(&self) -> Result<String>
pub async fn read_history(&self) -> Result<String>
Read the history file (HISTORY.md).
Returns an empty string if the file does not exist yet.
Sourcepub async fn append_history(&self, entry: &str) -> Result<()>
pub async fn append_history(&self, entry: &str) -> Result<()>
Append an entry to the history file.
Each entry is terminated with a double newline to match the
Python append_history behavior.
Sourcepub async fn search(&self, query: &str, max_results: usize) -> Vec<String>
pub async fn search(&self, query: &str, max_results: usize) -> Vec<String>
Substring search across both memory files.
Splits content by double-newline into paragraphs, then returns
paragraphs containing query (case-insensitive). Results are
returned in document order, capped at max_results.
Sourcepub fn memory_path(&self) -> &PathBuf
pub fn memory_path(&self) -> &PathBuf
Path to the memory file (for diagnostics / context building).
Sourcepub fn history_path(&self) -> &PathBuf
pub fn history_path(&self) -> &PathBuf
Path to the history file (for diagnostics / context building).
Auto Trait Implementations§
impl<P> Freeze for MemoryStore<P>
impl<P> RefUnwindSafe for MemoryStore<P>where
P: RefUnwindSafe,
impl<P> Send for MemoryStore<P>
impl<P> Sync for MemoryStore<P>
impl<P> Unpin for MemoryStore<P>
impl<P> UnsafeUnpin for MemoryStore<P>
impl<P> UnwindSafe for MemoryStore<P>where
P: RefUnwindSafe,
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> 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