Skip to main content

tracevault_cli/
agent.rs

1//! The AI coding agent a hook invocation belongs to. Carries the two
2//! agent-specific values stamped on an outgoing `StreamEventRequest`:
3//! the `tool` name (which the server keys its adapter off) and the
4//! `protocol_version`. Everything else in the capture path is agent-agnostic.
5
6#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
7pub enum Agent {
8    ClaudeCode,
9    Codex,
10}
11
12impl Agent {
13    /// The `tool` value stamped on the stream request. The server selects its
14    /// per-agent adapter from this string.
15    pub fn tool_name(&self) -> &'static str {
16        match self {
17            Agent::ClaudeCode => "claude-code",
18            Agent::Codex => "codex",
19        }
20    }
21
22    /// Wire protocol version. Claude Code stays on v1 (behaviour-preserving);
23    /// Codex uses v2, where the server honours the explicit `tool`.
24    pub fn protocol_version(&self) -> u8 {
25        match self {
26            Agent::ClaudeCode => 1,
27            Agent::Codex => 2,
28        }
29    }
30
31    /// Human-readable label for CLI output. Preserves the original wording so
32    /// the default Claude Code path prints identically to before.
33    pub fn label(&self) -> &'static str {
34        match self {
35            Agent::ClaudeCode => "Claude Code",
36            Agent::Codex => "Codex",
37        }
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44    use clap::ValueEnum;
45
46    #[test]
47    fn tool_name_and_protocol_version() {
48        assert_eq!(Agent::ClaudeCode.tool_name(), "claude-code");
49        assert_eq!(Agent::ClaudeCode.protocol_version(), 1);
50        assert_eq!(Agent::Codex.tool_name(), "codex");
51        assert_eq!(Agent::Codex.protocol_version(), 2);
52    }
53
54    #[test]
55    fn value_enum_parses_kebab_case() {
56        assert_eq!(
57            Agent::from_str("claude-code", true).unwrap(),
58            Agent::ClaudeCode
59        );
60        assert_eq!(Agent::from_str("codex", true).unwrap(), Agent::Codex);
61        assert!(Agent::from_str("cursor", true).is_err());
62    }
63
64    #[test]
65    fn label_wording() {
66        assert_eq!(Agent::ClaudeCode.label(), "Claude Code");
67        assert_eq!(Agent::Codex.label(), "Codex");
68    }
69}