Skip to content

Feature Request: /resume command to allow users to save, list, and restore previous chat sessions #51

@will-lamerton

Description

@will-lamerton

Overview

Implement automatic session storage and a /resume command to allow users to save, list, and restore previous chat sessions.

Goals

  • Automatically persist chat sessions to disk
  • Allow users to list previous sessions
  • Enable resuming any past session with full context
  • Handle session cleanup and management

Architecture

Session Storage

Location: ~/.nanocoder-sessions/

File Structure:

~/.nanocoder-sessions/
├── sessions.json          # Index of all sessions
└── {session-id}.json      # Individual session files

Session Schema:

interface Session {
  id: string;              // Unique session ID (timestamp-based)
  title: string;           // Auto-generated from first message or manual
  createdAt: string;       // ISO timestamp
  lastAccessedAt: string;  // ISO timestamp
  messageCount: number;    // Number of messages
  provider: string;        // LLM provider used
  model: string;           // Model used
  workingDirectory: string; // CWD when session created
  messages: Message[];     // Full conversation history
}

Implementation Tasks

1. Session Management Module

File: source/session/session-manager.ts

  • createSession() - Initialize new session
  • saveSession() - Persist current session to disk
  • listSessions() - Get all available sessions
  • loadSession() - Load session from disk
  • deleteSession() - Remove session file
  • autoSave() - Periodic auto-save functionality
  • generateSessionTitle() - Create title from first user message

2. Automatic Session Persistence

Integration Point: source/app/hooks/useAppState.ts

  • Auto-save after each assistant response
  • Debounce to avoid excessive writes
  • Save on exit (cleanup handler)
  • Update session metadata (lastAccessedAt, messageCount)

3. Session List UI Component

File: source/components/session-selector.tsx

Display format:

Recent Sessions:
[1] Fix authentication bug (15 messages) - 2 hours ago
[2] Add dark mode feature (42 messages) - yesterday
[3] Refactor API client (8 messages) - 3 days ago

Enter number to resume, or 'q' to cancel:

Features:

  • Sortable by date/message count
  • Search/filter by title or content
  • Show provider/model info
  • Pagination for large session lists

4. /resume Command Handler

File: source/commands/resume.ts

Behaviors:

  • /resume - Show session selector UI
  • /resume {id} - Resume specific session by ID
  • /resume {number} - Resume by list index
  • /resume last - Resume most recent session

5. Command Registration

File: source/commands/index.ts

Add resume command to built-in commands with:

  • Help text
  • Autocomplete support
  • Aliases (/sessions, /history)

6. App State Integration

File: source/app.tsx

  • Add resumeSession mode to app state
  • Handle session loading on startup
  • Restore full conversation context
  • Preserve provider/model selection from session

Edge Cases & Considerations

Session Cleanup

  • Auto-delete sessions older than X days (configurable)
  • Implement session size limits
  • Handle disk space issues gracefully

Migration & Compatibility

  • Version session schema for future updates
  • Handle corrupted session files
  • Backward compatibility for older sessions

Context Management

  • Validate loaded messages match current tool schema
  • Handle sessions from different working directories
  • Warn if provider/model no longer available

Performance

  • Lazy load session content (index vs full messages)
  • Implement session caching
  • Optimize for large session lists

Configuration Options

Add to agents.config.json or preferences:

{
  "sessions": {
    "autoSave": true,
    "saveInterval": 5000,
    "maxSessions": 100,
    "retentionDays": 30,
    "directory": "~/.nanocoder-sessions"
  }
}

Testing Considerations

  • Test session save/load cycle
  • Verify message history integrity
  • Test with different providers/models
  • Handle concurrent session access
  • Test cleanup and migration logic

Implementation Order

  1. Create session manager module with core storage logic
  2. Implement session schema and file I/O
  3. Add automatic session persistence to app state
  4. Build session selector UI component
  5. Implement /resume command handler
  6. Add command registration and integration
  7. Implement cleanup and edge case handling
  8. Add configuration options
  9. Write tests

Future Enhancements

  • Session branching (fork conversation at any point)
  • Session export/import (share sessions)
  • Session search by content
  • Session tagging and organization
  • Cloud sync for sessions across machines
  • Session analytics (token usage, cost tracking)

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions