I tried to use mosh, but it turned on really bad mobile network even it was not helpful. What surprisingly worked OK was Emacs shell plus lsyncd. With that I type commands locally and send the whole line on Enter while lsync transparently syncs my edits of local files to the server. Then I can live with latencies of over a second.