| name | memory-skills-cleanup |
| description | 全面清理 Hermes 记忆层 + skills 目录 + 路由引用。 当用户说"记忆太臃肿"、"清理记忆"、"优化记忆"、"skills太多"、"磁盘满了"时触发。
|
| tags | ["memory","skills","cleanup","optimization","routing"] |
触发条件
- 用户说记忆臃肿/太胖/需要减肥
- 用户说 skills 太多/磁盘满/清理
- MEMORY.md 或 user profile 接近容量上限
- skills 目录 >20M
四层清理流程
1. MEMORY.md(系统记忆)
路径:~/.hermes/memories/MEMORY.md
规则:
- 只保留跨项目稳定技术事实(如 Hermes 403 UA fix)
- 删除所有项目细节(ict-engine、arXiv paper ID 等)→ 属 repo docs / session_search
- 删除已过时的工作记录
- 文言压缩,每条 ≤30 字
2. User Profile(用户偏好)
路径:memory(target='user')
规则:
- 合并 10+ 散装条目为 1 条架构链
- 格式:树状依赖(
元→├─链→└─链),非扁平列表
- 只存硬规则(红线、偏好、禁止项)
- 删除已变质的条目(如旧 cron 架构描述)
- 文言压缩
架构链模板:
元:[核心行为规则]
├─红线:[不可做]
├─重试:[失败策略]
├─[领域A]链:[约束→执行→验证]
└─[领域B]链:[约束→执行→验证]
3. Skills 目录
路径:~/.hermes/skills/
清理步骤:
du -sh ~/.hermes/skills/* | sort -rh | head -20
for d in ~/.hermes/skills/*/; do
count=$(find "$d" -name "SKILL.md" | wc -l)
size=$(du -sh "$d" | cut -f1)
echo "$count skills, $size: $(basename $d)"
done | sort -t, -k1 -rn
rm -rf ~/.hermes/skills/CATEGORY/UNWANTED_PACK
du -sh ~/.hermes/skills/
find ~/.hermes/skills -name "SKILL.md" | wc -l
4. 路由引用清理
删除 skills 后必须清理引用,否则路由指向不存在的 skill。
文件:
~/.hermes/hermes-agent/routing/skill-router.md — 删除对应行
~/.hermes/hermes-agent/routing/skill-index.md — 删除对应 section + table rows
~/.hermes/hermes-agent/routing/skill-index.json — 删除对应 entries
方法:
import json
data = json.load(open('skill-index.json'))
data = [s for s in data if s.get('category') not in deleted_cats
and s.get('name') not in deleted_skills]
json.dump(data, open('skill-index.json', 'w'), indent=2)
验证:
grep -c "DELETED_SKILL_NAME" skill-router.md skill-index.md
Pitfalls
- skill-index.json 是数组不是 dict:顶层直接是
[{skill}, ...],不是 {"skills": [...]}
- sed 对多行 section 不可靠:清理 skill-index.md 用 Python regex 而非 sed
- 删 skills 前先查路由引用:确认哪些需要同步清理
- MEMORY.md 和 user profile 是独立系统:MEMORY.md 用 write_file,user profile 用 memory() tool
- 不要删用户手动创建的 skills:只删 auto-installed / cloned repos
- 路由文件在 hermes-agent repo 里:
~/.hermes/hermes-agent/routing/,不是 ~/.hermes/routing/