Skip to main content

codetether_agent/agent/
registry.rs

1//! Agent registry implementation.
2//!
3//! This module stores the catalog of available agents and offers filtered views
4//! for UI and server consumers.
5//!
6//! # Examples
7//!
8//! ```ignore
9//! let registry = AgentRegistry::with_builtins();
10//! assert!(!registry.list().is_empty());
11//! ```
12
13use super::{AgentInfo, AgentMode, builtin};
14use std::collections::HashMap;
15
16/// Registry of known agent profiles.
17///
18/// The registry is a simple in-memory catalog used by the server, tests, and
19/// UI layers to enumerate and select agents.
20///
21/// # Examples
22///
23/// ```ignore
24/// let registry = AgentRegistry::new();
25/// ```
26pub struct AgentRegistry {
27    agents: HashMap<String, AgentInfo>,
28}
29
30impl AgentRegistry {
31    /// Creates an empty registry with no built-in agents.
32    ///
33    /// # Examples
34    ///
35    /// ```ignore
36    /// let registry = AgentRegistry::new();
37    /// ```
38    pub fn new() -> Self {
39        Self {
40            agents: HashMap::new(),
41        }
42    }
43
44    /// Registers an agent profile in the catalog.
45    ///
46    /// # Examples
47    ///
48    /// ```ignore
49    /// registry.register(info);
50    /// ```
51    pub fn register(&mut self, info: AgentInfo) {
52        self.agents.insert(info.name.clone(), info);
53    }
54
55    /// Returns an agent profile by name when present.
56    ///
57    /// # Examples
58    ///
59    /// ```ignore
60    /// let build = registry.get("build");
61    /// ```
62    #[allow(dead_code)]
63    pub fn get(&self, name: &str) -> Option<&AgentInfo> {
64        self.agents.get(name)
65    }
66
67    /// Lists every registered agent profile.
68    ///
69    /// # Examples
70    ///
71    /// ```ignore
72    /// let all = registry.list();
73    /// ```
74    pub fn list(&self) -> Vec<&AgentInfo> {
75        self.agents.values().collect()
76    }
77
78    /// Lists visible primary agents for UI presentation.
79    ///
80    /// # Examples
81    ///
82    /// ```ignore
83    /// let primary = registry.list_primary();
84    /// ```
85    #[allow(dead_code)]
86    pub fn list_primary(&self) -> Vec<&AgentInfo> {
87        self.agents
88            .values()
89            .filter(|agent| agent.mode == AgentMode::Primary && !agent.hidden)
90            .collect()
91    }
92
93    /// Creates a registry pre-populated with built-in agents.
94    ///
95    /// # Examples
96    ///
97    /// ```ignore
98    /// let registry = AgentRegistry::with_builtins();
99    /// ```
100    pub fn with_builtins() -> Self {
101        let mut registry = Self::new();
102        registry.register(builtin::build_agent());
103        registry.register(builtin::plan_agent());
104        registry.register(builtin::explore_agent());
105        registry
106    }
107}
108
109impl Default for AgentRegistry {
110    fn default() -> Self {
111        Self::with_builtins()
112    }
113}