There is a relatively common technique to find the intersection of two segments in 3D, which can be found in page 304 of Graphics Gems
Note that a segment is a compact subset of a line.
The technique mostly works, but special logic is needed to handle the 2 cases where the lines are parallel. One where they overlap and one where they don't.
Normally these constructions are much easier with PGA but I don't see anything explicit on the bivector cheat sheet that I commonly use for PGA.
So, given 4 points in 3D given in pair wise segments $(p_1, p_2), (p_3, p_4)$
Can you:
Find the intersection point if it exists (including in cases where the lines are parallel and overlap, in which case any point belonging to both segments is good enough)
Return the closest points on each line in the case where the lines don't intersect, such as skew lines or parallel lines that do not overlap.
?
I have been toying around with doing the wedge of two lines $l_1 \wedge l_2$ to see what happens in those cases, but I am not getting anything useful.