ralph_workflow/reducer/event/planning.rs
1//! Planning phase events.
2//!
3//! Events related to plan generation and validation within the Planning phase.
4//! The planning phase generates a plan for the current development iteration.
5
6use serde::{Deserialize, Serialize};
7
8/// Planning phase events.
9///
10/// Events related to plan generation and validation within the Planning phase.
11/// The planning phase generates a plan for the current development iteration.
12///
13/// # State Transitions
14///
15/// - `PhaseStarted`: Sets phase to Planning
16/// - `GenerationCompleted(valid=true)`: Transitions to Development
17/// - `GenerationCompleted(valid=false)`: Stays in Planning for retry
18/// - `PhaseCompleted`: Transitions to Development
19///
20/// # Emitted By
21///
22/// - Planning effect handlers in `handler/planning/`
23/// - XSD validation handlers
24/// - Markdown generation handlers
25#[derive(Clone, Serialize, Deserialize, Debug)]
26pub enum PlanningEvent {
27 /// Planning phase has started.
28 PhaseStarted,
29 /// Planning phase completed, ready to proceed.
30 PhaseCompleted,
31 /// Planning prompt prepared for an iteration.
32 PromptPrepared {
33 /// The iteration number this plan is for.
34 iteration: u32,
35 },
36 /// Planning agent invoked for an iteration.
37 AgentInvoked {
38 /// The iteration number this plan is for.
39 iteration: u32,
40 },
41 /// Planning XML extracted for an iteration.
42 PlanXmlExtracted {
43 /// The iteration number this plan is for.
44 iteration: u32,
45 },
46 /// Planning XML missing for an iteration.
47 PlanXmlMissing {
48 /// The iteration number this plan is for.
49 iteration: u32,
50 /// The invalid output attempt count.
51 attempt: u32,
52 },
53 /// Planning XML validated for an iteration.
54 PlanXmlValidated {
55 /// The iteration number this plan is for.
56 iteration: u32,
57 /// Whether the generated plan passed validation.
58 valid: bool,
59 /// Markdown generated from the validated plan XML.
60 markdown: Option<String>,
61 },
62 /// Planning markdown written for an iteration.
63 PlanMarkdownWritten {
64 /// The iteration number this plan is for.
65 iteration: u32,
66 },
67 /// Planning XML archived for an iteration.
68 PlanXmlArchived {
69 /// The iteration number this plan is for.
70 iteration: u32,
71 },
72 /// Planning XML cleaned before invoking the planning agent.
73 PlanXmlCleaned {
74 /// The iteration number this plan is for.
75 iteration: u32,
76 },
77 /// Plan generation completed with validation result.
78 ///
79 /// This event signals the end of the plan generation attempt.
80 /// The reducer uses the `valid` field to decide whether to:
81 /// - Transition to Development phase (valid=true)
82 /// - Retry with same agent or switch agents (valid=false)
83 GenerationCompleted {
84 /// The iteration number this plan was for.
85 iteration: u32,
86 /// Whether the generated plan passed validation.
87 valid: bool,
88 },
89
90 /// Output validation failed (missing/empty or otherwise invalid plan output).
91 ///
92 /// Emitted when planning output cannot be validated. The reducer decides
93 /// whether to retry (same agent) or switch agents based on the attempt count.
94 OutputValidationFailed {
95 /// Current iteration number.
96 iteration: u32,
97 /// Current invalid output attempt number.
98 attempt: u32,
99 },
100}