Fix path relativization for packages in different directory trees
When running under dune exec, packages may be installed in different
directory trees (dune install vs opam). Fpath.relativize produces paths
with ".." in these cases, which breaks the output directory structure.
The fix detects ".." in relativized paths and falls back to extracting
path components after the "lib" directory.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>