ralph_workflow/reducer/event/development.rs
1//! Development events.
2
3use crate::reducer::state::DevelopmentStatus;
4use serde::{Deserialize, Serialize};
5
6/// Development phase events.
7///
8/// Events related to development iterations, including continuation handling
9/// for partial/failed completion states. Development iterations involve
10/// invoking developer agents to make code changes.
11///
12/// # State Transitions
13///
14/// - `PhaseStarted`: Sets phase to Development
15/// - `IterationStarted`: Resets agent chain, clears continuation state
16/// - `IterationCompleted(output_valid=true)`: Transitions to CommitMessage
17/// - `IterationCompleted(output_valid=false)`: Stays in Development for retry
18/// - `ContinuationTriggered`: Saves context for continuation attempt
19/// - `ContinuationSucceeded`: Clears continuation, proceeds to CommitMessage
20/// - `PhaseCompleted`: Transitions to Review
21#[derive(Clone, Serialize, Deserialize, Debug)]
22pub enum DevelopmentEvent {
23 /// Development phase has started.
24 PhaseStarted,
25 /// A development iteration has started.
26 IterationStarted {
27 /// The iteration number starting.
28 iteration: u32,
29 },
30
31 /// Development context prepared for an iteration.
32 ///
33 /// Emitted after `Effect::PrepareDevelopmentContext` completes.
34 ContextPrepared {
35 /// The iteration number the context was prepared for.
36 iteration: u32,
37 },
38
39 /// Development prompt prepared for an iteration.
40 ///
41 /// Emitted after `Effect::PrepareDevelopmentPrompt` completes.
42 PromptPrepared {
43 /// The iteration number the prompt was prepared for.
44 iteration: u32,
45 },
46
47 /// Developer agent was invoked for an iteration.
48 ///
49 /// Emitted after `Effect::InvokeDevelopmentAgent` completes.
50 AgentInvoked {
51 /// The iteration number the agent was invoked for.
52 iteration: u32,
53 },
54
55 /// Analysis agent was invoked to verify development results for an iteration.
56 ///
57 /// Emitted after `Effect::InvokeAnalysisAgent` completes. The analysis agent
58 /// produces `development_result.xml` by comparing git diff against PLAN.md.
59 AnalysisAgentInvoked {
60 /// The iteration number the analysis agent was invoked for.
61 iteration: u32,
62 },
63
64 /// Development result XML exists and was read successfully for the iteration.
65 ///
66 /// Emitted after `Effect::ExtractDevelopmentXml` completes.
67 XmlExtracted {
68 /// The iteration number the XML was extracted for.
69 iteration: u32,
70 },
71 /// Development result XML missing for an iteration.
72 ///
73 /// Emitted after `Effect::ExtractDevelopmentXml` when the XML was absent.
74 XmlMissing {
75 /// The iteration number the XML was extracted for.
76 iteration: u32,
77 /// The invalid output attempt count.
78 attempt: u32,
79 },
80
81 /// Development result XML validated for an iteration.
82 ///
83 /// This event captures the parsed development outcome.
84 XmlValidated {
85 /// The iteration number the XML was validated for.
86 iteration: u32,
87 /// The parsed development status.
88 status: DevelopmentStatus,
89 /// Summary of what was accomplished.
90 summary: String,
91 /// Files changed in this attempt.
92 files_changed: Option<Vec<String>>,
93 /// Agent's recommended next steps.
94 next_steps: Option<String>,
95 },
96
97 /// Development outcome applied for an iteration.
98 OutcomeApplied {
99 /// The iteration number the outcome was applied for.
100 iteration: u32,
101 },
102
103 /// Development result XML archived for an iteration.
104 ///
105 /// Emitted after `Effect::ArchiveDevelopmentXml` completes.
106 XmlArchived {
107 /// The iteration number the XML was archived for.
108 iteration: u32,
109 },
110 /// Development result XML cleaned before invoking the developer agent.
111 XmlCleaned {
112 /// The iteration number the XML was cleaned for.
113 iteration: u32,
114 },
115 /// A development iteration completed with validation result.
116 IterationCompleted {
117 /// The iteration number that completed.
118 iteration: u32,
119 /// Whether the output passed validation.
120 output_valid: bool,
121 },
122 /// Development phase completed, all iterations done.
123 PhaseCompleted,
124 /// Continuation triggered due to partial/failed status.
125 ///
126 /// Emitted only when development output is valid (parseable) but
127 /// status is not "completed" (i.e., "partial" or "failed").
128 ContinuationTriggered {
129 /// Current iteration number.
130 iteration: u32,
131 /// Status from the agent ("partial" or "failed").
132 status: DevelopmentStatus,
133 /// Summary of what was accomplished.
134 summary: String,
135 /// Files changed in this attempt.
136 files_changed: Option<Vec<String>>,
137 /// Agent's recommended next steps.
138 next_steps: Option<String>,
139 },
140 /// Continuation attempt succeeded with status "completed".
141 ContinuationSucceeded {
142 /// Current iteration number.
143 iteration: u32,
144 /// Number of continuation attempts it took.
145 total_continuation_attempts: u32,
146 },
147 /// Output validation failed (XSD/XML parsing error).
148 ///
149 /// Emitted when development output cannot be parsed or fails XSD validation.
150 /// The reducer decides whether to retry (same agent) or switch agents based
151 /// on the attempt count in state.
152 OutputValidationFailed {
153 /// Current iteration number.
154 iteration: u32,
155 /// Current invalid output attempt number.
156 attempt: u32,
157 },
158 /// Continuation attempts exhausted without reaching completed status.
159 ///
160 /// Emitted when development iteration has used all allowed continuation
161 /// attempts but still hasn't reached status="completed".
162 ContinuationBudgetExhausted {
163 /// Current iteration number.
164 iteration: u32,
165 /// Total continuation attempts made.
166 total_attempts: u32,
167 /// Last status received (Partial or Failed).
168 last_status: DevelopmentStatus,
169 },
170 /// Continuation context file was written successfully.
171 ///
172 /// Emitted after WriteContinuationContext effect completes. The reducer
173 /// clears the `needs_context_write` flag on this event.
174 ContinuationContextWritten {
175 /// Current iteration number.
176 iteration: u32,
177 /// Current continuation attempt number.
178 attempt: u32,
179 },
180 /// Continuation context file was cleaned up.
181 ///
182 /// Emitted after CleanupContinuationContext effect completes.
183 ContinuationContextCleaned,
184}