clawgarden-agent 0.7.3

Agent runtime with persona/memory loader, judge, and pi RPC for ClawGarden
Documentation
//! Memory loader - loads agent memory from filesystem

use anyhow::Result;
use std::path::Path;

/// Load memory for an agent from <workspace>/agents/<name>/memory.md
///
/// Memory is optional, so missing files are not treated as errors.
/// Returns the memory content as a String, or empty string if not found.
pub async fn load_memory(agent_name: &str) -> Result<String> {
    let config = clawgarden_proto::AppConfig::load();
    let path = Path::new(&config.agents_dir())
        .join(agent_name)
        .join("memory.md");

    match tokio::fs::read_to_string(&path).await {
        Ok(content) => {
            log::info!(
                "Loaded memory for agent '{}' from {}",
                agent_name,
                path.display()
            );
            Ok(content)
        }
        Err(e) => {
            // Memory is optional, don't warn - just return empty
            log::debug!(
                "Memory file not found for agent '{}' at {} (optional): {}",
                agent_name,
                path.display(),
                e
            );
            Ok(String::new())
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_load_memory_missing_file() {
        let result = load_memory("nonexistent_agent").await;
        assert!(result.is_ok());
        assert!(result.unwrap().is_empty());
    }
}