Memory System
Zettelkasten-based persistent memory for the cowboy WASM plugin using the zk CLI. Provides cross-session knowledge persistence for facts, decisions, and daily journals.
Status
Fully implemented in src/memory.rs. Integrated into the harness session lifecycle: initialization, loading, recall, error remembering, and memory-augmented LLM prompts.
Architecture
Since cowboy runs as a WASM plugin (no direct process spawning), the memory module produces ZkCommand structs containing shell command arguments and environment variables. The main loop executes these via run_command() and routes results back through handle_memory_result().
Directory Layout
/home/agent/memory/
.zk/config.toml
daily/YYYY-MM-DD.md
facts/*.md
decisions/*.md
templates/
Core Operations
| Operation | Method | Description |
|---|---|---|
| init | ZkMemory::init() | Create directory structure, initialize zk |
| remember | ZkMemory::remember(title, content, template) | Create a fact or decision note |
| recall | ZkMemory::recall(query) | Full-text search via zk list --match |
| journal | ZkMemory::journal(entry) | Append timestamped entry to today's daily note |
| today | ZkMemory::today() | Get or create today's daily note |
| by_tag | ZkMemory::by_tag(tag) | Search notes by tag |
| recent | ZkMemory::recent(limit) | List recent notes sorted by modification time |
| get_related | ZkMemory::get_related(path) | Find notes linked to a given note |
| link | ZkMemory::link(from, to, text) | Create a wiki-link between notes |
Session Lifecycle
- Startup:
init_memory()creates the zk directory structure - Session init:
load_initial_memories()loads recent facts (last 10) - Per-turn:
recall_for_query()runs async recall based on the user's latest message - LLM dispatch:
format_memory_context()injects cached memories into the system prompt as a "Relevant Memories" section - Tool errors:
remember_error()auto-stores concise error summaries as facts - Summarization: Summarized tool outputs can be stored in memory (not full content)
Output Parsing
parse_zk_list_output() handles three formats:
- JSON array (standard
zk list --format json) - Newline-delimited JSON (JSONL)
- Simple path-per-line fallback
parse_note_path() extracts the created note path from command output.
Context Correlation
Each ZkCommand carries a context_key matching a MemoryOperation variant (remember, recall, journal, related, today, init). The handle_memory_result() handler uses this to route results: recall/load_recent updates cached_memories, journal updates today_journal, remember is logged.
Relationship to Two-Library Split
Memory is a cowboy feature -- it's platform infrastructure, not bridge-specific. The memory directory and zk config are managed by the agent home-manager module in cowboy/home/.