Skip to main content

gate4agent_types/
executable.rs

1use crate::RuntimePlatform;
2
3/// Normalize an executable name for portable provider matching.
4///
5/// This function performs no filesystem access. It only applies the platform
6/// naming rules to a supplied path or command string.
7pub fn normalize_executable_name(
8    command_or_path: &str,
9    platform: RuntimePlatform,
10) -> String {
11    let basename = command_or_path
12        .trim()
13        .rsplit(['/', '\\'])
14        .next()
15        .unwrap_or_default();
16    if platform == RuntimePlatform::Windows {
17        let lowercase = basename.to_ascii_lowercase();
18        for suffix in [".exe", ".cmd", ".bat", ".ps1"] {
19            if let Some(stripped) = lowercase.strip_suffix(suffix) {
20                return stripped.to_owned();
21            }
22        }
23        lowercase
24    } else {
25        basename.to_owned()
26    }
27}