//! Remember a lesson or fact as persistent memory. //! //! Constructs a `Memory` struct from tool arguments and persists it //! via `MarkdownMemoryRepository` to the memory directory. use crate::tools::{Tool, ToolCtx}; use anyhow::Result; use serde_json::{json, Value}; use tracing::{info, instrument}; use zesdex_domain::cms::{Memory, MemoryRepository}; /// Tool that saves a lesson or fact to persistent memory. /// /// Flow: parse name/description/content/kind → construct a `Memory` struct /// with timestamps → instantiate `MarkdownMemoryRepository` → call /// `repo.save()` with the memory directory → confirm save. pub struct Remember; impl Tool for Remember { fn name(&self) -> &'static str { "remember" } fn description(&self) -> &'static str { "Save a lesson or fact to persistent memory" } fn parameters(&self) -> Value { json!({ "type": "object", "properties": { "name": { "type": "string", "description": "Unique name for this memory" }, "description": { "type": "string", "description": "Short summary of the memory" }, "content": { "type": "string", "description": "Full content of the memory" }, "kind": { "type": "string", "enum": ["lesson", "reference", "fact"], "description": "Category of memory" } }, "required": ["name", "description", "content"] }) } #[instrument(skip(self, ctx, args))] fn run(&self, ctx: &ToolCtx, args: &Value) -> Result { let name = crate::tools::arg_str(args, "name")?; let description = crate::tools::arg_str(args, "description")?; let content = crate::tools::arg_str(args, "content")?; let kind = args .get("kind") .and_then(|v| v.as_str()) .unwrap_or("reference") .to_string(); info!(name, kind, "remember invoked"); let memory = Memory { name: name.clone(), description, content, kind, created_at: chrono::Utc::now().timestamp(), updated_at: chrono::Utc::now().timestamp(), outcome: None, lifecycle: "active".to_string(), scope: None, before_snippet: None, after_snippet: None, provenances: Vec::new(), }; let repo = crate::persistence::cms::memory_repo::MarkdownMemoryRepository::new(); let memory_dir = crate::tools::memory::resolve_memory_dir(&ctx.memory_dir); repo.save(&memory_dir, &memory)?; info!(name, "memory saved"); Ok(format!("Memory '{}' saved", name)) } }