use crate::abstractions::git::GitOperations;
use crate::config::WorkflowConfig;
use crate::cook::environment::{EnvValue, EnvironmentConfig};
use crate::cook::execution::{ClaudeExecutor, CommandExecutor};
use crate::cook::interaction::UserInteraction;
use crate::cook::session::SessionManager;
use crate::cook::workflow::WorkflowExecutorImpl;
use crate::testing::config::TestConfiguration;
use std::path::PathBuf;
use std::sync::Arc;
use super::core::{CookConfig, DefaultCookOrchestrator};
pub struct OrchestratorBuilder {
session_manager: Arc<dyn SessionManager>,
command_executor: Arc<dyn CommandExecutor>,
claude_executor: Arc<dyn ClaudeExecutor>,
user_interaction: Arc<dyn UserInteraction>,
git_operations: Arc<dyn GitOperations>,
subprocess: crate::subprocess::SubprocessManager,
test_config: Option<Arc<TestConfiguration>>,
}
impl OrchestratorBuilder {
#[allow(clippy::too_many_arguments)]
pub fn new(
session_manager: Arc<dyn SessionManager>,
command_executor: Arc<dyn CommandExecutor>,
claude_executor: Arc<dyn ClaudeExecutor>,
user_interaction: Arc<dyn UserInteraction>,
git_operations: Arc<dyn GitOperations>,
subprocess: crate::subprocess::SubprocessManager,
) -> Self {
Self {
session_manager,
command_executor,
claude_executor,
user_interaction,
git_operations,
subprocess,
test_config: None,
}
}
pub fn with_test_config(mut self, test_config: Arc<TestConfiguration>) -> Self {
self.test_config = Some(test_config);
self
}
pub fn build(self) -> DefaultCookOrchestrator {
DefaultCookOrchestrator::from_builder(
self.session_manager,
self.command_executor,
self.claude_executor,
self.user_interaction,
self.git_operations,
self.subprocess,
self.test_config,
)
}
}
impl OrchestratorBuilder {
pub fn create_env_config(workflow: &WorkflowConfig) -> EnvironmentConfig {
EnvironmentConfig {
global_env: workflow
.env
.as_ref()
.map(|env| {
env.iter()
.map(|(k, v)| (k.clone(), EnvValue::Static(v.clone())))
.collect()
})
.unwrap_or_default(),
secrets: workflow.secrets.clone().unwrap_or_default(),
env_files: workflow.env_files.clone().unwrap_or_default(),
inherit: true,
profiles: workflow.profiles.clone().unwrap_or_default(),
active_profile: None,
}
}
}
pub trait OrchestratorConfigHelpers {
fn create_workflow_executor(&self, config: &CookConfig) -> WorkflowExecutorImpl;
fn create_workflow_state_base(
&self,
config: &CookConfig,
) -> (PathBuf, Vec<String>, Vec<String>);
}
impl OrchestratorConfigHelpers for DefaultCookOrchestrator {
fn create_workflow_executor(&self, config: &CookConfig) -> WorkflowExecutorImpl {
self.create_workflow_executor_internal(config)
}
fn create_workflow_state_base(
&self,
config: &CookConfig,
) -> (PathBuf, Vec<String>, Vec<String>) {
super::construction::create_workflow_state_base(&config.command)
}
}