If $M$ is a finitely generated module over a local ring $(R, \mathfrak{m})$, we can detect whether $M$ has a nonzero free direct summand as follows: Consider the natural map $$\phi_M\colon \mathrm{Hom}_R(M,\mathfrak{m}) \longrightarrow \mathrm{Hom}_R(M,R)$$ induced by the inclusion of $\mathfrak m$ into $R$. Then $M$ has a nonzero free direct summand if and only if $\\phi_m$ is not surjective. (If $M$ has no free direct summand, then the image of every homomorphism $M \longrightarrow R$ must be inside $\mathfrak m$, so $\phi_M$ is surjective. The converse is easy as well.)

I'd like a more precise statement to be true. The cokernel of $\phi_M$ is a submodule of $\mathrm{Hom}_R(M,R/\mathfrak{m})$, so is a finite-dimensional vector space.

Is the maximal rank of a free direct summand of $M$ equal to the dimension of $\mathrm{coker} \;\phi_M$?

One inequality is obvious -- a surjection $M \longrightarrow R^r$ will give a subspace of dimension $r$.