Skip to main content

atomr_agents_coding_cli_harness/
registry.rs

1//! Registry mapping `CliVendorKind` → adapter.
2
3use std::collections::HashMap;
4use std::sync::Arc;
5
6use atomr_agents_coding_cli_core::{CliVendor, CliVendorKind};
7
8#[derive(Default, Clone)]
9pub struct VendorRegistry {
10    inner: HashMap<CliVendorKind, Arc<dyn CliVendor>>,
11}
12
13impl VendorRegistry {
14    pub fn new() -> Self {
15        Self::default()
16    }
17
18    pub fn with(mut self, vendor: Arc<dyn CliVendor>) -> Self {
19        self.inner.insert(vendor.kind(), vendor);
20        self
21    }
22
23    pub fn insert(&mut self, vendor: Arc<dyn CliVendor>) {
24        self.inner.insert(vendor.kind(), vendor);
25    }
26
27    pub fn get(&self, kind: &CliVendorKind) -> Option<Arc<dyn CliVendor>> {
28        self.inner.get(kind).cloned()
29    }
30
31    pub fn kinds(&self) -> impl Iterator<Item = &CliVendorKind> {
32        self.inner.keys()
33    }
34
35    pub fn iter(&self) -> impl Iterator<Item = (&CliVendorKind, &Arc<dyn CliVendor>)> {
36        self.inner.iter()
37    }
38
39    /// Build a registry with the three default vendor adapters wired
40    /// up. Each is gated by a Cargo feature; when a feature is off
41    /// the corresponding adapter is silently omitted.
42    pub fn default_vendors() -> Self {
43        let mut r = Self::new();
44        #[cfg(feature = "vendor-claude")]
45        {
46            r.insert(Arc::new(
47                atomr_agents_coding_cli_vendor_claude::ClaudeVendor::new(),
48            ));
49        }
50        #[cfg(feature = "vendor-codex")]
51        {
52            r.insert(Arc::new(
53                atomr_agents_coding_cli_vendor_codex::CodexVendor::new(),
54            ));
55        }
56        #[cfg(feature = "vendor-gemini")]
57        {
58            r.insert(Arc::new(
59                atomr_agents_coding_cli_vendor_gemini::GeminiVendor::new(),
60            ));
61        }
62        r
63    }
64}