Skip to main content

ralph_workflow/reducer/state/pipeline/
phase_fields.rs

1// Phase-specific validated outcome types.
2//
3// These structures capture the validated results from each pipeline phase
4// after XML parsing and schema validation. They represent the contract
5// between agent output and reducer state.
6
7/// Reason why a file was excluded from a selective commit.
8///
9/// Used in `<ralph-excluded-files>` XML elements to record why the commit
10/// agent chose to omit a file. This metadata is audit/observability only
11/// and does not change commit execution semantics.
12#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
13#[serde(rename_all = "kebab-case")]
14pub enum ExcludedFileReason {
15    /// File is a Ralph-internal artifact (logs, tmp outputs).
16    ///
17    /// This is audit/observability metadata only; commit execution ignores it.
18    /// A separate, deterministic artifact-ignore mechanism may use this reason
19    /// to manage a Ralph-local ignore layer (e.g., `.git/info/exclude`).
20    InternalIgnore,
21    /// File is unrelated to the current task and is intentionally deferred.
22    NotTaskRelated,
23    /// File contains sensitive content that must not be committed.
24    Sensitive,
25    /// File could not be committed in this pass; carried forward to the next cycle.
26    Deferred,
27}
28
29/// A single file that was excluded from a selective commit, with a reason.
30///
31/// Populated from `<ralph-excluded-file reason="...">path</ralph-excluded-file>`
32/// elements inside `<ralph-excluded-files>` in the commit XML output.
33#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
34pub struct ExcludedFile {
35    /// Repo-relative path of the excluded file.
36    pub path: String,
37    /// Why this file was excluded from the commit.
38    pub reason: ExcludedFileReason,
39}
40
41#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
42pub struct ReviewValidatedOutcome {
43    pub pass: u32,
44    pub issues_found: bool,
45    pub clean_no_issues: bool,
46    /// Issues found during review. Box<[String]> saves 8 bytes per instance
47    /// vs Vec<String> (no separate capacity field) since this collection
48    /// never grows after construction.
49    #[serde(default)]
50    pub issues: Box<[String]>,
51    #[serde(default)]
52    pub no_issues_found: Option<String>,
53}
54
55#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
56pub struct PlanningValidatedOutcome {
57    pub iteration: u32,
58    pub valid: bool,
59    #[serde(default)]
60    pub markdown: Option<String>,
61}
62
63#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
64pub struct DevelopmentValidatedOutcome {
65    pub iteration: u32,
66    pub status: DevelopmentStatus,
67    pub summary: String,
68    /// Files changed during development. Option<Box<[String]>> saves 8 bytes
69    /// per instance vs Option<Vec<String>> when Some, and is None when empty
70    /// to avoid allocation entirely.
71    pub files_changed: Option<Box<[String]>>,
72    pub next_steps: Option<String>,
73}
74
75#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
76pub struct FixValidatedOutcome {
77    pub pass: u32,
78    pub status: FixStatus,
79    pub summary: Option<String>,
80}
81
82#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
83pub struct CommitValidatedOutcome {
84    pub attempt: u32,
85    pub message: Option<String>,
86    pub reason: Option<String>,
87}
88
89#[derive(Clone, Serialize, Deserialize, Debug, Default)]
90pub struct PromptInputsState {
91    #[serde(default)]
92    pub planning: Option<MaterializedPlanningInputs>,
93    #[serde(default)]
94    pub development: Option<MaterializedDevelopmentInputs>,
95    #[serde(default)]
96    pub review: Option<MaterializedReviewInputs>,
97    #[serde(default)]
98    pub commit: Option<MaterializedCommitInputs>,
99    /// Materialized last invalid XML output for XSD retry prompts.
100    ///
101    /// This is used to dedupe retries and keep oversize handling reducer-visible.
102    #[serde(default)]
103    pub xsd_retry_last_output: Option<MaterializedXsdRetryLastOutput>,
104}
105
106impl PromptInputsState {
107    /// Clear commit inputs without cloning other fields.
108    /// Uses consuming builder pattern for zero-cost state updates.
109    #[must_use]
110    pub fn with_commit_cleared(self) -> Self {
111        Self {
112            commit: None,
113            ..self
114        }
115    }
116
117    /// Clear planning inputs without cloning other fields.
118    #[must_use]
119    pub fn with_planning_cleared(self) -> Self {
120        Self {
121            planning: None,
122            ..self
123        }
124    }
125
126    /// Clear development inputs without cloning other fields.
127    #[must_use]
128    pub fn with_development_cleared(self) -> Self {
129        Self {
130            development: None,
131            ..self
132        }
133    }
134
135    /// Clear review inputs without cloning other fields.
136    #[must_use]
137    pub fn with_review_cleared(self) -> Self {
138        Self {
139            review: None,
140            ..self
141        }
142    }
143
144    /// Clear XSD retry last output without cloning other fields.
145    #[must_use]
146    pub fn with_xsd_retry_cleared(self) -> Self {
147        Self {
148            xsd_retry_last_output: None,
149            ..self
150        }
151    }
152}
153
154#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
155pub struct MaterializedPlanningInputs {
156    pub iteration: u32,
157    pub prompt: MaterializedPromptInput,
158}
159
160#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
161pub struct MaterializedDevelopmentInputs {
162    pub iteration: u32,
163    pub prompt: MaterializedPromptInput,
164    pub plan: MaterializedPromptInput,
165}
166
167#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
168pub struct MaterializedReviewInputs {
169    pub pass: u32,
170    pub plan: MaterializedPromptInput,
171    pub diff: MaterializedPromptInput,
172}
173
174#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
175pub struct MaterializedCommitInputs {
176    pub attempt: u32,
177    pub diff: MaterializedPromptInput,
178}
179
180#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
181pub struct MaterializedXsdRetryLastOutput {
182    pub phase: PipelinePhase,
183    pub scope_id: u32,
184    pub last_output: MaterializedPromptInput,
185}