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

OperationMethodDescription
initZkMemory::init()Create directory structure, initialize zk
rememberZkMemory::remember(title, content, template)Create a fact or decision note
recallZkMemory::recall(query)Full-text search via zk list --match
journalZkMemory::journal(entry)Append timestamped entry to today's daily note
todayZkMemory::today()Get or create today's daily note
by_tagZkMemory::by_tag(tag)Search notes by tag
recentZkMemory::recent(limit)List recent notes sorted by modification time
get_relatedZkMemory::get_related(path)Find notes linked to a given note
linkZkMemory::link(from, to, text)Create a wiki-link between notes

Session Lifecycle

  1. Startup: init_memory() creates the zk directory structure
  2. Session init: load_initial_memories() loads recent facts (last 10)
  3. Per-turn: recall_for_query() runs async recall based on the user's latest message
  4. LLM dispatch: format_memory_context() injects cached memories into the system prompt as a "Relevant Memories" section
  5. Tool errors: remember_error() auto-stores concise error summaries as facts
  6. 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/.