I saw a question here about the mechanism for a heterocyclic ring formation: What is a reasonable mechanism for the following reaction?. I tried solving the mechanism but I am missing something. Let me explain my reasoning:
I started protonating the nitrile N, followed by the attack of the cyclic N to the terminal alkyne carbon. Then I couldn't figure out what happens next, so I assumed the triple bond attacks a proton and forms the acrylonitrile intermediate (I am 99.99% sure this is not what happens). Then the exo N attacks the nitrile carbon and form the 6-membered ring, followed by a proton exchange between the imino nitrogen and the protonated cyclic amino group (again, I feel this is ridiculously wrong). The lone pair on the cyclic amino group form the double C=N bond, however, I still end with a protonated N that is not in the product.
Can someone explain to me what I am missing?