feat: add persistent auto-memory system#3241
Conversation
Implement a file-based persistent memory system that allows the AI to retain knowledge about users, feedback, projects, and references across sessions. Memory files use YAML frontmatter with markdown body, stored at ~/.claw/projects/<workspace-hash>/memory/. Key components: - MemoryStore data layer with FNV-1a workspace fingerprinting - MemoryRead/MemoryWrite tools with security hardening (path traversal, symlink, absolute path, and size limit protections) - System prompt injection of MEMORY.md index with prompt injection mitigation (fenced code block + trust-lowering notice) - autoMemoryEnabled config option (defaults to true) - Doctor health check for auto-memory state - /memory command enhancement showing persistent memory info Tested end-to-end with Zhipu GLM-4-Flash via OpenAI-compatible routing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
This is a solid implementation. The FNV-1a workspace fingerprinting approach is clean and avoids complex state tracking. The security hardening is comprehensive -- blocking path traversal, symlinks, and absolute paths covers the main attack vectors, and the prompt injection mitigation with fenced code blocks is a pragmatic touch. One consideration: with the 200-line cap on MEMORY.md, how does the system handle index overflow? Does it use an LRU eviction strategy, or does it simply stop appending once the cap is reached? This matters if users accumulate significant project-specific memory over time. It may be worth exposing the cap as a configurable option (e.g., �utoMemoryIndexMaxLines) so repos with different needs can tune it. The per-workspace hash directory structure under ~/.claw/projects/ is a clean design choice -- isolates memories by project and avoids cross-contamination. |
|
Thanks for the careful review and the kind words on the security hardening! On the 200-line cap: it's a system-prompt budget (~30KB at ~150 chars/line), not a storage limit. The on-disk Curation is delegated to the model itself: the system prompt instructs it to keep entries terse (one line, <150 chars), organize semantically by topic, consolidate related entries, and remove stale ones. When overflow does occur, the rendered index includes a We deliberately avoid LRU or automatic eviction — mechanical eviction would silently rewrite a user-visible file the model curates, and access-time signals are a poor proxy for "still relevant" (that judgment is semantic, which the model handles better than any heuristic we'd encode). On making the cap configurable ( |
Summary
Add a file-based persistent memory system that allows the AI to retain knowledge across sessions. This implements the same auto-memory pattern used by Claude Code, adapted for Claw Code's Rust architecture.
autoMemoryEnabledoption (defaults totrue)auto-memoryhealth check reporting directory state/memorycommand: enhanced to show persistent memory info alongside instruction filesArchitecture
Memory types:
user,feedback,project,referenceSecurity
..components rejected)symlink_metadata()Testing
🤖 Generated with Claude Code