Skip to main content

ralph/tools/
memory_tools.rs

1use crate::memory::MemoryStore;
2
3/// Store a key/value fact in project memory.
4pub fn remember(memory: &mut MemoryStore, key: &str, value: &str) -> String {
5    memory.upsert(key, value);
6    format!("Remembered: {} = {}", key, value)
7}
8
9/// Search stored facts. Empty query returns all facts.
10pub fn recall(memory: &MemoryStore, query: &str) -> String {
11    if query.trim().is_empty() {
12        let facts = memory.all_facts();
13        if facts.is_empty() {
14            return "No facts stored yet.".to_string();
15        }
16        let mut out = format!("All {} stored fact(s):\n\n", facts.len());
17        for f in &facts {
18            out.push_str(&format!("  {}: {}\n", f.key, f.value));
19        }
20        return out;
21    }
22    let results = memory.search(query);
23    if results.is_empty() {
24        return format!("No facts found matching '{}'.", query);
25    }
26    let mut out = format!("Found {} fact(s) matching '{}':\n\n", results.len(), query);
27    for f in &results {
28        out.push_str(&format!("  {}: {}\n", f.key, f.value));
29    }
30    out
31}