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(mut self) -> Self {
111        self.commit = None;
112        self
113    }
114
115    /// Clear planning inputs without cloning other fields.
116    #[must_use]
117    pub fn with_planning_cleared(mut self) -> Self {
118        self.planning = None;
119        self
120    }
121
122    /// Clear development inputs without cloning other fields.
123    #[must_use]
124    pub fn with_development_cleared(mut self) -> Self {
125        self.development = None;
126        self
127    }
128
129    /// Clear review inputs without cloning other fields.
130    #[must_use]
131    pub fn with_review_cleared(mut self) -> Self {
132        self.review = None;
133        self
134    }
135
136    /// Clear XSD retry last output without cloning other fields.
137    #[must_use]
138    pub fn with_xsd_retry_cleared(mut self) -> Self {
139        self.xsd_retry_last_output = None;
140        self
141    }
142}
143
144#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
145pub struct MaterializedPlanningInputs {
146    pub iteration: u32,
147    pub prompt: MaterializedPromptInput,
148}
149
150#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
151pub struct MaterializedDevelopmentInputs {
152    pub iteration: u32,
153    pub prompt: MaterializedPromptInput,
154    pub plan: MaterializedPromptInput,
155}
156
157#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
158pub struct MaterializedReviewInputs {
159    pub pass: u32,
160    pub plan: MaterializedPromptInput,
161    pub diff: MaterializedPromptInput,
162}
163
164#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
165pub struct MaterializedCommitInputs {
166    pub attempt: u32,
167    pub diff: MaterializedPromptInput,
168}
169
170#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
171pub struct MaterializedXsdRetryLastOutput {
172    pub phase: PipelinePhase,
173    pub scope_id: u32,
174    pub last_output: MaterializedPromptInput,
175}