paladin-ai 0.4.1

Enterprise AI orchestration framework with multi-agent coordination patterns
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
//! Onboarding wizard command
//!
//! Interactive wizard to guide new users through Paladin setup

use crate::application::cli::error::{CliError, CliResult};
use crate::application::cli::formatters::output::OutputFormatter;
use crate::application::cli::formatters::progress::Spinner;
use crate::application::cli::interactive::prompts::PromptBuilder;
use crate::application::cli::interactive::wizard::{StepResult, Wizard, WizardContext, WizardStep};
use crate::application::cli::templates::env::EnvTemplate;
use reqwest::Client;
use serde_json::json;
use std::collections::HashMap;
use std::path::PathBuf;
use std::time::Duration;

// Constants for context keys
const KEY_SELECTED_PROVIDERS: &str = "selected_providers";
const KEY_API_KEYS_PREFIX: &str = "api_key_";
const KEY_CREATE_SAMPLES: &str = "create_samples";
const KEY_ENV_ACTION: &str = "env_action";

/// LLM Provider types
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum Provider {
    OpenAI,
    Anthropic,
    DeepSeek,
}

impl Provider {
    fn name(&self) -> &'static str {
        match self {
            Provider::OpenAI => "OpenAI",
            Provider::Anthropic => "Anthropic",
            Provider::DeepSeek => "DeepSeek",
        }
    }

    fn env_var(&self) -> &'static str {
        match self {
            Provider::OpenAI => "OPENAI_API_KEY",
            Provider::Anthropic => "ANTHROPIC_API_KEY",
            Provider::DeepSeek => "DEEPSEEK_API_KEY",
        }
    }

    fn all() -> Vec<Self> {
        vec![Provider::OpenAI, Provider::Anthropic, Provider::DeepSeek]
    }

    fn from_name(name: &str) -> Option<Self> {
        match name {
            "OpenAI" => Some(Provider::OpenAI),
            "Anthropic" => Some(Provider::Anthropic),
            "DeepSeek" => Some(Provider::DeepSeek),
            _ => None,
        }
    }
}

// API Validation Functions

/// Validate OpenAI API key by calling the models endpoint
async fn validate_openai_key(api_key: &str) -> CliResult<()> {
    let client = Client::builder()
        .timeout(Duration::from_secs(10))
        .build()
        .map_err(|e| CliError::execution(format!("Failed to create HTTP client: {}", e)))?;

    let response = client
        .get("https://api.openai.com/v1/models")
        .header("Authorization", format!("Bearer {}", api_key))
        .send()
        .await
        .map_err(|e| CliError::execution(format!("API request failed: {}", e)))?;

    if response.status().is_success() {
        Ok(())
    } else {
        let status = response.status();
        let error_text = response.text().await.unwrap_or_default();
        Err(CliError::execution(format!(
            "OpenAI API validation failed ({}): {}",
            status, error_text
        )))
    }
}

/// Validate Anthropic API key by making a minimal request
async fn validate_anthropic_key(api_key: &str) -> CliResult<()> {
    let client = Client::builder()
        .timeout(Duration::from_secs(10))
        .build()
        .map_err(|e| CliError::execution(format!("Failed to create HTTP client: {}", e)))?;

    // Anthropic uses x-api-key header
    let body = json!({
        "model": "claude-3-haiku-20240307",
        "max_tokens": 1,
        "messages": [{"role": "user", "content": "test"}]
    });

    let response = client
        .post("https://api.anthropic.com/v1/messages")
        .header("x-api-key", api_key)
        .header("anthropic-version", "2023-06-01")
        .header("content-type", "application/json")
        .json(&body)
        .send()
        .await
        .map_err(|e| CliError::execution(format!("API request failed: {}", e)))?;

    if response.status().is_success() {
        Ok(())
    } else {
        let status = response.status();
        let error_text = response.text().await.unwrap_or_default();
        Err(CliError::execution(format!(
            "Anthropic API validation failed ({}): {}",
            status, error_text
        )))
    }
}

/// Validate DeepSeek API key by calling the models endpoint
async fn validate_deepseek_key(api_key: &str) -> CliResult<()> {
    let client = Client::builder()
        .timeout(Duration::from_secs(10))
        .build()
        .map_err(|e| CliError::execution(format!("Failed to create HTTP client: {}", e)))?;

    let response = client
        .get("https://api.deepseek.com/v1/models")
        .header("Authorization", format!("Bearer {}", api_key))
        .send()
        .await
        .map_err(|e| CliError::execution(format!("API request failed: {}", e)))?;

    if response.status().is_success() {
        Ok(())
    } else {
        let status = response.status();
        let error_text = response.text().await.unwrap_or_default();
        Err(CliError::execution(format!(
            "DeepSeek API validation failed ({}): {}",
            status, error_text
        )))
    }
}

/// Generate sample configuration files
fn generate_sample_configs(provider: &str) -> CliResult<()> {
    use crate::application::cli::templates::battalion_template::generate_battalion_template;
    use crate::application::cli::templates::paladin_template::generate_paladin_template;
    use std::fs;

    // Create examples directory if it doesn't exist
    let examples_dir = PathBuf::from("examples");
    fs::create_dir_all(&examples_dir)
        .map_err(|e| CliError::execution(format!("Failed to create examples directory: {}", e)))?;

    // Generate basic_paladin.yaml
    let basic_paladin = generate_paladin_template("Assistant", provider);
    let basic_path = examples_dir.join("basic_paladin.yaml");
    fs::write(&basic_path, basic_paladin)
        .map_err(|e| CliError::execution(format!("Failed to write basic_paladin.yaml: {}", e)))?;

    // Generate formation.yaml
    let formation = generate_battalion_template("AnalysisPipeline", "formation").map_err(|e| {
        CliError::execution(format!("Failed to generate formation template: {}", e))
    })?;
    let formation_path = examples_dir.join("formation.yaml");
    fs::write(&formation_path, formation)
        .map_err(|e| CliError::execution(format!("Failed to write formation.yaml: {}", e)))?;

    // Generate phalanx.yaml
    let phalanx = generate_battalion_template("ParallelProcessors", "phalanx")
        .map_err(|e| CliError::execution(format!("Failed to generate phalanx template: {}", e)))?;
    let phalanx_path = examples_dir.join("phalanx.yaml");
    fs::write(&phalanx_path, phalanx)
        .map_err(|e| CliError::execution(format!("Failed to write phalanx.yaml: {}", e)))?;

    // Generate paladin_with_rag.yaml - enhanced version with garrison
    let rag_paladin = format!(
        r#"# Paladin with RAG Configuration
# This Paladin includes Garrison (memory) for context retention

name: "RAGAssistant"

system_prompt: |
  You are a knowledgeable AI assistant with access to conversation history.
  Use previous context to provide more relevant and contextual responses.
  Reference prior information when appropriate.

model: "{model}"

temperature: 0.7
max_loops: 3
timeout_seconds: 300

provider:
  type: {provider}

# Enable Garrison for context/memory
garrison:
  type: sqlite
  config:
    path: "./garrison.db"
    max_entries: 100

# Optional: Add Arsenal for tool access
# arsenal:
#   mcp_servers:
#     - name: web_search
#       type: stdio
#       command: uvx
#       args:
#         - mcp-web-search
"#,
        model = match provider {
            "openai" => "gpt-4",
            "deepseek" => "deepseek-chat",
            "anthropic" => "claude-3-5-sonnet-20241022",
            _ => "gpt-4",
        },
        provider = provider
    );
    let rag_path = examples_dir.join("paladin_with_rag.yaml");
    fs::write(&rag_path, rag_paladin).map_err(|e| {
        CliError::execution(format!("Failed to write paladin_with_rag.yaml: {}", e))
    })?;

    Ok(())
}

// Welcome Step
struct WelcomeStep;

impl WizardStep for WelcomeStep {
    fn execute(&self, _context: &mut WizardContext) -> CliResult<StepResult> {
        let formatter = OutputFormatter::new();

        formatter.header("Welcome to Paladin! 🛡️");
        println!();
        formatter.success("Let's get you set up with a multi-agent orchestration framework.");
        println!();

        println!("This wizard will help you:");
        println!("  • Configure LLM provider API keys");
        println!("  • Set up your environment file");
        println!("  • Validate API connectivity");
        println!("  • Generate sample configurations");
        println!();

        let continue_prompt = PromptBuilder::confirm("Ready to begin?")
            .with_default(true)
            .prompt()?;

        if continue_prompt {
            Ok(StepResult::Continue)
        } else {
            formatter.warning("Onboarding cancelled. Run 'paladin onboarding' anytime to restart.");
            Ok(StepResult::Cancel)
        }
    }

    fn name(&self) -> &str {
        "Welcome"
    }
}

// Provider Selection Step
struct ProviderSelectionStep;

impl WizardStep for ProviderSelectionStep {
    fn execute(&self, context: &mut WizardContext) -> CliResult<StepResult> {
        let formatter = OutputFormatter::new();

        formatter.header("LLM Provider Selection");
        println!();
        println!("Select one or more LLM providers to configure:");
        println!();

        let provider_options: Vec<String> = Provider::all()
            .iter()
            .map(|p| p.name().to_string())
            .collect();

        let selections = PromptBuilder::multi_select(
            "Select providers (use Space to select, Enter to confirm)",
            provider_options.clone(),
        )
        .with_defaults(vec![true, false, false])
        .prompt()?;

        if selections.is_empty() {
            formatter.error("At least one provider must be selected.");
            return Ok(StepResult::Continue); // Retry this step
        }

        // selections are already the provider names (Vec<String>), not indices
        context.set(KEY_SELECTED_PROVIDERS, selections.join(","));
        let selected_names = selections;

        formatter.success(&format!(
            "Selected providers: {}",
            selected_names.join(", ")
        ));
        println!();

        Ok(StepResult::Continue)
    }

    fn name(&self) -> &str {
        "Provider Selection"
    }
}

// API Key Input Step
struct ApiKeyInputStep;

impl WizardStep for ApiKeyInputStep {
    fn execute(&self, context: &mut WizardContext) -> CliResult<StepResult> {
        let formatter = OutputFormatter::new();

        formatter.header("API Key Configuration");
        println!();

        let provider_names = context
            .get(KEY_SELECTED_PROVIDERS)
            .ok_or_else(|| CliError::configuration("No providers selected".to_string()))?;

        let providers: Vec<Provider> = provider_names
            .split(',')
            .filter_map(Provider::from_name)
            .collect();

        let mut keys_configured = 0;

        for provider in &providers {
            println!("Enter your {} API key:", provider.name());

            let key =
                PromptBuilder::password(&format!("{}_API_KEY", provider.name().to_uppercase()))
                    .prompt()?;

            if key.is_empty() {
                formatter.warning(&format!("Skipping {} (no key provided)", provider.name()));
                continue;
            }

            // Store API key in context
            context.set(format!("{}{}", KEY_API_KEYS_PREFIX, provider.name()), key);
            keys_configured += 1;
        }

        if keys_configured == 0 {
            formatter.error("No API keys provided. At least one is required.");
            return Ok(StepResult::Continue); // Retry
        }

        println!();
        formatter.success(&format!("Configured {} API key(s)", keys_configured));
        println!();

        Ok(StepResult::Continue)
    }

    fn name(&self) -> &str {
        "API Key Input"
    }
}

// API Validation Step
struct ApiValidationStep;

impl WizardStep for ApiValidationStep {
    fn execute(&self, context: &mut WizardContext) -> CliResult<StepResult> {
        let formatter = OutputFormatter::new();

        formatter.header("API Validation");
        println!();
        println!("Testing API connectivity...");
        println!();

        let provider_names = context
            .get(KEY_SELECTED_PROVIDERS)
            .ok_or_else(|| CliError::configuration("No providers selected".to_string()))?;

        let providers: Vec<Provider> = provider_names
            .split(',')
            .filter_map(Provider::from_name)
            .collect();

        for provider in &providers {
            let key_name = format!("{}{}", KEY_API_KEYS_PREFIX, provider.name());
            if let Some(api_key) = context.get(&key_name) {
                let spinner = Spinner::new(format!("Validating {}...", provider.name()));

                // Validate API key with actual API call
                let validation_result = tokio::task::block_in_place(|| {
                    tokio::runtime::Handle::current().block_on(async {
                        match provider {
                            Provider::OpenAI => validate_openai_key(api_key).await,
                            Provider::Anthropic => validate_anthropic_key(api_key).await,
                            Provider::DeepSeek => validate_deepseek_key(api_key).await,
                        }
                    })
                });

                match validation_result {
                    Ok(_) => {
                        spinner.finish_with_message(format!("{}", provider.name()));
                    }
                    Err(e) => {
                        spinner.finish_with_message(format!("{}", provider.name()));
                        formatter.error(&format!("Validation failed: {}", e));
                        println!();
                        formatter.warning("You can continue setup, but verify your API key later.");
                        println!();
                    }
                }
            }
        }

        println!();
        formatter.success("All API keys validated successfully!");
        println!();

        Ok(StepResult::Continue)
    }

    fn name(&self) -> &str {
        "API Validation"
    }
}

// Environment File Step
struct EnvFileStep;

impl WizardStep for EnvFileStep {
    fn execute(&self, context: &mut WizardContext) -> CliResult<StepResult> {
        let formatter = OutputFormatter::new();

        formatter.header("Environment File Setup");
        println!();

        let env_path = PathBuf::from(".env");
        let env_exists = env_path.exists();

        let action = if env_exists {
            formatter.warning(&format!("Found existing file: {}", env_path.display()));
            println!();

            let choice = PromptBuilder::select(
                "How should we proceed?",
                vec![
                    "Overwrite (replace existing file)".to_string(),
                    "Skip (keep existing file)".to_string(),
                    "Merge (combine configurations)".to_string(),
                ],
            )
            .prompt_index()?;

            match choice {
                0 => "overwrite".to_string(),
                1 => "skip".to_string(),
                2 => "merge".to_string(),
                _ => "skip".to_string(),
            }
        } else {
            println!("Creating new .env file...");
            "overwrite".to_string()
        };

        context.set(KEY_ENV_ACTION, &action);

        match action.as_str() {
            "skip" => {
                formatter.info("Keeping existing .env file");
            }
            "overwrite" | "merge" => {
                write_env_file(context, action.as_str() == "merge")?;
                formatter.success(if action.as_str() == "merge" {
                    "Merged with existing .env file"
                } else {
                    "Created .env file"
                });
            }
            _ => {}
        }

        println!();
        Ok(StepResult::Continue)
    }

    fn name(&self) -> &str {
        "Environment File"
    }
}

// Sample Configurations Step
struct SampleConfigsStep;

impl WizardStep for SampleConfigsStep {
    fn execute(&self, context: &mut WizardContext) -> CliResult<StepResult> {
        let formatter = OutputFormatter::new();

        formatter.header("Sample Configurations");
        println!();

        let create = PromptBuilder::confirm("Create sample configuration files?")
            .with_default(true)
            .prompt()?;

        if create {
            let spinner = Spinner::new("Generating samples...");

            // Get the first configured provider for sample generation
            let provider = context
                .get(KEY_SELECTED_PROVIDERS)
                .and_then(|providers| providers.split(',').next().map(String::from))
                .unwrap_or_else(|| "openai".to_string())
                .to_lowercase();

            // Generate sample configuration files
            let result = generate_sample_configs(&provider);

            match result {
                Ok(_) => {
                    spinner.finish_with_message("Sample files created");

                    println!();
                    println!("  • examples/basic_paladin.yaml");
                    println!("  • examples/formation.yaml");
                    println!("  • examples/phalanx.yaml");
                    println!("  • examples/paladin_with_rag.yaml");

                    context.set(KEY_CREATE_SAMPLES, "true");
                }
                Err(e) => {
                    spinner.finish_with_message("Failed to create samples");
                    formatter.error(&format!("Error generating samples: {}", e));
                    formatter.warning("You can manually create configuration files later.");
                }
            }
        } else {
            formatter.info("Skipped sample generation");
        }

        println!();
        Ok(StepResult::Continue)
    }

    fn name(&self) -> &str {
        "Sample Configurations"
    }
}

// Summary Step
struct SummaryStep;

impl WizardStep for SummaryStep {
    fn execute(&self, context: &mut WizardContext) -> CliResult<StepResult> {
        let formatter = OutputFormatter::new();

        formatter.header("Setup Complete! 🎉");
        println!();

        formatter.success("Your Paladin environment is ready!");
        println!();

        println!("Completed:");

        if let Some(providers) = context.get(KEY_SELECTED_PROVIDERS) {
            let count = providers.split(',').count();
            println!("  ✓ Configured {} LLM provider(s)", count);
        }

        if context.get(KEY_ENV_ACTION).is_some() {
            println!("  ✓ Created/updated .env file");
        }

        if context.contains(KEY_CREATE_SAMPLES) {
            println!("  ✓ Generated sample configurations");
        }

        println!();
        formatter.box_message(&[
            "Next Steps:",
            "1. Run 'paladin setup-check' to verify your configuration",
            "2. Try the examples in the examples/ directory",
            "3. Run 'paladin features' to explore available commands",
            "4. Read the docs at https://github.com/DF3NDR/paladin",
        ]);

        println!();
        Ok(StepResult::Complete)
    }

    fn name(&self) -> &str {
        "Summary"
    }
}

/// Write .env file with API keys
fn write_env_file(context: &WizardContext, merge: bool) -> CliResult<()> {
    let provider_names = context
        .get(KEY_SELECTED_PROVIDERS)
        .ok_or_else(|| CliError::configuration("No providers selected".to_string()))?;

    let providers: Vec<Provider> = provider_names
        .split(',')
        .filter_map(Provider::from_name)
        .collect();

    // Collect API keys
    let mut api_keys = HashMap::new();
    for provider in providers {
        let key_name = format!("{}{}", KEY_API_KEYS_PREFIX, provider.name());
        if let Some(key) = context.get(&key_name) {
            api_keys.insert(provider.env_var().to_string(), key.to_string());
        }
    }

    let existing_content = if merge {
        std::fs::read_to_string(".env").ok()
    } else {
        None
    };

    let template = EnvTemplate::new();
    let content = template
        .generate(&api_keys, existing_content.as_deref())
        .map_err(|e| CliError::configuration(format!("Template error: {}", e)))?;

    std::fs::write(".env", content)?;

    Ok(())
}

/// Run the onboarding wizard
pub async fn run_onboarding() -> CliResult<()> {
    let wizard = Wizard::new()
        .add_step(Box::new(WelcomeStep))
        .add_step(Box::new(ProviderSelectionStep))
        .add_step(Box::new(ApiKeyInputStep))
        .add_step(Box::new(ApiValidationStep))
        .add_step(Box::new(EnvFileStep))
        .add_step(Box::new(SampleConfigsStep))
        .add_step(Box::new(SummaryStep))
        .with_resume();

    // Run wizard
    wizard.run().map_err(|e| CliError::Other(e.to_string()))?;

    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;
    use tokio;

    #[test]
    fn test_provider_enum_name() {
        assert_eq!(Provider::OpenAI.name(), "OpenAI");
        assert_eq!(Provider::Anthropic.name(), "Anthropic");
        assert_eq!(Provider::DeepSeek.name(), "DeepSeek");
    }

    #[test]
    fn test_provider_env_var() {
        assert_eq!(Provider::OpenAI.env_var(), "OPENAI_API_KEY");
        assert_eq!(Provider::Anthropic.env_var(), "ANTHROPIC_API_KEY");
        assert_eq!(Provider::DeepSeek.env_var(), "DEEPSEEK_API_KEY");
    }

    #[test]
    fn test_provider_from_name() {
        assert_eq!(Provider::from_name("OpenAI"), Some(Provider::OpenAI));
        assert_eq!(Provider::from_name("Anthropic"), Some(Provider::Anthropic));
        assert_eq!(Provider::from_name("DeepSeek"), Some(Provider::DeepSeek));
        assert_eq!(Provider::from_name("Invalid"), None);
    }

    #[test]
    fn test_provider_all() {
        let providers = Provider::all();
        assert_eq!(providers.len(), 3);
        assert!(providers.contains(&Provider::OpenAI));
        assert!(providers.contains(&Provider::Anthropic));
        assert!(providers.contains(&Provider::DeepSeek));
    }

    #[tokio::test]
    #[ignore] // Requires valid API key
    async fn test_validate_openai_key_invalid() {
        let result = validate_openai_key("invalid-key-12345").await;
        assert!(result.is_err());
    }

    #[tokio::test]
    #[ignore] // Requires valid API key
    async fn test_validate_anthropic_key_invalid() {
        let result = validate_anthropic_key("invalid-key-12345").await;
        assert!(result.is_err());
    }

    #[tokio::test]
    #[ignore] // Requires valid API key
    async fn test_validate_deepseek_key_invalid() {
        let result = validate_deepseek_key("invalid-key-12345").await;
        assert!(result.is_err());
    }

    #[test]
    fn test_generate_sample_configs() {
        use std::fs;
        use tempfile::TempDir;

        // Create temporary directory for testing
        let temp_dir = TempDir::new().unwrap();
        let original_dir = std::env::current_dir().unwrap();

        // Change to temp directory
        std::env::set_current_dir(temp_dir.path()).unwrap();

        // Test generation for each provider
        for provider in &["openai", "anthropic", "deepseek"] {
            let result = generate_sample_configs(provider);
            assert!(
                result.is_ok(),
                "Failed to generate configs for {}",
                provider
            );

            // Verify files were created
            assert!(temp_dir.path().join("examples/basic_paladin.yaml").exists());
            assert!(temp_dir.path().join("examples/formation.yaml").exists());
            assert!(temp_dir.path().join("examples/phalanx.yaml").exists());
            assert!(
                temp_dir
                    .path()
                    .join("examples/paladin_with_rag.yaml")
                    .exists()
            );

            // Clean up for next iteration
            fs::remove_dir_all(temp_dir.path().join("examples")).unwrap();
        }

        // Restore original directory
        std::env::set_current_dir(original_dir).unwrap();
    }

    #[test]
    fn test_wizard_step_names() {
        assert_eq!(WelcomeStep.name(), "Welcome");
        assert_eq!(ProviderSelectionStep.name(), "Provider Selection");
        assert_eq!(ApiKeyInputStep.name(), "API Key Input");
        assert_eq!(ApiValidationStep.name(), "API Validation");
        assert_eq!(EnvFileStep.name(), "Environment File");
        assert_eq!(SampleConfigsStep.name(), "Sample Configurations");
        assert_eq!(SummaryStep.name(), "Summary");
    }
}