The top line of less output scrolls out on top because you print a line at the bottom, causing one line of scrolling. That's the
\n in your prompt.
How to avoid this, and still have two lines?
You could write part of the prompt above the mormal command line, instead of using a two line prompt. In a sense, it would be one normal line, and one printed above - outside the normal prompt area (it would require the terminal escape sequences for cursor control).
That would cover the
less case by writing over the last output line, as you suggested.
But it would also write over the output of other commands - many of which do not have more output that just this line.
So there needs to be some explicit handling of the two cases, like printing an extra newline in the not-
It's possible for sure, but would need a lot of manual tweaking to work smooth enough for every-day use...
There are other possible approaches, like changing the terminal scroll area for less,
but that get's even more messy.