In calculating the phase difference between two waves, it seems necessary that both waves have the same functionality as a function of the independent variable and that the frequency of the two waves are the same, i.e., their period is the same. In that case the phase difference may be interpreted as the horizontal shift that is necessary to make the two waves fall right on top of each other (assuming they have the same amplitude). It is this fact that necessitates the same period of the two waves. Once the periods are the same, the shift necessary to make the two waves identical is definitely less than the equal wave period. With that, one can proceed to each of your examples to calculate the phase difference. In the first case the two waves are $\sin(x+\phi_{1})$ and $\sin(x+\phi_{2})$. Note that the two waves have the same exact frequency and both are the same periodic function. Thus the magnitude of the phase difference is
$$|(x+\phi_{1})-(x+\phi_{2})|=|\phi_{1}-\phi_{2}|$$
In the second case the two waves are $\sin(x+\phi_{1})$ and $\sin(\phi_{2}-x)$. While both waves are $\sin$ functions, they do not have the exact same frequency (though the absolute value is the same). Thus, as mentioned in the comments
$$\sin(\phi_{2}-x)=-\sin(x-\phi_{2})=\sin(x-\phi_{2}+\pi)$$
Subsequently, the magnitude of the phase difference in this case is
$$|(x+\phi_{1})-(x-\phi_{2}+\pi)|=|\phi_{1}+\phi_{2}-\pi|$$
Note that as mentioned in your problem, the implication of the above equation for $\cos(x)=\sin(\pi/2-x)=\sin(\pi/2+x)$ is that the phase difference between $\sin(\pi/2-x)$ and $\sin(\pi/2+x)$ is 0. I think this answer provides general guidelines for finding the phase difference between two waves through specific examples mentioned in the question. Please let me know if you have any questions or find the answer incorrect.
Phase difference as a constant, independent on time, can be defined only between two waves with the same wave vector and frequency, which is not the case in the example given in the OP, where the waves propagate in the opposite directions.
More generally, the phase difference is defined between two points in space and time. E.g., if we have waves
$$y_1(\mathbf{x},t)=\cos\phi_1(\mathbf{x},t),
y_2(\mathbf{x},t)=\cos\phi_2(\mathbf{x},t),$$
we could define a phase difference between points $\mathbf{x}_1,t_1$ and $\mathbf{x}_2,t_2$ as
$$\Delta \phi(\mathbf{x}_1,t_1;\mathbf{x}_2,t_2 )=\phi_1(\mathbf{x}_1,t_1)-\phi_2(\mathbf{x}_2,t_2).$$
Thus, the phase differences defined in the Op correspond to two different cases:
- same space point, but different time
- same time point, but different locations in space
Remark
One also has to agree about what is considered as a positive/negative frequency and the phase - the paradox in the OP might be simply due to exploiting even symmetry of the cosine function.
Best Answer
Your textbook is describing a special case.
Consider a wave described by the equation
$$\xi = A\sin 2\pi\left(ft-\frac x \lambda\right) = A\sin (\omega t - \varphi)$$
where $x$ is the distance from the source of the wave.
From that we apparently have
$$\varphi = 2\pi\frac x \lambda$$
Now consider two points lying on a line, one with distance $x_1$ from the source and the other with distance $x_2$. Now the path difference is
$$\Delta L\equiv x_2 - x_1$$
and the phase difference
$$\delta\equiv\varphi_2-\varphi_1 = 2\pi\frac{\Delta L}\lambda$$
In vacuum, we obviously don't need to take index of refraction into account.
In case of the entire space being filled with environment with index of refraction $n\neq1$, it doesn't matter either, because we can either take the wavelength of the wave in the environment to be $\lambda$ (in which case the equation stays the same), or we'll take the wavelength in vacuum to be $\lambda$, then the wavelength in the environment becomes
$$\lambda_e = \frac\lambda n$$
and we have
$$\delta = 2\pi\frac{n\Delta L}{\lambda}=2\pi\frac{\text{OPD}}{\lambda}$$
where $\text{OPD}$ is optical path difference.
That's true if you have two waves, each of them traveling through distance $x$ in different environments, the first wave traveling through an environment with index of refraction $n$, and the second one through an environment with $n'$.
(If instead they traveled through the same path in the same environment, and they had the same wavelength in vacuum ($\lambda$), the index of refraction for them would be the same as well, so for two such waves described by your equations, $\delta = 0$.)
Since $x$ is the distance the waves traveled, you can rewrite the right side as
$$\sum\limits_{i=1}^k(n'_i-n_i)d_i=(n'-n)d$$
Now it's apparent that both sides are identical, except the left side takes into account the possibility of each wave travelling through $k$ environments.