use hh_core::AgentKind;
use std::path::Path;
#[must_use]
pub fn detect_agent(command: &[String]) -> AgentKind {
let Some(first) = command.first() else {
return AgentKind::Generic;
};
let basename = Path::new(first)
.file_name()
.map(std::ffi::OsStr::to_string_lossy)
.unwrap_or_default();
let stem = basename
.strip_suffix(".exe")
.unwrap_or(&basename)
.to_ascii_lowercase();
if stem == "claude" {
AgentKind::ClaudeCode
} else {
AgentKind::Generic
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_command_is_generic() {
assert_eq!(detect_agent(&[]), AgentKind::Generic);
}
#[test]
fn claude_basename_detects_claude_code() {
assert_eq!(detect_agent(&["claude".into()]), AgentKind::ClaudeCode);
assert_eq!(
detect_agent(&["/usr/local/bin/claude".into()]),
AgentKind::ClaudeCode
);
assert_eq!(detect_agent(&["claude.exe".into()]), AgentKind::ClaudeCode);
}
#[test]
fn other_commands_are_generic() {
assert_eq!(detect_agent(&["python3".into()]), AgentKind::Generic);
assert_eq!(
detect_agent(&["npx".into(), "tsx".into()]),
AgentKind::Generic
);
}
}