ralph_workflow/app/
finalization.rs

1//! Pipeline finalization and cleanup.
2//!
3//! This module handles the final phase of the pipeline including cleanup,
4//! final summary, and checkpoint clearing.
5
6use crate::banner::{print_final_summary, PipelineSummary};
7use crate::checkpoint::clear_checkpoint;
8use crate::config::Config;
9use crate::files::protection::monitoring::PromptMonitor;
10use crate::logger::Colors;
11use crate::logger::Logger;
12use crate::pipeline::Timer;
13use crate::pipeline::{AgentPhaseGuard, Stats};
14
15/// Finalizes the pipeline: cleans up and prints summary.
16///
17/// Commits now happen per-iteration during development and per-cycle during review,
18/// so this function only handles cleanup and final summary.
19pub fn finalize_pipeline(
20    agent_phase_guard: &mut AgentPhaseGuard,
21    logger: &Logger,
22    colors: Colors,
23    config: &Config,
24    timer: &Timer,
25    stats: &Stats,
26    prompt_monitor: Option<PromptMonitor>,
27) {
28    // Stop the PROMPT.md monitor if it was started
29    if let Some(monitor) = prompt_monitor {
30        monitor.stop();
31    }
32
33    // End agent phase and clean up
34    crate::git_helpers::end_agent_phase();
35    crate::git_helpers::disable_git_wrapper(agent_phase_guard.git_helpers);
36    if let Err(err) = crate::git_helpers::uninstall_hooks(logger) {
37        logger.warn(&format!("Failed to uninstall Ralph hooks: {err}"));
38    }
39
40    // Note: Individual commits were created per-iteration during development
41    // and per-cycle during review. The final commit phase has been removed.
42
43    // Final summary
44    let summary = PipelineSummary {
45        total_time: timer.elapsed_formatted(),
46        dev_runs_completed: stats.developer_runs_completed as usize,
47        dev_runs_total: config.developer_iters as usize,
48        review_runs: stats.reviewer_runs_completed as usize,
49        changes_detected: stats.changes_detected as usize,
50        isolation_mode: config.isolation_mode,
51        verbose: config.verbosity.is_verbose(),
52        review_summary: None,
53    };
54    print_final_summary(colors, &summary, logger);
55
56    if config.features.checkpoint_enabled {
57        if let Err(err) = clear_checkpoint() {
58            logger.warn(&format!("Failed to clear checkpoint: {err}"));
59        }
60    }
61
62    agent_phase_guard.disarm();
63}