Skip to main content

ralph_workflow/cli/handlers/
dry_run.rs

1//! Dry run command handler.
2//!
3//! This module provides validation of Ralph setup without running any agents.
4
5use crate::checkpoint::{checkpoint_exists_with_workspace, load_checkpoint_with_workspace};
6use crate::config::Config;
7use crate::files::validate_prompt_md_with_workspace;
8use crate::language_detector::detect_stack_summary;
9use crate::logger::Logger;
10use crate::workspace::Workspace;
11use std::path::Path;
12
13/// Handle --dry-run command.
14///
15/// Validates the setup without running any agents:
16/// - Checks PROMPT.md exists and has required sections
17/// - Validates agent configuration
18/// - Reports detected project stack
19/// - Shows checkpoint status if available
20///
21/// # Arguments
22///
23/// * `logger` - Logger for status output
24/// * `_colors` - Color configuration (unused but kept for API consistency)
25/// * `config` - The current Ralph configuration
26/// * `developer_agent` - Name of the developer agent
27/// * `reviewer_agent` - Name of the reviewer agent
28/// * `repo_root` - Path to the repository root
29/// * `workspace` - Workspace for explicit file operations
30///
31/// # Returns
32///
33/// Returns `Ok(())` if validation passes, or an error if PROMPT.md validation fails.
34pub fn handle_dry_run(
35    logger: &Logger,
36    _colors: crate::logger::Colors,
37    config: &Config,
38    developer_agent: &str,
39    reviewer_agent: &str,
40    repo_root: &Path,
41    workspace: &dyn Workspace,
42) -> anyhow::Result<()> {
43    logger.header("DRY RUN: Validation", crate::logger::Colors::cyan);
44
45    // Validate PROMPT.md using the utility function
46    // Dry run is non-interactive by definition
47    let validation =
48        validate_prompt_md_with_workspace(workspace, config.behavior.strict_validation, false);
49
50    // Report errors first
51    for err in &validation.errors {
52        logger.error(err);
53    }
54
55    // Report warnings
56    for warn in &validation.warnings {
57        logger.warn(&format!("{warn} (recommended)"));
58    }
59
60    // Bail if validation failed
61    if !validation.is_valid() {
62        anyhow::bail!("Dry run failed: PROMPT.md validation errors");
63    }
64
65    // Report successes
66    if validation.has_goal {
67        logger.success("PROMPT.md has Goal section");
68    }
69    if validation.has_acceptance {
70        logger.success("PROMPT.md has acceptance checks section");
71    }
72    if validation.is_perfect() {
73        logger.success("PROMPT.md validation passed with no warnings");
74    }
75
76    logger.success(&format!("Developer agent: {developer_agent}"));
77    logger.success(&format!("Reviewer agent: {reviewer_agent}"));
78    logger.success(&format!("Developer iterations: {}", config.developer_iters));
79    logger.success(&format!("Reviewer passes: {}", config.reviewer_reviews));
80
81    // Check for checkpoint
82    if checkpoint_exists_with_workspace(workspace) {
83        logger.info("Checkpoint found - can resume with --resume");
84        if let Ok(Some(cp)) = load_checkpoint_with_workspace(workspace) {
85            logger.info(&format!("  Phase: {}", cp.phase));
86            logger.info(&format!("  Progress: {}", cp.description()));
87            logger.info(&format!("  Saved at: {}", cp.timestamp));
88        }
89    }
90
91    // Detect stack - use the convenience function for simple display
92    logger.success(&format!(
93        "Detected stack: {}",
94        detect_stack_summary(repo_root)
95    ));
96
97    logger.success("Dry run validation complete");
98    Ok(())
99}