use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
pub enum IsolationMode {
#[default]
GitWorktree,
Container,
Hybrid,
}
impl IsolationMode {
pub fn requires_docker(&self) -> bool {
matches!(self, Self::Container | Self::Hybrid)
}
pub fn uses_worktree(&self) -> bool {
matches!(self, Self::GitWorktree | Self::Hybrid)
}
pub fn display_name(&self) -> &'static str {
match self {
Self::GitWorktree => "Git Worktree",
Self::Container => "Docker Container",
Self::Hybrid => "Hybrid (Worktree + Container)",
}
}
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Option<Self> {
match s.to_lowercase().as_str() {
"worktree" | "git" | "gitworktree" => Some(Self::GitWorktree),
"container" | "docker" => Some(Self::Container),
"hybrid" => Some(Self::Hybrid),
_ => None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct IsolationConfig {
pub mode: IsolationMode,
pub enforce: bool,
pub container: ContainerIsolationConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContainerIsolationConfig {
pub base_image: Option<String>,
pub enable_gpu: bool,
pub extra_volumes: Vec<(String, String)>,
pub extra_env: std::collections::HashMap<String, String>,
pub network_mode: Option<String>,
pub auto_remove: bool,
}
impl Default for ContainerIsolationConfig {
fn default() -> Self {
Self {
base_image: None,
enable_gpu: false,
extra_volumes: Vec::new(),
extra_env: std::collections::HashMap::new(),
network_mode: None,
auto_remove: true,
}
}
}