Skip to main content

detect_coding_agent/
types.rs

1/// The kind of AI coding environment detected.
2#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3pub enum AgentKind {
4    /// A fully automated coding agent (no human in the loop during execution).
5    ///
6    /// Examples: Claude Code, OpenAI Codex, GitHub Copilot Cloud Agent.
7    Agent,
8
9    /// An interactive AI-assisted coding tool where a human is still driving.
10    ///
11    /// Examples: Cursor (interactive mode), Zed (interactive mode).
12    Interactive,
13
14    /// An environment that can operate in both agent and interactive modes.
15    ///
16    /// Examples: Warp Terminal.
17    Hybrid,
18}
19
20impl AgentKind {
21    /// Returns `true` if this is an autonomous [`AgentKind::Agent`].
22    pub fn is_agent(&self) -> bool {
23        matches!(self, Self::Agent)
24    }
25
26    /// Returns `true` if this is an [`AgentKind::Interactive`] environment.
27    pub fn is_interactive(&self) -> bool {
28        matches!(self, Self::Interactive)
29    }
30
31    /// Returns `true` if this is a [`AgentKind::Hybrid`] environment.
32    pub fn is_hybrid(&self) -> bool {
33        matches!(self, Self::Hybrid)
34    }
35}
36
37impl std::fmt::Display for AgentKind {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        match self {
40            Self::Agent => write!(f, "agent"),
41            Self::Interactive => write!(f, "interactive"),
42            Self::Hybrid => write!(f, "hybrid"),
43        }
44    }
45}
46
47/// Information about a detected AI coding agent environment.
48#[derive(Debug, Clone, PartialEq, Eq)]
49pub struct DetectedAgent {
50    /// A stable, unique identifier for the agent (e.g. `"claude-code"`, `"codex"`).
51    pub id: &'static str,
52
53    /// The human-readable name of the agent (e.g. `"Claude Code"`, `"OpenAI Codex"`).
54    pub name: &'static str,
55
56    /// The kind of AI coding environment.
57    pub kind: AgentKind,
58}
59
60impl DetectedAgent {
61    /// Returns `true` if the detected environment is an autonomous agent.
62    pub fn is_agent(&self) -> bool {
63        self.kind.is_agent()
64    }
65
66    /// Returns `true` if the detected environment is interactive (human-driven).
67    pub fn is_interactive(&self) -> bool {
68        self.kind.is_interactive()
69    }
70
71    /// Returns `true` if the detected environment is hybrid (agent + interactive).
72    pub fn is_hybrid(&self) -> bool {
73        self.kind.is_hybrid()
74    }
75}
76
77impl std::fmt::Display for DetectedAgent {
78    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79        write!(f, "{} ({})", self.name, self.kind)
80    }
81}