This is how Ibn `Arabi (q) in Fusus al-hikam explains the three acts of Khidr witnessed by Musa :
"Moses was tested 'by many ordeals' [20:41] the first of which was the murder of the Egyptian [28:14-15], an act which he committed by Divine impulsion and with the approbation of God deep inside him, without however, his perceiving it; nevertheless he felt no affliction in his soul for having killed the Egyptian, although he himself was not acquitted until he had received a Divine revelation on the subject. For all prophets are interiorly preserved from sin without their being conscious of it, even before they are warned by inspiration.
"It is for that reason that al-Khidr showed him the putting to death of the boy, an action for which Moses reproached him, without remembering his murder of the Egyptian, upon which al-Khidr said to him: 'I have not done it of my own initiative,' recalling thus to Moses the state in which he, the latter, found himself when he did not yet know that he was essentially preserved from all action contrary to the Divine Order.
"He showed him also the perforation of the boat, apparently made to destroy the people, but which has, however, the hidden sense of saving them from the hand of a 'violent man.' He showed this to him as an analogy to the ark which hid Moses when he was thrown into the Nile; according to appearances, this act was equally to destroy him, but according to the hidden sense, it was to save him. Again his mother had done that for fear of the 'violent man,' in this case Pharaoh, so that he would not cruelly kill the child...
"Moses arrived then at Madyan, there met the two girls and for them drew water from the well, without asking from them a salary. Then he 'withdrew to the shade,' that is to say to the Divine shadow, and said: 'O my Lord, I am poor with regard to the blessings Thou bestowest on Me'; he attributed, then, to God alone the essence of the good that he did and qualified himself as poor (faqir) towards God. It was for that reason that al-Khidr reconstructed before him the crumbling wall without asking a salary for his work, for which Moses reprimanded him, until Khidr reminded him of his action of drawing water without asking for reward, and other things too, of which there is no mention in the Koran; so that the Messenger of God -- may God bless him and give him Peace! -- regretted that Moses did not keep quiet and did not remain with al-Khidr, so that God could tell him more of their actions."
 Kabbani, Shaykh Muhammad Hisham, Classical Islam and the Naqshbandi Sufi Tradition, Islamic Supreme Council of America, Washington, DC, 2004.