Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restoring project from snapshot on reload #444

Merged
merged 8 commits into from
Mar 5, 2025

Conversation

thecodacus
Copy link
Collaborator

@thecodacus thecodacus commented Nov 28, 2024

Add Chat History Snapshot System

Overview

This PR introduces a snapshot system for chat history, allowing the restoration of previous chat states along with their associated file system state. This feature improves the user experience by enabling users to resume work from specific points in their conversation history while maintaining context and workspace consistency.

Key Changes

1. Chat History Management

  • Added snapshot storage and restoration functionality
  • Implemented message filtering for hidden and no-store annotations
  • Added support for archived messages
  • Introduced chat index tracking for partial history restoration

2. File System Integration

  • Added snapshot system for file system state
  • Implemented file and folder restoration logic
  • Added support for binary and text file handling
  • Integrated with WebContainer for file system operations

3. UI Updates

  • Added snapshot restoration messages
  • Implemented hidden message filtering in the Messages component
  • Added visual indicators for restored snapshots

4. Storage System

  • Added new Snapshot type definition
  • Implemented localStorage-based snapshot storage
  • Added file system state serialization
  • Introduced FileMap type for tracking file states

Technical Details

Snapshot System

  • Stores chat index and complete file system state
  • Handles both binary and text files
  • Manages folder structure preservation
  • Implements proper cleanup and restoration logic

Message Handling

  • Added support for message annotations (hidden, no-store)
  • Implemented archived message management
  • Added snapshot restoration messages
  • Improved message filtering logic

Testing

  • Tested snapshot creation and restoration
  • Verified file system state preservation
  • Tested binary and text file handling
  • Verified folder structure restoration
  • Tested partial history restoration

Migration Impact

  • No breaking changes for existing chat functionality
  • Snapshots are stored separately from existing chat history
  • Backwards compatible with existing chats
  • No changes required for existing message handling

Future Improvements

  • Add support for multiple snapshots per chat
  • Implement snapshot cleanup mechanism
  • Add snapshot management UI
  • Improve restoration performance for large file systems

Preview

Snapshot.demo.mp4

@thecodacus thecodacus marked this pull request as ready for review November 28, 2024 11:49
@coleam00
Copy link
Collaborator

@thecodacus Nice work!! Honestly I already thought that this functionality existed mostly already where you could go back to previous conversations and it would already have everything loaded in. Is that not the case? When you went back to a previous chat it wouldn't actually load in the context from the file system?

Also, I would suggest changing the messaging from "Restoring chat from snapshot" to "Restored chat from snapshot", otherwise it seems like it is processing infinitely since the message never goes away. Maybe you could also have the code window open automatically as well?

Thank you for the work you're putting into this man!

@thecodacus
Copy link
Collaborator Author

hi @coleam00 , the purpose of this pr is to add snapshots.

the currently when you reload a chat all the actions are run again from scratch, and executes all the action in sequence to reconstruct the file system. and that includes all the writes and rewrites of the files. But with this the file system is restored and from a snapshot in one message at the start.

but when you restore from snapshot naturally llm looses all the actions from the pasts and looses the files context. this change also considers that it retains the project content as context after restoring

@thecodacus thecodacus changed the title feat:(project-snapshot) restoring project from snapshot on reload feat: restoring project from snapshot on reload Dec 22, 2024
@thecodacus
Copy link
Collaborator Author

thecodacus commented Dec 22, 2024

@wonderwhy-er , please test this you will love it. it retains the chat context even after snapshot.

but i might have to refactor some of the stuff i wrote here, what to get review before that

@wonderwhy-er
Copy link
Collaborator

Will try, holidays not letting me to computer
Will see

@flikites
Copy link

@wonderwhy-er , please test this you will love it. it retains the chat context even after snapshot.

but i might have to refactor some of the stuff i wrote here, what to get review before that

I can ttest this out if it hasn't been tested yet?

@leex279 leex279 added the core-team-discussion to be discussed within the core team label Jan 17, 2025
@siba2893
Copy link

When will this PR be tested and added to the core implementation?

@thecodacus
Copy link
Collaborator Author

I will be adapting this to the latest codebase.
I believe you will be able to see this as experimental optional feature in next few days

@thecodacus thecodacus requested review from leex279 and xKevIsDev March 4, 2025 17:20
Copy link
Collaborator

@leex279 leex279 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me as described. Dont see any errors so far.

@thecodacus thecodacus merged commit 1f94039 into stackblitz-labs:main Mar 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-team-discussion to be discussed within the core team enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants