Well, that's a whole book waiting to be written, but here's where I would start.
First, the whole piece should be treated as a low fidelity prototype, even if the user interface looks polished. That's the fidelity trap. Instead, I'd assume that the whole thing tells me roughly what the original intent was, and from there, I'd use my best judgment to discern what that intent might have been. That understanding could then be captured in a list of stories or, better yet, a user story map.
Next, I'd assess whether a rewrite is in order or whether the code can be rescued through a number of small, methodical improvements. Remember, the whole point of a prototype is that it can be disposed of, so the usual caution against rewrites or starting over does not necessarily apply. But if there's already a user base that shouldn't be disrupted, the methodical way of working with legacy code is more appropriate, with the understanding that it preserves what's been built at the cost of taking longer.
Through all this, AI coding assistance can be of great help. Untangling spaghetti code and pinning down dependencies, creating interactive walkthroughs, writing characterization tests so you can then safely jump into refactoring andchanging the behavior.
But hold on a second. Why even bother with all that? Why not load up the codebase into the most capable model to date and tell that one: "Hey, this code is a mess. Fix it and make no mistakes."
The answer lies precisely in the steps I'd take before touching any code: Verifying which behaviors are bugs, which behaviors were explicitly desired, and which were filled in by the AI with no particular user input. You can't tell that from the code, so letting an AI, no matter how good at coding it is, try its best to improve existing code will not get you beyond that inconsistent mix of bugs, features, and in-betweens.
I'd also want to set up the whole system such that the AI can verify and lock in the wins and improvements instead of having to do a big one-shot attempt at "improving" things. Of course an AI can help you set that all up - if you know what to ask for.
The best way to deal with vibe-coded mess is to not get into that situation in the first place. The second best way is to start applying some of the steps from this post. And if that, too, seems daunting, you can work with me to figure it out.
