Structured memory system for OpenClaw with 4-type classification and automated migration.
memory/*.md to organized categoriesclawhub install claude-memory-optimizer
# Auto-detect workspace
node ~/.openclaw/skills/claude-memory-optimizer/scripts/refactor-memory.js
# Or specify explicitly
node ~/.openclaw/skills/claude-memory-optimizer/scripts/refactor-memory.js ~/.openclaw/workspace
ls -la ~/.openclaw/workspace/memory/
cat ~/.openclaw/workspace/MEMORY.md
| Type | Purpose | Example |
|---|---|---|
| ------ | --------- | --------- |
| user | User role, preferences, skills | "Data scientist, prefers concise replies" |
| feedback | Behavior corrections/confirmations | "No trailing summaries — user can read diffs" |
| project | Project context, decisions, deadlines | "Thesis deadline: 2026-06-01" |
| reference | External system pointers | "Kaggle: https://kaggle.com/chenziong" |
memory/
├── user/ # User information
├── feedback/ # Behavior guidance
├── project/ # Project context
├── reference/ # External references
└── logs/ # Append-only logs (optional)
└── YYYY/
└── MM/
└── YYYY-MM-DD.md
Each memory file uses frontmatter metadata:
---
name: Data Science Background
description: User is a data scientist focused on observability and LLMs
type: user
---
User studies at Beijing University of Technology & UCD, GPA 3.95/4.2.
Research: LLM, AI Agents, MCP.
**Skills:** Python, PyTorch, Transformers, NLP
**How to apply:** Use data science terminology, assume ML background.
git log){
"agents": {
"defaults": {
"memorySearch": {
"enabled": true,
"provider": "local",
"maxResults": 20,
"minScore": 0.3
},
"compaction": {
"memoryFlush": {
"enabled": true,
"softThresholdTokens": 4000
}
}
}
}
}
User: "Remember, I prefer concise replies without trailing summaries."
AI: Saves to memory/feedback/reply-style.md:
---
name: Reply Style Preference
description: User wants concise replies, no trailing summaries
type: feedback
---
**Rule:** Keep replies concise, no trailing summaries.
**Why:** User said "I can read the diff myself."
**How to apply:** End responses directly after completing work.
User: "What did I say about database testing?"
AI: Runs memory_search query="database testing" → returns memory/feedback/db-testing.md
User: "Is the experiment design in memory/project/dong-thesis.md still current?"
AI: Runs grep to verify → detects outdated info → updates memory file.
memory/
├── 2026-03-21.md
├── 2026-03-28.md
├── research-memory.md
└── video-memory.md
memory/
├── project/
│ ├── 2026-03-21-.md
│ ├── 2026-03-28-.md
│ └── research-memory.md
├── reference/
│ └── video-memory.md
└── logs/2026/04/2026-04-02.md
async function findRelevantMemories(query: string, memoryDir: string) {
const memories = await scanMemoryFiles(memoryDir);
const selected = await selectRelevantMemories(query, memories);
return selected.slice(0, 5); // Top 5 relevant memories
}
Before recommending from memory:
ls to verify existencegrep to confirm> "Memory says X exists" ≠ "X exists now"
memory/YYYY-MM-DD.mdMEMORY.md.learnings/ recordsMEMORY.md exists in workspace rootagents.defaults.memorySearch.enabled = truedescription in frontmatterminScore (lower = broader matches)memory/ directory first--dry-run (if available)src/memdir/ (memdir.ts, memoryTypes.ts, findRelevantMemories.ts)docs/concepts/memory.mdmemory-setup-openclaw, elite-longterm-memoryMIT-0
MIT-0
共 1 个版本