- Reorganize v3/ into implementation/ subfolders: - planning/, architecture/, migration/, integration/ - security/, adrs/, research/, swarm-plans/ - Add 15-agent concurrent swarm implementation plans: - SWARM-OVERVIEW.md: Hierarchical mesh topology, 4 phases - AGENT-SPECIFICATIONS.md: 15 agent configs with capabilities - TDD-LONDON-SCHOOL-PLAN.md: Mock-first TDD methodology - BENCHMARK-OPTIMIZATION.md: Performance targets (2.49x-7.47x) - DEPLOYMENT-PLAN.md: Release strategy, CI/CD, rollback - GITHUB-ISSUE-TRACKING.md: Issue workflow with agent replies - Update .claude/settings.json with proper hooks format - Add bash aliases for claude --dangerously-skip-permissions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
6.5 KiB
Fix Verification: Memory Stats Command
Issue
GitHub Issue #865: memory stats command returns zero for ReasoningBank data
Fix Summary
Successfully fixed the memory stats command to properly detect and display ReasoningBank SQLite data alongside JSON storage statistics.
Changes Made
File: src/cli/simple-commands/memory.js
-
Modified
showMemoryStats()function (lines 221-315):- Added
modeparameter to detect active storage backend - Implemented unified statistics display showing both JSON and ReasoningBank data
- Added file size calculation for ReasoningBank database
- Provides helpful tips for users to switch between modes
- Added
-
Updated
statscase in switch statement (lines 66-70):- Changed from directly calling
showMemoryStats(loadMemory) - Now passes
modeparameter:showMemoryStats(loadMemory, mode) - Ensures proper mode detection for unified output
- Changed from directly calling
-
Added comment in mode delegation (line 52):
- Clarifies that
statscommand is handled in switch statement for unified output - Prevents early routing to
handleReasoningBankCommand
- Clarifies that
Test Results
Test 1: Auto Mode (Unified Statistics) ✅
Command: memory stats (default, no flags)
Output:
✅ Memory Bank Statistics:
📁 JSON Storage (./memory/memory-store.json):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
Namespace Breakdown:
default: 1 entries
🧠 ReasoningBank Storage (.swarm/memory.db):
Total Memories: 19
Categories: 2
Average Confidence: 80.0%
Embeddings: 19
Trajectories: 0
Database Size: 9.58 MB
💡 Active Mode: ReasoningBank (auto-selected)
Use --basic flag to force JSON-only statistics
Result: ✅ PASS - Shows both storage backends with complete statistics
Test 2: Basic Mode (JSON Only) ✅
Command: memory stats --basic
Output:
✅ Memory Bank Statistics (JSON Mode):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
📁 Namespace Breakdown:
default: 1 entries
💡 Tip: Initialize ReasoningBank for AI-powered memory
Run: memory init --reasoningbank
Result: ✅ PASS - Shows only JSON storage with helpful tip
Test 3: ReasoningBank Mode (Explicit) ✅
Command: memory stats --reasoningbank
Output:
✅ Memory Bank Statistics:
📁 JSON Storage (./memory/memory-store.json):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
Namespace Breakdown:
default: 1 entries
🧠 ReasoningBank Storage (.swarm/memory.db):
Total Memories: 19
Categories: 2
Average Confidence: 80.0%
Embeddings: 19
Trajectories: 0
Database Size: 9.58 MB
💡 Active Mode: ReasoningBank (auto-selected)
Use --basic flag to force JSON-only statistics
Result: ✅ PASS - Shows unified statistics (same as auto mode)
Test 4: Database Verification ✅
Direct SQL Query:
$ sqlite3 .swarm/memory.db "SELECT COUNT(*) FROM patterns WHERE type = 'reasoning_memory';"
19
ReasoningBank List:
$ memory list --reasoningbank
✅ ReasoningBank memories (10 shown):
📌 test-key
📌 test-sqlite
📌 api-design
[... 16 more entries]
Result: ✅ PASS - Statistics match actual database content
Before vs After
Before Fix ❌
$ memory stats
✅ Memory Bank Statistics:
Total Entries: 0 # ❌ Wrong - ReasoningBank has 19 entries
Namespaces: 0 # ❌ Wrong - ReasoningBank has 2 categories
Size: 0.00 KB # ❌ Wrong - Database is 9.58 MB
After Fix ✅
$ memory stats
✅ Memory Bank Statistics:
📁 JSON Storage (./memory/memory-store.json):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
🧠 ReasoningBank Storage (.swarm/memory.db):
Total Memories: 19 # ✅ Correct
Categories: 2 # ✅ Correct
Database Size: 9.58 MB # ✅ Correct
Implementation Details
Mode Detection Logic
async function showMemoryStats(loadMemory, mode) {
const rbInitialized = await isReasoningBankInitialized();
// Auto mode: show unified stats if ReasoningBank exists
if (mode === 'reasoningbank' || (rbInitialized && mode !== 'basic')) {
// Show both JSON and ReasoningBank statistics
// ... unified output ...
} else {
// Basic mode: JSON only
// ... JSON-only output ...
}
}
Key Features
- Automatic Detection: Checks if
.swarm/memory.dbexists - Unified Display: Shows both storage backends when ReasoningBank is initialized
- Mode Overrides: Supports
--basicand--reasoningbankflags - File Size Calculation: Uses
fs.stat()to get accurate database size - Helpful Tips: Guides users to enable ReasoningBank if not initialized
- Error Handling: Gracefully handles missing files or database errors
Backward Compatibility
✅ No Breaking Changes
- Existing
memory statsbehavior preserved for JSON-only mode - New unified output only shown when ReasoningBank is initialized
- All flags (
--basic,--reasoningbank,--auto) work correctly - JSON storage continues to work independently
Performance Impact
- Negligible: Only adds one file stat check for database size
- Efficient: Uses existing
getStatus()function from ReasoningBank adapter - Cached: ReasoningBank initialization is cached after first call
Related Commands
All memory commands now properly support both backends:
| Command | JSON Mode | ReasoningBank Mode | Unified Output |
|---|---|---|---|
store |
✅ | ✅ | N/A |
query |
✅ | ✅ | N/A |
list |
✅ | ✅ | N/A |
stats |
✅ | ✅ | ✅ (NEW) |
status |
N/A | ✅ | N/A |
Future Enhancements
Potential improvements for future versions:
- Export/Import: Support exporting unified statistics to file
- Diff Mode: Show differences between JSON and ReasoningBank storage
- Migration Stats: Show progress when migrating between backends
- Historical Trends: Track statistics over time
- Memory Usage Graphs: Visual representation of storage growth
Conclusion
The fix successfully resolves the bug where memory stats returned zeros for ReasoningBank data. The command now provides comprehensive statistics for both storage backends with intelligent mode detection and helpful user guidance.
Status: ✅ VERIFIED AND WORKING
Files Modified:
src/cli/simple-commands/memory.js(3 changes, ~100 lines added)
Tests Passed: 4/4 ✅
Build Status: ✅ Successful (warnings are expected from pkg binary compilation)
Ready for: v2.7.32 release