diff options
Diffstat (limited to 'src/platform/mod.rs')
| -rw-r--r-- | src/platform/mod.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/platform/mod.rs b/src/platform/mod.rs index e396966b..3583df5e 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -148,11 +148,22 @@ mod fallback; #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))] pub use fallback::*; -#[cfg(not(target_os = "linux"))] +#[cfg(not(any(target_os = "linux", target_os = "macos")))] pub fn process_agent_hint(_pid: u32) -> Option<crate::detect::Agent> { None } +#[cfg(any(target_os = "linux", target_os = "macos"))] +pub(crate) fn parse_agent_env_hint(environ: &[u8]) -> Option<crate::detect::Agent> { + for record in environ.split(|&byte| byte == 0) { + let Some(value) = record.strip_prefix(b"HERDR_AGENT=") else { + continue; + }; + return crate::detect::parse_agent_label(std::str::from_utf8(value).ok()?); + } + None +} + #[cfg(not(target_os = "macos"))] #[derive(Debug)] pub(crate) struct InputSourceRestore; @@ -229,6 +240,26 @@ mod tests { ); } + #[cfg(any(target_os = "linux", target_os = "macos"))] + #[test] + fn parse_agent_env_hint_accepts_known_agents() { + assert_eq!( + parse_agent_env_hint(b"PATH=/bin\0HERDR_AGENT=claude\0TERM=xterm\0"), + Some(crate::detect::Agent::Claude) + ); + assert_eq!( + parse_agent_env_hint(b"HERDR_AGENT=codex"), + Some(crate::detect::Agent::Codex) + ); + } + + #[cfg(any(target_os = "linux", target_os = "macos"))] + #[test] + fn parse_agent_env_hint_ignores_missing_or_unknown_agents() { + assert_eq!(parse_agent_env_hint(b"PATH=/bin\0TERM=xterm\0"), None); + assert_eq!(parse_agent_env_hint(b"HERDR_AGENT=not-an-agent\0"), None); + } + #[test] fn read_limited_reader_returns_complete_data_under_limit() { let input = std::io::Cursor::new(b"image".to_vec()); |
