Structural basis of the Cope rearrangement and cyclization in hapalindole biogenesis