This answer assumes that we are not talking about the Master's Thesis of the student here, just some project during your and his time at uni, which stems from the line of inquiry *you* are following in your PhD studies.
According to your question and subsequent comments, you clearly did the intellectual and editorial work, presumably you wrote all natural language sentences; the student clearly provided the (relatively) menial task of writing the code. Without the student's contribution, your paper might still have valid meaning as a purely theoretical piece (or you could have done the programming yourself if you had the time). Without your contribution, there would be nothing at all. You were the "owner" here.I also don't get the vibe that you had regular meetings with the student on an equal footing, as a "sparring partner", but it was a clear top-down relationship.
Of course the student wants to have primary authorship, but that does not change the fact that he has not been the primary author. If I understood you right he authored nothing of the paper, only the source code - which probably is not the thing that's printed in publication and consumed by avid readers.
If you are not inclined to deny his request, then you can of course play the "equal authorship" card (which would certainly be nice of you, but... not correct, neither factual not moral). Unless you have formal limitation of what to write there, you could say something like ("$ME (first author), $THEM (programming)") or something along these lines. But in all honesty, you should put it the way it happened. You did author the paper, so you are the primary author. You can still go out of your way to praise the efforts of the student in a personal foreword, which may have equally large benefit for the student.
At the end, the advice of your supervisor is the most important: you have to decide. I could well imagine that he intends it as an exercise for yourself, to work on your moral compass and/or leadership skills, and maybe to drive home the point that these kinds of things should be specified beforehand.
(By the way, I think "moral" is the wrong word here; "ethics" would be the one. And in this context, above all, this is about honesty and objectivity, not about favours. That should be the nucleus of your own answer...)