Skip to content

[FEATURE] Implement neurolink memory CLI subcommand for conversation memory management #754

Description

@murdore

Problem Statement

Is your feature request related to a problem? Please describe.

The documentation at docs/features/conversation-history.md describes CLI commands for managing conversation memory (list, export, delete sessions), but these commands do not actually exist in the CLI implementation. Users reading the documentation expect to use commands like neurolink memory list or neurolink memory export --session-id <ID>, but receive "command not found" errors.

This creates a documentation-implementation gap and prevents users from managing their conversation sessions via the CLI.

Proposed Solution

Describe the solution you'd like

Implement a memory subcommand in the NeuroLink CLI with the following commands:

Commands to Implement

Command Description
neurolink memory list List all conversation sessions with metadata
neurolink memory export --session-id <ID> Export a specific session to JSON/CSV
neurolink memory export-all Export all sessions to a directory
neurolink memory delete --session-id <ID> Delete a specific session
neurolink memory clear Clear all sessions (with confirmation)

API Design

# List all sessions for current user
neurolink memory list
# Output format:
# session-123 | "Machine Learning Discussion" | 15 messages | last active: 2024-01-01
# session-456 | "API Design Review"          |  8 messages | last active: 2024-01-02

# List with JSON output
neurolink memory list --format json

# Export single session to JSON
neurolink memory export --session-id session-123 --format json > history.json

# Export with full metadata
neurolink memory export --session-id session-123 --include-metadata

# Export to CSV format
neurolink memory export --session-id session-123 --format csv > history.csv

# Export all sessions to directory
neurolink memory export-all --output ./exports/

# Delete specific session
neurolink memory delete --session-id session-123

# Delete with force (skip confirmation)
neurolink memory delete --session-id session-123 --force

# Clear all sessions
neurolink memory clear --confirm

# Get memory stats
neurolink memory stats

Expected Inputs and Outputs

Input Options:

  • --session-id <string>: Session identifier (required for export/delete)
  • --format <json|csv>: Output format (default: json)
  • --include-metadata: Include session metadata in export
  • --output <path>: Output directory for export-all
  • --confirm: Skip confirmation prompt for destructive operations
  • --force: Force operation without prompts
  • --user-id <string>: User ID for multi-user scenarios (optional)

Output:

  • Formatted table output for list command
  • JSON/CSV file output for export commands
  • Confirmation messages for delete/clear operations

Example Usage

Describe how you would use this feature

// This is CLI usage, not SDK - showing the file structure needed

// src/cli/commands/memory.ts - New file to create
import { CommandModule } from "yargs";
import { createMemoryCommands } from "../factories/memoryCommandFactory.js";

export const memoryCommand: CommandModule = {
  command: "memory <subcommand>",
  describe: "Manage conversation memory and session history",
  builder: (yargs) => createMemoryCommands(yargs),
  handler: () => {},
};
# CLI usage examples

# Developer workflow: Debug a problematic conversation
neurolink memory list --format json | jq '.[] | select(.title | contains("error"))'
neurolink memory export --session-id session-problematic --include-metadata > debug.json

# Operations workflow: Clean up old sessions
neurolink memory list
neurolink memory delete --session-id old-session-1 --force
neurolink memory delete --session-id old-session-2 --force

# Analytics workflow: Export all for analysis
neurolink memory export-all --output ./weekly-export/ --format csv

Alternatives Considered

Describe alternatives you've considered

  1. Direct Redis CLI access: Users could use redis-cli to query session data directly

    • Why insufficient: Requires Redis knowledge, doesn't handle serialization/deserialization, no user-friendly formatting
  2. SDK-only API: Keep memory management as SDK-only feature

    • Why insufficient: CLI users expect parity with documented features, CLI is often used for debugging/operations
  3. Loop mode commands: Add memory commands as loop-mode internal commands (/memory list)

    • Why insufficient: Users expect these to work as standalone CLI commands matching documentation

Use Case

What is your use case?

  • Industry: Enterprise AI development (all industries using NeuroLink)
  • Application type: Developer tooling, DevOps, debugging, compliance auditing
  • Scale: Production - teams managing multiple conversation sessions

Specific scenarios:

  1. Debugging: Developer needs to export a conversation to understand why AI gave unexpected response
  2. Compliance: Team needs to export all conversations for audit trail
  3. Operations: Ops engineer needs to clean up stale sessions to manage Redis storage
  4. Analytics: Data team needs to export conversations for quality analysis

Impact

Who would benefit from this feature?

  • Individual developers
  • Small teams
  • Enterprise users
  • All users

Additional Context

Current State

The SDK already has the underlying implementation in RedisConversationMemoryManager:

// Existing methods in src/lib/core/redisConversationMemoryManager.ts
getUserSessions(userId: string): Promise<string[]>
getUserSessionMetadata(userId: string, sessionId: string): Promise<SessionMetadata | null>
getUserSessionHistory(userId: string, sessionId: string): Promise<ChatMessage[] | null>
getUserSessionObject(userId: string, sessionId: string): Promise<RedisConversationObject | null>
getUserAllSessionsHistory(userId: string): Promise<SessionMetadata[]>
clearSession(sessionId: string, userId?: string): Promise<boolean>
clearAllSessions(): Promise<void>
getStats(): Promise<ConversationMemoryStats>

Documentation Reference

The following documentation already describes these CLI commands:

  • docs/features/conversation-history.md - Lines 76-80, 266-269

Related Files

File Purpose
src/lib/core/redisConversationMemoryManager.ts Existing Redis memory manager with required methods
src/cli/commands/ Directory for CLI command implementations
src/cli/factories/commandFactory.ts Pattern to follow for command creation
docs/features/conversation-history.md Documentation to align with

Implementation Considerations

Technical details

  • Affected components: CLI only (SDK methods already exist)
  • Breaking changes: No - this adds new functionality
  • Provider compatibility: N/A - this is storage layer (Redis)
  • Performance implications:
    • list command should use metadata-only fetch (already optimized)
    • export-all should handle pagination for large session counts
    • clear should use batch deletion (already implemented)

Suggested Implementation Steps

  1. Create src/cli/commands/memory.ts with subcommand definitions
  2. Create src/cli/factories/memoryCommandFactory.ts following existing patterns
  3. Register memory command in src/cli/index.ts
  4. Add proper error handling for Redis connection issues
  5. Implement table formatting for list output
  6. Add confirmation prompts for destructive operations
  7. Add tests in test/cli/memory.test.ts
  8. Update CLI documentation in docs/cli/commands.md

Example Output Formats

List command (table format):

Session ID    | Title                        | Messages | Last Active
--------------|------------------------------|----------|---------------------
session-123   | Machine Learning Discussion  | 15       | 2024-01-01 10:30:00
session-456   | API Design Review            | 8        | 2024-01-02 14:15:00

Export command (JSON format):

{
  "sessionId": "session-123",
  "title": "Machine Learning Discussion",
  "userId": "user-001",
  "createdAt": "2024-01-01T10:00:00Z",
  "updatedAt": "2024-01-01T10:30:00Z",
  "messages": [
    {
      "id": "msg-001",
      "role": "user",
      "content": "What is machine learning?",
      "timestamp": "2024-01-01T10:00:00Z"
    },
    {
      "id": "msg-002", 
      "role": "assistant",
      "content": "Machine learning is...",
      "timestamp": "2024-01-01T10:00:05Z"
    }
  ]
}

Checklist

  • I have searched existing issues and feature requests to ensure this is not a duplicate
  • I have clearly described the problem and proposed solution
  • I have provided example usage code
  • I have considered alternatives and explained why they don't work
  • I have described the real-world use case

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions