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 ( |
|
The two-tier index/entry architecture is well thought out. Keeping the cap as a system-prompt budget rather than a storage limit makes sense — the truncated marker gives the model visibility into what it can't see, and the individual entry files ensure nothing is lost. The model-delegated curation (consolidation, staleness removal) is the right approach for this scale. One small thought: consider adding a periodic auto-prune hook that removes entries whose frontmatter timestamp exceeds a configurable TTL, as a complement to the model-driven curation. This would prevent unbounded disk growth in long-lived workspaces. |
|
Good point! I agree TTL-based pruning could be useful as a complementary maintenance mechanism, but I’d prefer not to couple it to this PR since it introduces policy questions around what should be deleted automatically. I’ll open a follow-up issue to track pruning/retention options. |
|
Makes sense to track pruning as a follow-up issue rather than scope-creeping this PR. The current implementation is clean and self-contained — the two-tier architecture with model-delegated curation is the right foundation. Curious to see how the project-hash directory structure works out in practice across workspaces. |
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