First, writing a detailed functional specification document based on the results of the current code, and then having the latest model rewrite it based on that spec, is a good approach. I use this method frequently too, but there's one important issue to keep in mind: don't
Dotey on Spec-Driven Code Rewriting with Latest Models
Dotey shares a common workflow: write a detailed functional spec from the current code's behavior, then have the latest model rewrite it—while cautioning one important issue to keep in mind.