  Let $\mathfrak{g}$ be a simple Lie algebra, and let $W_\kappa$ be the affine
${W}$-algebra associated to a principal nilpotent element of $\mathfrak{g}$ and
level $\kappa$. We explain a duality between the categories of smooth ${W}$
modules at levels $\kappa + \kappa_c$ and $-\kappa + \kappa_c$, where
$\kappa_c$ is the critical level. Their pairing amounts to a construction of
semi-infinite cohomology for the ${W}$-algebra. As an application, we determine
all homomorphisms between the Verma modules for ${W}$, verifying a conjecture
from the conformal field theory literature of de Vos--van Driel. Along the way,
we determine the linkage principle for Category $\mathscr{O}$ of the
${W}$-algebra.
