openlatch-client 0.1.6

The open-source security layer for AI agents — client forwarder
use std::path::PathBuf;
use std::sync::Arc;

use crate::error::OlError;

pub trait AgentBinding: Send + Sync {
    fn agent_type(&self) -> &str;
    fn settings_path(&self) -> PathBuf;
    fn hook_event_types(&self) -> &[&str];
    fn token_env_var(&self) -> &str;
}

pub fn detect_binding() -> Result<Arc<dyn AgentBinding>, OlError> {
    use super::bindings::claude_code::ClaudeCodeBinding;

    if let Some(binding) = ClaudeCodeBinding::detect() {
        return Ok(Arc::new(binding));
    }

    Err(OlError::new(
        crate::error::ERR_HOOK_AGENT_NOT_FOUND,
        "No AI agents detected",
    )
    .with_suggestion("Install Claude Code (https://claude.ai/download) and try again.")
    .with_docs("https://docs.openlatch.ai/errors/OL-1400"))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn agent_binding_is_object_safe() {
        fn _assert_object_safe(_: &dyn AgentBinding) {}
    }

    #[test]
    fn agent_binding_is_send_sync() {
        fn _assert_send_sync<T: Send + Sync>() {}
        _assert_send_sync::<Arc<dyn AgentBinding>>();
    }
}