To solve the given differential equation:
\[ x \cos\left(\frac{y}{x}\right) \frac{dy}{dx} = y \cos\left(\frac{y}{x}\right) + x \]
This equation can be solved using the substitution \( z = \frac{y}{x} \).
This implies \( y = zx \). Differentiating with respect to \( x \), we get:
\(\frac{dy}{dx} = z + x \frac{dz}{dx}\)
Substituting these into the differential equation yields:
\[ x \cos(z) (z + x \frac{dz}{dx}) = zx \cos(z) + x \]
Simplifying the equation leads to:
\[ xz \cos(z) + x^2 \cos(z) \frac{dz}{dx} = zx \cos(z) + x \]
After canceling terms, we obtain:
\[ x^2 \cos(z) \frac{dz}{dx} = x(1 - z \cos(z)) \]
This further simplifies to:
\[ \frac{dz}{dx} = \frac{1 - z \cos(z)}{x \cos(z)} \]
Separating variables and integrating both sides:
\[ \int \frac{\cos(z)}{1 - z \cos(z)} \, dz = \int \frac{1}{x} \, dx \]
The integral on the right side is:
\[ \int \frac{1}{x} \, dx = \log_e |x| + C \]
Considering the provided solution format:
\[ \sin\left(\frac{y}{x}\right) = \log_e |x| + \frac{\alpha}{2} \]
Using the point \( x = 1, y = \frac{\pi}{3} \), we substitute these values:
\[ \sin\left(\frac{\pi}{3}\right) = \log_e |1| + \frac{\alpha}{2} \]
Since \(\sin\left(\frac{\pi}{3}\right) = \frac{\sqrt{3}}{2}\) and \(\log_e |1| = 0\):
\[ \frac{\sqrt{3}}{2} = 0 + \frac{\alpha}{2} \]
Solving for \( \alpha \):
\[ \alpha = \sqrt{3} \]
Consequently, \( \alpha^2 = (\sqrt{3})^2 = 3 \).
Therefore, the final answer is 3.