Hey @ashvin-arkeup! Thanks for sharing.
Accidental removal of code is unfortunately a relatively common issue with all current LLMs, whether you’re working in Cursor, ChatGPT or anywhere else.
While it’s not possible for Cursor to prevent this entirely, they’ve definitely been making some progress with getting Agent mode to spot it for you and course-correct. Sometimes though you do have to keep an eye on the diffs and make sure there’s not an unexpectedly large negative number.
I seem to get this quite rarely now (he said, tempting fate) – it takes a bit of practice in steering the models though. I habitually use phrases like ‘minimal change’ and ‘without affecting existing functionality’ in my prompts, which helps.
It’s also worth making sure you’re not overwhelming the available context, which increases the chances of the model trying to do too much at once and handing back functionally-reduced answers. Keeping your individual file sizes small can be a good habit here. Also, while Cursor’s ability to negotiate long chat/composer sessions for you has improved a lot in recent versions, I still try to start a new session for each major feature I want to work on.
In the case of Composer, if you see a suspect diff, the best thing you can do is to use the Checkpoint restore feature:
This will let you go back to right before the damage was done and adjust your prompt (typically by adding something like “do this carefully and methodically and take care not to remove any existing functionality”).
Alternatively, sometimes (especially with Agent) I take the approach of saying “It seems like you removed almost all of our functionality in @fungibles.ts. Did you really mean to do that?” and the model will respond apologetically and try to repair from context. Be careful with this approach though: it’s fine for smaller fixes but if your file is very large, it may struggle to reconstruct it all. This ends up being another reason I try to keep all source files under about 400 lines, so they’re bite-sized pieces for the model. But at least you can still Checkpoint restore if that doesn’t work out.
Hope this is at least a little helpful. If your projects are starting to grow in size, you might also find some additional handy tips in An Idiot’s Guide To Bigger Projects (from back in October, but still relevant – new version coming soon).