Memory Defrag π§ π§
Memory Defrag is your AI-powered note janitor. It scans your memory files, finds duplicates and related content, suggests consolidations, and helps reorganize your second brain.
Full Public Reader
---
name: memory-defrag
description: AI that reorganizes your notes, finds duplicates, suggests consolidation - keep your second brain clean
homepage: https://github.com/clawdbot
user-invocable: true
command-dispatch: defrag
metadata.clawdbot: {"version": "2.0.0", "hef_generation": 6}
---
Memory Defrag π§ π§
> _"A cluttered mind can't think clearly. Neither can cluttered notes."_
Memory Defrag is your AI-powered note janitor. It scans your memory files, finds duplicates and related content, suggests consolidations, and helps reorganize your second brain.
What's New in Gen 6
### π Reference Graph
- Detects `[[wiki-links]]`, `@mentions`, and file paths
- Maps connections between notes
- Identifies truly isolated content
### π Growth Trends
- Tracks memory growth over time
- Visualizes word count and health trends
- Helps identify documentation patterns
### π± Freshness Decay
- Exponential decay model for content freshness
- Highlights stale areas needing attention
- Smarter orphan detection
### π Safe Operations
- Automatic backups before any changes
- Easy restore from any backup
- Non-destructive archive system
### π N-gram Similarity
- Character n-gram matching for better duplicate detection
- Catches rephrased content that keyword matching misses
- Combined with keyword Jaccard for hybrid accuracy
What It Does
### π Duplicate Detection
- N-gram + keyword similarity (hybrid approach)
- Finds near-duplicates across files
- Groups related content that should be merged
### π Content Analysis
- Maps your knowledge topology
- Identifies orphaned notes (stale + no connections)
- Finds dense clusters (over-documented areas)
- Spots sparse zones (under-documented areas)
- Tracks content freshness with decay model
### π Reference Connectivity
- Detects `[[wiki-links]]` between notes
- Tracks `@mentions` and file references
- Shows connection graph statistics
### ποΈ Smart Suggestions
- Merge: Combine similar content
- Archive: Move stale content safely
- Split: Break up oversized files
- Link: Create topic indexes
Commands
| Command | Description |
|---|---|
| `/defrag scan` | Full scan of memory files |
| `/defrag scan <path>` | Scan specific file/directory |
| `/defrag duplicates` | Show duplicate/similar content |
| `/defrag clusters` | Show content clusters |
| `/defrag orphans` | Find stale disconnected notes |
| `/defrag refs` | Show reference connectivity |
| `/defrag suggest` | Get consolidation suggestions |
| `/defrag apply <id>` | Apply a suggestion (with backup) |
| `/defrag preview <id>` | Preview what a suggestion would do |
| `/defrag status` | Show scan status and stats |
| `/defrag health` | Overall memory health report |
| `/defrag trends` | Show growth over time |
| `/defrag archive` | Show archive candidates |
| `/defrag backups` | List available backups |
| `/defrag restore <id>` | Restore from backup |
Quick Start
User: /defrag scan
Memory Defrag π§ π§ Scan Complete
π Stats:
β’ Files scanned: 12
β’ Sections analyzed: 847
β’ Total words: 42,350
β’ Duplicates found: 23
β’ Clusters detected: 8
β’ Orphans found: 15
π’ Health Score: 78/100
π± Avg Freshness: 72%
π‘ Next Steps:
β’ /defrag duplicates β see duplicate content
β’ /defrag suggest β get consolidation ideasExample Workflow
1. Health Check
User: /defrag health
π₯ Memory Health Report
π’ Overall Score: 78/100
π Stats:
β’ 847 sections analyzed
β’ 42,350 total words
β’ 23 duplicate groups
β’ 8 topic clusters
β’ 12 pending suggestions
π± Freshness: 72%
π Connectivity: 234/847 sections linked (28%)
β οΈ Issues:
π‘ 23 duplicate sections found
π‘ 15 orphaned notes detected2. Find Duplicates
User: /defrag duplicates
π Duplicate Content Found
Group 1: π (87% similar)
β’ 2025-01-29.md:234-267 β HEF Evolution Tasks
β’ 2025-01-30.md:89-120 β HEF Evolution Log
β’ 2025-01-31.md:45-78 β Today's HEF Work
β Suggested: merge to memory/hef-evolution.md
Group 2: π (92% similar)
β’ 2025-01-28.md:156-198 β N'Ko Vocabulary Notes
β’ 2025-01-31.md:892-934 β N'Ko Words Learned
β Suggested: merge to memory/nko-vocabulary.md
π‘ Use /defrag suggest for actionable suggestions3. Preview & Apply
User: /defrag preview sug_merge_dup_1
ποΈ Preview: sug_merge_dup_1
Type: merge
Description: Merge 3 similar sections about 'HEF Evolution'
Target: memory/hef-evolution.md
Would affect:
β’ 2025-01-29.md β HEF Evolution Tasks
β’ 2025-01-30.md β HEF Evolution Log
β’ 2025-01-31.md β Today's HEF Work
Preview:
# Merged: HEF Evolution
## From 2025-01-29.md
### HEF Evolution Tasks
[content would be merged here]
...
π‘ Use /defrag apply sug_merge_dup_1 to execute
User: /defrag apply sug_merge_dup_1
β
Suggestion Applied
Created merged file: memory/hef-evolution.md
π Backup created: 20250131_143022
π Original sections preserved. Remove from source files manually after review.
Use /defrag restore 20250131_143022 to undo if needed.4. Track Trends
User: /defrag trends
π Memory Growth Trends
01-25 [ββββββββββ] 38,200w π’
01-26 [ββββββββββ] 39,100w π’
01-27 [ββββββββββ] 40,500w π’
01-28 [ββββββββββ] 41,200w π‘
01-29 [ββββββββββ] 42,350w π’
01-30 [ββββββββββ] 42,800w π’
01-31 [ββββββββββ] 43,100w π’
π Change over 7 days:
β’ Words: +4,900
β’ Sections: +425. Check References
User: /defrag refs
π Reference Connectivity
Most Connected:
β’ MEMORY.md β Main Index (12 refs)
β’ projects.md β Active Projects (8 refs)
β’ goals.md β 2025 Goals (6 refs)
β οΈ 613 unconnected sections
Consider adding links to integrate these into your knowledge graph.
π Overall: 234/847 sections connected (28%)Configuration
Create `[home-path]`:
{
"scan_paths": [
"[home-path]
"[home-path]
],
"similarity_threshold": 0.70,
"orphan_days": 30,
"max_file_kb": 50,
"freshness_half_life_days": 30,
"ngram_size": 3
}Similarity Detection
Uses hybrid approach:
- N-grams (70
- Keywords (30
| Similarity | Classification |
|---|---|
| > 95 | |
| 85-95 | |
| 70-85 | |
| < 70 |
Freshness Model
Content freshness decays exponentially:
- Half-life: 30 days (configurable)
- Fresh (>70
- Aging (40-70
- Stale (<40
Backup System
All destructive operations create automatic backups:
- Stored in `[home-path]`
- Named with timestamp: `YYYYMMDD_HHMMSS`
- Easy restore: `/defrag restore <backup_id>`
Integration
### With Dream Weaver
- Scans dream journals for duplicates
- Suggests merging related dreams
- Identifies stale dreams for composting
### With MEMORY.md
- Monitors growth trends
- Suggests archiving old entries
- Recommends topic-based splits
### With Daily Memory
- Detects repeated patterns
- Suggests templates
- Identifies routine vs. unique events
Files
| File | Description |
|---|---|
| `defrag.py` | Core defrag engine (Gen 6) |
| `handler.py` | Command handler |
| `[home-path]` | Scan state |
| `[home-path]` | Pending suggestions |
| `[home-path]` | Growth trends |
| `[home-path]` | Backup storage |
Philosophy
> Your second brain should be as organized as you want your first brain to be.
>
> But organization isn't about perfectionβit's about findability.
> Memory Defrag doesn't impose structure; it reveals the structure that's already there,
> and suggests improvements that match how you actually think.
---
_Version 2.0.0 β HEF Generation 6_ π§ π§
Promotion Decision
Attach run IDs, datasets, metrics, and reproduction commands.
Source Anchor
homelab/clawdbot/skills/memory-defrag/SKILL.md
Detected Structure
Evaluation Β· References Β· Code Anchors