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
//! Pipeline Phase Orchestration Module
//!
//! This module contains the execution logic for each phase of the Ralph pipeline.
//! Phases are invoked by the reducer architecture via effects, keeping business
//! logic (when to transition) separate from execution logic (how to execute).
//!
//! # Pipeline Phases
//!
//! Ralph runs four sequential phases:
//!
//! ```text
//! ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
//! │ Planning │ ──▶ │ Development │ ──▶ │ Review │ ──▶ │ Commit │
//! │ │ │ │ │ │ │ │
//! │ Creates PLAN │ │ Implements │ │ Reviews code │ │ Generates │
//! │ from PROMPT │ │ iterations │ │ and fixes │ │ commit msg │
//! └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘
//! ```
//!
//! ## Planning Phase
//!
//! Reads `PROMPT.md` and generates `.agent/PLAN.md` via AI agent.
//! The plan guides subsequent development iterations.
//!
//! ## Development Phase
//!
//! Executes N iterations (configurable via `-D`) where the agent:
//! 1. Reads `PROMPT.md` and `PLAN.md`
//! 2. Implements changes
//! 3. Commits after each iteration (if changes detected)
//!
//! ## Review Phase
//!
//! Runs M review cycles (configurable via `-R`) where:
//! 1. Reviewer agent analyzes cumulative diff since pipeline start
//! 2. Creates `.agent/ISSUES.md` with findings
//! 3. Developer agent fixes issues
//! 4. Repeats until no issues or max cycles reached
//!
//! ## Commit Phase
//!
//! Generates a final commit message via AI, analyzing the full diff.
//! Falls back to intelligent heuristic-based message if AI fails.
//!
//! # Module Structure
//!
//! - [`context`] - Shared [`PhaseContext`] for passing state between phases
//! - [`development`] - Iterative development cycle execution
//! - [`review`] - Code review and fix cycle execution
//! - [`commit`] - Automated commit message generation
//! - [`integrity`] - File integrity verification
//!
//! # Integration with Reducer
//!
//! The reducer (see [`crate::reducer`]) determines which phase to execute via
//! [`crate::reducer::determine_next_effect`]. Phase modules are invoked by
//! effect handlers, returning events that update pipeline state.
//!
//! **Important**: Phase modules do NOT make control-flow decisions. They execute
//! their assigned task and return events. All decisions about phase transitions,
//! agent fallback, and retry behavior are made by the reducer based on events.
//!
//! # Phase Module Responsibilities
//!
//! Phase modules execute tasks and emit events. They do NOT:
//! - Make control flow decisions (no "if condition then skip phase")
//! - Read legacy artifact files to recover missing results
//! - Skip or advance phases based on file existence checks
//! - Perform implicit agent selection or fallback logic
//! - Trigger agent fallback directly (only the reducer does this)
//!
//! All phase transitions are made by the reducer based on events emitted by effects.
//!
//! # Note on Re-exports
//!
//! The functions below are public for use by the reducer architecture.
//! They were previously private module internals.
pub use ;
pub use ;
pub use ;