ralph_workflow/reducer/event/commit.rs
1//! Commit generation events.
2//!
3//! Events related to commit message generation, validation, and creation.
4
5use serde::{Deserialize, Serialize};
6
7/// Commit generation events.
8///
9/// Events related to commit message generation, validation, and creation.
10/// Commit generation occurs after development iterations and review fixes.
11///
12/// # State Machine
13///
14/// ```text
15/// NotStarted -> Generating -> Generated -> Committed
16/// | |
17/// +--> (retry) --+
18/// |
19/// +--> Skipped
20/// ```
21///
22/// # Emitted By
23///
24/// - Commit generation handlers in `handler/commit/`
25/// - Commit message validation handlers
26/// - Git commit handlers
27#[derive(Clone, Serialize, Deserialize, Debug)]
28pub enum CommitEvent {
29 /// Commit message generation started.
30 GenerationStarted,
31 /// Commit diff computed for commit generation.
32 ///
33 /// Emitted after preparing the diff that will be committed. The reducer
34 /// uses the `empty` flag to decide whether to skip commit creation.
35 DiffPrepared {
36 /// True when the diff is empty.
37 empty: bool,
38 /// Content identifier (sha256 hex) of the prepared diff content.
39 ///
40 /// This is used to guard against reusing stale materialized inputs when the
41 /// diff content changes across checkpoints or retries.
42 content_id_sha256: String,
43 },
44 /// Commit diff computation failed.
45 DiffFailed {
46 /// The error message for the diff failure.
47 error: String,
48 },
49 /// Commit diff is no longer available and must be recomputed.
50 ///
51 /// This is used for recoverability when `.agent/tmp` artifacts are cleaned between
52 /// checkpoints or when required diff files go missing during resume.
53 DiffInvalidated {
54 /// Reason for invalidation.
55 reason: String,
56 },
57 /// Commit prompt prepared for a commit attempt.
58 PromptPrepared {
59 /// The attempt number.
60 attempt: u32,
61 },
62 /// Commit agent invoked for a commit attempt.
63 AgentInvoked {
64 /// The attempt number.
65 attempt: u32,
66 },
67 /// Commit message XML extracted for a commit attempt.
68 CommitXmlExtracted {
69 /// The attempt number.
70 attempt: u32,
71 },
72 /// Commit message XML missing for a commit attempt.
73 CommitXmlMissing {
74 /// The attempt number.
75 attempt: u32,
76 },
77 /// Commit message XML validated successfully.
78 CommitXmlValidated {
79 /// The generated commit message.
80 message: String,
81 /// The attempt number.
82 attempt: u32,
83 },
84 /// Commit message XML validation failed.
85 CommitXmlValidationFailed {
86 /// The reason for validation failure.
87 reason: String,
88 /// The attempt number.
89 attempt: u32,
90 },
91 /// Commit message XML archived.
92 CommitXmlArchived {
93 /// The attempt number.
94 attempt: u32,
95 },
96 /// Commit message XML cleaned before invoking the commit agent.
97 CommitXmlCleaned {
98 /// The attempt number.
99 attempt: u32,
100 },
101 /// Commit message was generated.
102 MessageGenerated {
103 /// The generated commit message.
104 message: String,
105 /// The attempt number.
106 attempt: u32,
107 },
108 /// Commit message validation failed.
109 MessageValidationFailed {
110 /// The reason for validation failure.
111 reason: String,
112 /// The attempt number that failed.
113 attempt: u32,
114 },
115 /// Commit was created successfully.
116 Created {
117 /// The commit hash.
118 hash: String,
119 /// The commit message used.
120 message: String,
121 },
122 /// Commit generation failed completely.
123 GenerationFailed {
124 /// The reason for failure.
125 reason: String,
126 },
127 /// Commit was skipped (e.g., no changes to commit).
128 Skipped {
129 /// The reason for skipping.
130 reason: String,
131 },
132}