Skip to main content

resolve_memory_dir

Function resolve_memory_dir 

Source
pub fn resolve_memory_dir(
    scope: MemoryScope,
    agent_name: &str,
) -> Result<PathBuf, SubAgentError>
Expand description

Resolve the memory directory path for a given scope and agent name.

Agent name is validated against the same regex enforced in parse_with_path. This prevents path traversal via crafted names (e.g., ../../../etc).

ScopeDirectory
User~/.zeph/agent-memory/<name>/
Project.zeph/agent-memory/<name>/ (relative to CWD)
Local.zeph/agent-memory-local/<name>/ (relative to CWD)

§Errors

Returns SubAgentError::Invalid if the agent name fails validation. Returns SubAgentError::Memory if the home directory is unavailable (User scope).

§Examples

use zeph_subagent::memory::resolve_memory_dir;
use zeph_config::MemoryScope;

// Path traversal names are rejected.
assert!(resolve_memory_dir(MemoryScope::Project, "../etc").is_err());
// Valid names produce a usable path (relative to the current working directory).
let path = resolve_memory_dir(MemoryScope::Project, "my-agent").unwrap();
assert!(path.ends_with(".zeph/agent-memory/my-agent"));