From 3e30e13e7601884a8f3ec69a7899fd3e8d207e4f Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sun, 24 May 2026 03:42:43 +0800 Subject: Add optional --about filter to explore and dumpall commands --- builtin/PROMPT.md | 8 +++++--- src/mem_mgr.rs | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/builtin/PROMPT.md b/builtin/PROMPT.md index 6a4cdef..5343b4f 100644 --- a/builtin/PROMPT.md +++ b/builtin/PROMPT.md @@ -39,7 +39,7 @@ Always decide the language of your reply based on the language the user uses to ## Explore (view all memory entries) ``` -memm explore +memm explore [--about ] ``` This tool outputs a list of entry titles. You can **read, rewrite, remember, forget, or dumpall** specific memories based on the titles in the list. @@ -95,10 +95,12 @@ This tool **completely replaces** the content of the memory entry with the new * ## DumpAll (dump all memory entries with their full content) ``` -memm dumpall +memm dumpall [--about ] ``` -This tool outputs **all memory entries** with their **full content** in a structured format, including each entry's title and content. This is useful when you need to see everything at once, e.g., when the chat session just started to load all memories into context. +**FILTER** (optional): A fuzzy filter string to narrow down results. Only entries whose title matches the filter (case-insensitive, alphanumeric-only comparison) will be returned. + +This tool outputs **all memory entries** (or those matching the optional filter) with their **full content** in a structured format, including each entry's title and content. This is useful when you need to see everything at once, e.g., when the chat session just started to load all memories into context. **Important:** When you first enter a new chat session, you **must** use `memm dumpall` to load all past memories into your context. diff --git a/src/mem_mgr.rs b/src/mem_mgr.rs index 8b9d950..c6e442e 100644 --- a/src/mem_mgr.rs +++ b/src/mem_mgr.rs @@ -50,8 +50,9 @@ pub fn handle_read(args: EntryRead, constants: &Constants) -> Next { } #[chain] -pub fn handle_dumpall(_p: EntryDumpAll, constants: &Constants) -> Next { - dumpall(constants).to_render() +pub fn handle_dumpall(args: EntryDumpAll, constants: &Constants) -> Next { + let about = args.pick::("--about").unpack(); + dumpall(constants, about).to_render() } #[derive(Serialize, Groupped)] @@ -214,7 +215,7 @@ fn forget(constants: &Constants, title: String) -> ResultForgotten { } } -fn dumpall(constants: &Constants) -> ResultDumpAll { +fn dumpall(constants: &Constants, about: String) -> ResultDumpAll { let store_root = &constants.store_root; let mut entries = Vec::new(); if let Ok(dir_entries) = std::fs::read_dir(store_root) { @@ -225,6 +226,22 @@ fn dumpall(constants: &Constants) -> ResultDumpAll { if let Some(stem) = path.file_stem() { let title = stem.to_string_lossy().to_string(); let content = std::fs::read_to_string(&path).unwrap_or_default(); + // If about is provided and not empty, do fuzzy matching on lowercase alphanumeric + if !about.is_empty() { + let filter: String = about + .chars() + .filter(|c| c.is_alphanumeric()) + .collect::() + .to_lowercase(); + let title_clean: String = title + .chars() + .filter(|c| c.is_alphanumeric()) + .collect::() + .to_lowercase(); + if !title_clean.contains(&filter) { + continue; + } + } entries.push(DumpEntry { title, content }); } } -- cgit