kodegen_bundler_autoconfig/
lib.rs

1pub mod clients;
2pub mod config;
3pub mod install;
4pub mod watcher;
5
6// Re-export commonly used types
7use std::path::{Path, PathBuf};
8
9use anyhow::Result;
10pub use config::ConfigMerger;
11pub use install::{InstallResult, install_all_clients};
12use serde::{Deserialize, Serialize};
13
14/// Core trait for MCP client configuration plugins
15pub trait ClientConfigPlugin: Send + Sync {
16    /// Unique identifier (e.g., "claude-desktop", "windsurf", "cursor")
17    fn client_id(&self) -> &str;
18
19    /// Human-readable name (e.g., "Claude Desktop")
20    fn client_name(&self) -> &str;
21
22    /// Get all directories to watch for this client
23    fn watch_paths(&self) -> Vec<PathBuf>;
24
25    /// Get the config file path(s) for this client
26    fn config_paths(&self) -> Vec<ConfigPath>;
27
28    /// Check if config indicates client is installed
29    fn is_installed(&self, path: &Path) -> bool;
30
31    /// Inject KODEGEN.ᴀɪ into existing config
32    ///
33    /// # Errors
34    ///
35    /// Returns an error if the config cannot be parsed or serialized for the given format.
36    fn inject_kodegen(&self, config_content: &str, format: ConfigFormat) -> Result<String>;
37
38    /// Get the default config format for this client
39    fn config_format(&self) -> ConfigFormat;
40}
41
42#[derive(Debug, Clone)]
43pub struct ConfigPath {
44    pub path: PathBuf,
45    pub format: ConfigFormat,
46    pub platform: Platform,
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum ConfigFormat {
51    Json,
52    Toml,
53    Yaml,
54    Plist,
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum Platform {
59    Windows,
60    MacOS,
61    Linux,
62    All,
63}
64
65impl Platform {
66    #[must_use]
67    pub const fn current() -> Self {
68        #[cfg(target_os = "windows")]
69        return Self::Windows;
70
71        #[cfg(target_os = "macos")]
72        return Self::MacOS;
73
74        #[cfg(target_os = "linux")]
75        return Self::Linux;
76
77        #[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
78        return Self::All;
79    }
80}
81
82/// Standard KODEGEN server configuration
83#[derive(Debug, Serialize, Deserialize, Clone)]
84pub struct KodegenConfig {
85    pub command: String,
86    pub args: Vec<String>,
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub env: Option<serde_json::Value>,
89}
90
91impl Default for KodegenConfig {
92    fn default() -> Self {
93        Self {
94            command: "kodegen".to_string(),
95            args: vec!["--stdio".to_string()],
96            env: None,
97        }
98    }
99}
100
101/// Alternative HTTP-based config for clients that support it
102#[derive(Debug, Serialize, Deserialize, Clone)]
103pub struct KodegenHttpConfig {
104    #[serde(rename = "type")]
105    pub transport_type: String,
106    pub url: String,
107}
108
109impl Default for KodegenHttpConfig {
110    fn default() -> Self {
111        Self {
112            transport_type: "streamable-http".to_string(),
113            url: "https://kodegen.kodegen.dev:8443".to_string(),
114        }
115    }
116}