extract_meaningful_path

Function extract_meaningful_path 

Source
pub fn extract_meaningful_path(path: &Path) -> String
Expand description

Extract meaningful path structure from a dependency path.

This function handles three cases:

  1. Relative paths with ../ - strips all parent directory components
  2. Absolute paths - resolves .. components and strips root/prefix
  3. Clean relative paths - uses as-is with normalized separators

ยงExamples

use std::path::Path;

// Relative paths with parent navigation
assert_eq!(extract_meaningful_path(Path::new("../../snippets/dir/file.md")), "snippets/dir/file.md");

// Absolute paths (root stripped, .. resolved) - Unix-style path
#[cfg(unix)]
assert_eq!(extract_meaningful_path(Path::new("/tmp/foo/../bar/agent.md")), "tmp/bar/agent.md");

// Absolute paths (root stripped, .. resolved) - Windows-style path
#[cfg(windows)]
assert_eq!(extract_meaningful_path(Path::new("C:\\tmp\\foo\\..\\bar\\agent.md")), "tmp/bar/agent.md");

// Clean relative paths
assert_eq!(extract_meaningful_path(Path::new("agents/test.md")), "agents/test.md");