Skip to content

Conversation

@samestrin
Copy link
Owner

Summary

Implements llm-semantic memory stats CLI subcommand for retrieving statistics and managing memory entries, with full MCP tool parity.

Key Deliverables

  • Stats Table Mode: Default output showing memory ID, question, creation date, retrieval count, and last accessed time
  • Filter Options: Filter by specific --id or minimum --min-retrievals threshold
  • History Mode: --history displays detailed retrieval timeline for a specific memory entry
  • Prune Mode: --prune --older-than <days> removes retrieval logs older than specified days
  • Output Formats: Full JSON (--json) and minimal JSON (--min) for automation
  • MCP Tool: llm_semantic_memory_stats provides full feature parity via MCP protocol

Security Fixes

  • Negative --min-retrievals validation prevented
  • --older-than upper-bounded at 36,500 days (100 years)
  • JSON indentation removed for --min output
  • Error type preservation with %w verb for proper error unwrapping

Test Plan

  • All tests pass (go test ./internal/semantic/...)
  • Code compiles (go build ./cmd/llm-semantic)
  • MCP server exposes llm_semantic_memory_stats tool
  • CLI command responds to all mode combinations
  • Input validation for negative and extreme values

Implemented the memory stats CLI subcommand with table output display.
- Added memoryStatsCmd() function with all required flags
- Registered stats subcommand to memoryCmd()
- Implemented runMemoryStats() with mode routing
- Implemented runMemoryStatsTable() for default stats display
- Implemented runMemoryHistory() for retrieval history display
- Implemented runMemoryPrune() for log pruning
- Added formatDisplayDate() helper for date formatting
- Added truncateRuneAware() for UTF-8 safe text truncation
- Fixed adversarial findings: UTF-8 truncation, stdin error handling, older-than cap

Tests: Added TestMemoryStatsCmd_HasRequiredFlags, TestMemoryStatsCmd_RegisteredAsSubcommand,
       TestMemoryStatsCmd_Flags, TestTruncateRuneAware with UTF-8 support
Add --json and --min flags to memory stats subcommand with output for:
- runMemoryStatsTable: Full/min JSON with abbreviated keys
- runMemoryHistory: Full/min JSON with memory details and history
- runMemoryPrune: Full/min JSON with deletion count

TDD: GREEN + ADVERSARIAL (1 LOW severity issue logged)
Fixes:
- LOW: Remove JSON indent for --min output (compact JSON now actual min)
- LOW: Preserve error type when wrapping memory not found error (%w)

Deferred:
- LOW: N+1 query pattern in GetAllMemoryStats (requires schema/interface changes)
- Add llm_semantic_memory_stats MCP tool wrapper
- Fix code review findings (min-retrievals validation, JSON indent, error wrapping)
- Update code review report with all fixes verified
@samestrin samestrin merged commit 1885f08 into main Jan 18, 2026
8 checks passed
@samestrin samestrin deleted the feature/8.15_memory_stats branch January 18, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant