4.5 KiB
Memory System Fixes Summary
This document summarizes the fixes implemented for GitHub issue #589.
Issues Fixed
1. CLI Namespace Flag Not Working
Problem: The --namespace option in CLI memory commands didn't work correctly (always stored in default namespace).
Root Cause: The namespace was being extracted from subArgs instead of the flags parameter passed by Commander.js.
Fix Implemented:
- Modified
memoryCommandfunction to extract namespace fromflagsparameter - Updated all subfunctions to accept and use the namespace parameter
- Fixed parameter extraction logic in
queryMemory,exportMemory, andclearMemory
Files Modified:
/src/cli/simple-commands/memory.js
Testing Results:
# Store in custom namespace - WORKING ✓
npx claude-flow memory store testkey1 "test value 1" --namespace custom-ns
# Query specific namespace - WORKING ✓
npx claude-flow memory query test --namespace custom-ns
# Export specific namespace - WORKING ✓
npx claude-flow memory export test.json --namespace custom-ns
# Clear specific namespace - WORKING ✓
npx claude-flow memory clear --namespace custom-ns
2. Database Fragmentation
Problem: Multiple .db files scattered across different directories causing fragmentation and inconsistent memory storage.
Identified Database Files:
./.swarm/memory.db(85MB)./.hive-mind/memory.db(24KB)./.hive-mind/hive.db(508KB)./.ruv-swarm/swarm.db(0KB)./data/hive-mind.db(148KB)- And several others in subdirectories
Solution Implemented:
-
Memory Consolidation Utility (
/src/cli/simple-commands/memory-consolidation.js):- Scans for all memory storage locations (JSON and SQLite)
- Creates automatic backups before consolidation
- Merges all stores into a unified SQLite database
- Optimizes with indices for better performance
- Maintains backward compatibility
-
Unified Memory Manager (
/src/memory/unified-memory-manager.js):- Single interface for all memory operations
- Automatic detection of unified vs legacy stores
- Seamless fallback to JSON if SQLite unavailable
- Support for import/export operations
-
New CLI Command (
memory-consolidate):# Scan for all memory stores npx claude-flow memory-consolidate scan # Create consolidation plan npx claude-flow memory-consolidate plan # Execute consolidation (requires sqlite3 package) npx claude-flow memory-consolidate execute --force # Generate report npx claude-flow memory-consolidate report
Benefits
- Namespace Support: Properly isolate memory by namespace for better organization
- Performance: SQLite with indices provides faster queries than JSON scanning
- Single Source of Truth: All memory data in one location
- Easier Backup: Single database file to backup/restore
- Reduced Fragmentation: No more scattered .db files
- Backward Compatibility: Falls back to JSON if SQLite unavailable
Migration Path
For users wanting to consolidate their fragmented databases:
-
Install SQLite dependencies (optional but recommended):
npm install sqlite3 sqlite -
Run consolidation:
npx claude-flow memory-consolidate scan npx claude-flow memory-consolidate plan npx claude-flow memory-consolidate execute --force -
The unified database will be created at:
./.claude-flow/memory/unified-memory.db
Technical Details
Unified Database Schema
CREATE TABLE memory_entries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key TEXT NOT NULL,
value TEXT NOT NULL,
namespace TEXT NOT NULL DEFAULT 'default',
timestamp INTEGER NOT NULL,
source TEXT,
UNIQUE(key, namespace)
);
-- Performance indices
CREATE INDEX idx_namespace ON memory_entries(namespace);
CREATE INDEX idx_timestamp ON memory_entries(timestamp);
CREATE INDEX idx_key ON memory_entries(key);
CREATE INDEX idx_key_value ON memory_entries(key, value);
CREATE INDEX idx_namespace_timestamp ON memory_entries(namespace, timestamp);
Compatibility
- The system automatically detects if a unified database exists
- Falls back to JSON storage if SQLite modules unavailable
- All existing memory commands work with both storage types
- Import/export functionality preserved
Future Improvements
- Automatic migration on first run after update
- Memory quota management per namespace
- Memory compression for large values
- Cross-project memory sharing capabilities
- Memory versioning and history tracking