Project Memory
ox-core provides a per-project Markdown memory directory through MemoryStore. Each project receives a deterministic directory containing a MEMORY.md index and topic Markdown files, along with bounded prompt-section formatting for system prompt injection.
Configuration
Section titled “Configuration”Configure memory storage under [memory] in config.toml:
[memory]# "global" (default) stores memory under $XDG_DATA_HOME/ox/memory/<project-key>/# (fallback ~/.local/share/ox/memory/<project-key>/).# "local" stores memory inside the repository at <project-root>/.ox/memory/.mode = "global"
# Optional explicit directory override.# Relative paths resolve against the project root, and absolute paths are used as-is.# dir = ".agents/memory"| Field | Type | Default | Description |
|---|---|---|---|
mode |
string |
"global" |
Storage mode: "global" (under XDG data home) or "local" (inside the project root) |
dir |
path |
None | Explicit directory override taking precedence over mode (relative to project_root) |
MemoryStore::resolve(project_root, &config.memory) resolves the memory directory in this order:
dirwhen set (used as-is if absolute, or joined toproject_rootif relative).<project-root>/.ox/memory/whenmode = "local".$XDG_DATA_HOME/ox/memory/<project-key>/(falling back to~/.local/share/ox/memory/<project-key>/whenXDG_DATA_HOMEis unset or empty) whenmode = "global".
Callers and tests can also override the global root with MemoryStore::for_project_in or bind directly to a directory with MemoryStore::at_dir.
Directory Layout
Section titled “Directory Layout”~/.local/share/ox/memory/<project-key>/├── MEMORY.md # index loaded into the system prompt├── architecture.md # topic file└── conventions.md # topic fileproject_key(project_root) canonicalizes project_root when it exists on disk, then builds <slug>-<hash> from a sanitized ASCII directory-name slug (up to 48 characters) and a 16-hex-character 64-bit FNV-1a hash of the normalized path. This keeps directory names deterministic, bounded, and safe across filesystems.
Reading, Writing, and Listing
Section titled “Reading, Writing, and Listing”MemoryStore supports index and topic operations without creating the directory until the first write:
| Method | Behavior |
|---|---|
read_index() |
Reads MEMORY.md, returning Ok(None) when missing |
write_index(content) |
Creates the memory directory if needed and writes MEMORY.md |
read_topic(name) |
Reads <name>.md, returning Ok(None) when missing |
write_topic(name, content) |
Creates the memory directory if needed, writes <name>.md, returns its path |
delete_topic(name) |
Removes <name>.md, returning Ok(true) if removed or Ok(false) if absent |
list_entries() |
Lists regular .md files with MEMORY.md first, then topics sorted by name |
Topic names accept an optional .md suffix and must consist of ASCII alphanumeric characters, -, or _. Empty names, path separators, and the reserved MEMORY index name are rejected with MemoryError::InvalidTopicName.
System Prompt Injection
Section titled “System Prompt Injection”Use MemoryStore::prompt_section() to render a bounded # Project Memory snippet from MEMORY.md for SystemPromptBuilder. It returns None when MEMORY.md is missing or whitespace-only.
By default, prompt_section() caps the included index at DEFAULT_MAX_PROMPT_LINES (200 lines) and DEFAULT_MAX_PROMPT_BYTES (8 KiB), respecting UTF-8 character boundaries. When truncated, the rendered section appends a notice pointing to the full MEMORY.md path. Use prompt_section_bounded(max_lines, max_bytes) for custom limits.