In the book "Rashi and Maimonides" (pg 302), I found the following (paraphrasing):
Another story has it that Rashi sat fasting for 613 days to purify himself for the task of commenting on the Torah. When he completed his work, Moses appeared to him and said "אשריך בני שרק אתה זכית להבין את דברי התורה כי בבאורך כך קבלתי מפי הגבורה" ("you are praiseworthy, my son, that only you merited to understand the Torah, that in your commentary thus I received from the Almighty").
Despite being a relatively academic book, no source is provided for this legend. Where did it come from (or at least, where has it been published previously)?