Memory Defrag
Reorganize memory files for clarity, efficiency, and relevance. Like filesystem defragmentation but for knowledge.
When to Run
- - Periodic: Weekly or biweekly via cron (recommended)
- On demand: User asks to clean up, reorganize, or defrag memory
- Threshold: When MEMORY.md exceeds ~500 lines or daily notes accumulate without consolidation
Process
1. Audit Current State
Inventory all memory files:
CODEBLOCK0
For each file, note: line count, last modified, topic coverage, staleness.
2. Identify Problems
Look for these common issues:
| Problem | Signal | Fix |
|---|
| Bloated file | >300 lines, covers many topics | Split into focused files |
| Duplicate info |
Same fact in multiple places | Consolidate to one location |
|
Stale entries | References to completed work, old dates, resolved issues | Remove or archive |
|
Orphan files | Files in memory/ never referenced or updated | Review, merge, or remove |
|
Inconsistencies | Contradictory information across files | Resolve to ground truth |
|
Poor organization | Related info scattered across files | Restructure by topic |
|
Recursive nesting |
memory/memory/memory/... directories | Delete nested dirs (indexer bug artifact) |
3. Plan Changes
Before making edits, write a brief plan:
CODEBLOCK1
4. Execute
Apply changes one at a time:
- - Split: Extract sections from large files into focused topical files
- Merge: Combine related small files into coherent documents
- Prune: Remove information that is no longer relevant or accurate
- Restructure: Move files to appropriate directories, rename for clarity
- Update: Fix outdated facts, dates, statuses
5. Verify & Log
After changes:
- - Verify no information was lost (compare before/after)
- Update any cross-references between files
- Log what was done in today's daily note:
CODEBLOCK2
Guidelines
- - Preserve raw daily notes. Don't delete or modify
memory/YYYY-MM-DD.md files — they're the audit trail. - Target 15-25 focused files. Too few means bloated files; too many means fragmentation. Aim for the sweet spot.
- File names should be scannable. Use descriptive names:
people.md, project-status.md, competitive-landscape.md — not notes-2.md. - Don't over-organize. One level of directories is usually enough.
memory/tasks/ and memory/competitive/ are fine; memory/work/projects/active/basic-memory/notes/ is not. - Completed tasks: Tasks with
status: done older than 14 days can be removed. Their insights should already be in MEMORY.md via reflection. - Ask before destructive changes. If uncertain whether information is still relevant, keep it with a
(review needed) tag rather than deleting.
内存碎片整理
重新组织内存文件,使其更清晰、高效且相关。类似于文件系统碎片整理,但针对的是知识。
何时运行
- - 定期:通过cron每周或每两周运行(推荐)
- 按需:用户要求清理、重组或整理内存时
- 阈值:当MEMORY.md超过约500行,或日常笔记积累但未整合时
流程
1. 审计当前状态
盘点所有内存文件:
MEMORY.md — 长期记忆
memory/ — 日常笔记、任务、专题文件
memory/tasks/ — 进行中和已完成的任务
对每个文件,记录:行数、最后修改时间、主题覆盖范围、陈旧程度。
2. 识别问题
查找这些常见问题:
| 问题 | 信号 | 修复 |
|---|
| 文件臃肿 | >300行,涵盖多个主题 | 拆分为聚焦的文件 |
| 重复信息 |
同一事实出现在多个位置 | 整合到一个位置 |
|
陈旧条目 | 引用已完成的工作、旧日期、已解决的问题 | 删除或归档 |
|
孤立文件 | memory/中从未被引用或更新的文件 | 审查、合并或删除 |
|
不一致 | 文件间信息矛盾 | 解决为基准事实 |
|
组织混乱 | 相关信息分散在多个文件中 | 按主题重组 |
|
递归嵌套 | memory/memory/memory/... 目录 | 删除嵌套目录(索引器错误产物) |
3. 规划变更
在进行编辑前,编写简要计划:
markdown
碎片整理计划
- - [ ] 将MEMORY.md的关键人物部分拆分 → memory/people.md
- [ ] 从memory/tasks/中删除超过30天的已完成任务
- [ ] 将memory/bm-marketing-ideas.md合并到memory/competitive/
- [ ] 更新MEMORY.md中过时的项目状态条目
4. 执行
一次应用一个变更:
- - 拆分:从大文件中提取章节到聚焦的专题文件
- 合并:将相关的小文件合并为连贯的文档
- 修剪:删除不再相关或准确的信息
- 重组:将文件移动到适当的目录,重命名以清晰化
- 更新:修正过时的事实、日期、状态
5. 验证与记录
变更后:
- - 验证没有信息丢失(对比变更前后)
- 更新文件间的交叉引用
- 在今天的日常笔记中记录所做的工作:
markdown
内存碎片整理 (HH:MM)
- - 审查的文件数:N
- 拆分:[列表]
- 合并:[列表]
- 修剪:[列表]
- 净结果:X个文件,Y总行数(原为Z行)
指南
- - 保留原始日常笔记。 不要删除或修改memory/YYYY-MM-DD.md文件——它们是审计轨迹。
- 目标为15-25个聚焦文件。 太少意味着文件臃肿;太多意味着碎片化。力求最佳平衡点。
- 文件名应易于扫描。 使用描述性名称:people.md、project-status.md、competitive-landscape.md——而不是notes-2.md。
- 不要过度组织。 一层目录通常就足够了。memory/tasks/和memory/competitive/没问题;memory/work/projects/active/basic-memory/notes/则不行。
- 已完成的任务:status: done超过14天的任务可以删除。它们的见解应已通过反思纳入MEMORY.md。
- 破坏性变更前先询问。 如果不确定信息是否仍然相关,保留并添加(待审查)标签,而不是直接删除。