Defragmenting memory

From edmundmiller/dotfiles · View interactive version

Defragmenting memory is an AI agent skill from the GitHub repository edmundmiller/dotfiles. Decomposes and reorganizes agent memory files into focused, single-purpose components. Use when memory has large multi-topic blocks, redundancy, or poor organization. Trigger phrases: "defrag memory", "reorganize memory", "clean up memory files", "split memory blocks".

How to use this skill

Skill file

Memory Defragmentation

Requires context-repo extension with memory at .pi/memory/

Splits large, multi-purpose memory blocks into focused single-purpose files

with hierarchical / naming.

When to Use

Workflow

Step 1: Backup (MANDATORY)

Use the memory_backup tool before proceeding. This is your safety net.

Step 2: Analyze Current Memory

find .pi/memory -name '*.md' | while read f; do
  echo "=== $f ($(wc -l < "$f") lines) ==="
  head -5 "$f"
  echo
done

For each file, determine:

Step 3: Decompose

Split multi-purpose blocks into focused files using hierarchical naming:

Before:

system/project.md  (80 lines mixing overview, tooling, conventions, gotchas)

After:

system/project/overview.md
system/project/tooling.md
system/project/conventions.md
system/project/gotchas.md

Use memory_write for each new file, then delete the original:

rm .pi/memory/system/project.md

Step 4: Clean Up

For each file (new and existing):

Step 5: Commit

memory_commit({ message: "refactor: defragment memory — split N files into M focused blocks" })

Step 6: Report

Provide a summary:

Evaluation Criteria

  1. DECOMPOSITION — Each file has ONE clear purpose described by its filename
  2. STRUCTURE — Headers, bullets, scannable at a glance
  3. CONCISENESS — No redundancy, no speculation, only unique value
  4. CLARITY — Contradictions resolved, plain language, actionable
  5. ORGANIZATION — General to specific within files, important first

Naming Rules

What to Preserve

Rollback

If something goes wrong:

/memory-backups     # list available backups
/memory-restore <backup-name>
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.