Who has right of way in a medina alley?

The short answer

An unwritten hierarchy based on physics: laden donkeys first, then handcarts, then motorcycles, then bicycles, then pedestrians. The thing hardest to stop gets priority.

A donkey carrying two hundred kilos cannot stop or reverse easily. You can. A motorcycle at speed has less ability to brake than you have to press against a wall.

On crowded streets, the hierarchy inverts. A short horn beep means "I'm behind you, move slightly." A half-step to either side without turning around. Nobody stops. The motorcycle passes with centimetres to spare.

"Balak!" from a handcart operator means move aside. A donkey handler clicks or hisses. A cyclist says nothing and expects you to hear the wheels.

Your job as a pedestrian: walk at a steady pace, keep roughly to the right, don't make sudden lateral moves. The system fails when people freeze or leap sideways.