-
Notifications
You must be signed in to change notification settings - Fork 72
Labels
enhancementNew feature or requestNew feature or request
Description
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 sessionsaveSession()- Persist current session to disklistSessions()- Get all available sessionsloadSession()- Load session from diskdeleteSession()- Remove session fileautoSave()- Periodic auto-save functionalitygenerateSessionTitle()- 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
resumeSessionmode 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
- Create session manager module with core storage logic
- Implement session schema and file I/O
- Add automatic session persistence to app state
- Build session selector UI component
- Implement
/resumecommand handler - Add command registration and integration
- Implement cleanup and edge case handling
- Add configuration options
- 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
Assignees
Labels
enhancementNew feature or requestNew feature or request