If you must refuse, refuse in person, or refuse by phone. Do not put anything in writing, unless you're absolutely sure of your rights.
Since your advisor is making you a Research Assistant, note that she could be implicitly buying your future collaboration as well. After all, if your code is sufficiently complex, she may require your expertise to install it, understand it, run it properly, and possibly modify it.
In which case, you could use the fact that you don't have the time to work with her, nor the time to clean up your code to make it more readable or usable right now. Or you could simply refuse her request without justifying yourself to her (but again, do not put any of this in writing, just tell her in person or over the phone, if you're not absolutely sure of your rights).
And some people mentioned that you might want to get cited for your source code, but it could also be that you don't want your name associated with her project. So you could ask for that as well if you wanted.
Or perhaps, you could set the goal to release the source code, but only a year or two from now, by which time, it will be too late for her to use it in her grant. Or perhaps, you could release an older less usable version of the code.
Or if your relationship ended really badly, you could just tell her that you won't help and that you don't wish her to ever contact you again. And then, you could make a filter that ensures that you never see her email messages ever again.
My point is that you have many options. It's just that I am not really clear about your reason for refusing her request. If we knew your exact reason, then maybe we could supply you with a more exact answer.