1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//! Structured AI worker output types.
//!
//! These types define the structured output contracts for AI worker agents and
//! agentic phase execution. They are used for JSON Schema generation and
//! cross-language type bindings (TypeScript, Python).
//!
//! - `WorkerOutput` and its supporting types (`StructuredSignal`,
//! `StructuredFinding`, `StructuredOverride`, `ConfidenceLevel`) model the
//! per-iteration output from an AI worker agent.
//! - `AgenticPhaseOutput` and its supporting types (`AgenticStatus`,
//! `FileChange`, `FindingOutput`, `ReflectionFixOutput`) model the canonical
//! output from the agentic phase of a unified workflow execution.
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
// ── WorkerOutput (mirrors orchestrator::structured_output::WorkerOutput) ──
/// Structured output from an AI worker agent.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct WorkerOutput {
/// Summary of work performed in this iteration.
#[serde(alias = "work_summary")]
pub work_summary: String,
/// Signals for orchestrator control flow.
#[serde(default, alias = "signals")]
pub signals: Vec<StructuredSignal>,
/// Findings discovered during work.
#[serde(default, alias = "findings")]
pub findings: Vec<StructuredFinding>,
/// Files that were modified in this iteration.
#[serde(default, alias = "files_modified")]
pub files_modified: Vec<String>,
/// Criterion overrides with justifications.
#[serde(default, alias = "criterion_overrides")]
pub criterion_overrides: Vec<StructuredOverride>,
/// Confidence level in the work quality.
#[serde(default, alias = "confidence")]
pub confidence: ConfidenceLevel,
/// Optional suggestion for next action if work continues.
#[serde(
skip_serializing_if = "Option::is_none",
alias = "next_action_suggestion"
)]
pub next_action_suggestion: Option<String>,
/// Optional progress estimate (0.0 to 1.0).
#[serde(skip_serializing_if = "Option::is_none", alias = "progress_estimate")]
pub progress_estimate: Option<f32>,
/// Optional notes for debugging or context.
#[serde(skip_serializing_if = "Option::is_none", alias = "notes")]
pub notes: Option<String>,
}
/// A signal from the worker to the orchestrator.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct StructuredSignal {
/// Signal type (e.g., "complete", "blocked", "needs_input").
#[serde(alias = "signal_type")]
pub signal_type: String,
/// Optional message providing context for the signal.
#[serde(skip_serializing_if = "Option::is_none", alias = "message")]
pub message: Option<String>,
}
/// A finding discovered during work.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct StructuredFinding {
/// Finding category (e.g., "bug", "security", "performance").
#[serde(alias = "category")]
pub category: String,
/// Severity level.
#[serde(alias = "severity")]
pub severity: String,
/// Short title describing the finding.
#[serde(alias = "title")]
pub title: String,
/// Detailed description.
#[serde(default, alias = "description")]
pub description: String,
/// Whether this finding requires human input.
#[serde(default, alias = "needs_input")]
pub needs_input: bool,
}
/// A criterion override with justification.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct StructuredOverride {
/// The criterion being overridden.
#[serde(alias = "criterion")]
pub criterion: String,
/// The new status.
#[serde(alias = "status")]
pub status: String,
/// Justification for the override.
#[serde(alias = "justification")]
pub justification: String,
}
/// Confidence level enum.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum ConfidenceLevel {
/// High confidence in work quality.
High,
/// Medium confidence in work quality.
#[default]
Medium,
/// Low confidence in work quality.
Low,
}
// ── AgenticPhaseOutput (mirrors unified_workflow_executor::agentic_output) ──
/// Status of the agentic phase execution.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum AgenticStatus {
/// Agentic phase completed successfully.
Success,
/// Agentic phase partially succeeded.
PartialSuccess,
/// Agentic phase failed.
Failed,
/// Errors determined to be unfixable.
Unfixable,
}
/// A file change made during the agentic phase.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct FileChange {
/// Path of the changed file.
#[serde(alias = "path")]
pub path: String,
/// Action performed on the file (e.g., "modified", "created", "deleted").
#[serde(alias = "action")]
pub action: String,
}
/// A finding reported by the AI.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct FindingOutput {
/// Finding category.
#[serde(alias = "category")]
pub category: String,
/// Severity level.
#[serde(alias = "severity")]
pub severity: String,
/// Short title describing the finding.
#[serde(alias = "title")]
pub title: String,
/// Detailed description.
#[serde(default, alias = "description")]
pub description: String,
/// Whether this finding requires human input.
#[serde(default, alias = "needs_input")]
pub needs_input: bool,
/// Whether this finding has been resolved.
#[serde(default, alias = "resolved")]
pub resolved: bool,
}
/// A reflection fix reported by the AI.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct ReflectionFixOutput {
/// Identifier for the error being fixed.
#[serde(alias = "error_id")]
pub error_id: String,
/// Description of the fix applied.
#[serde(alias = "description")]
pub description: String,
}
/// Canonical structured output from the agentic phase.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[schemars(deny_unknown_fields)]
pub struct AgenticPhaseOutput {
/// Overall status of the agentic phase.
#[serde(alias = "status")]
pub status: AgenticStatus,
/// Human-readable summary of what was done.
#[serde(alias = "summary")]
pub summary: String,
/// AI's confidence that the fixes will pass verification (0.0-1.0).
#[serde(default, alias = "confidence")]
pub confidence: Option<f64>,
/// Whether the AI determined errors are unfixable.
#[serde(default, alias = "unfixable")]
pub unfixable: bool,
/// Reason why errors are unfixable (if unfixable is true).
#[serde(default, alias = "unfixable_reason")]
pub unfixable_reason: Option<String>,
/// Files modified during this agentic phase.
#[serde(default, alias = "files_modified")]
pub files_modified: Vec<FileChange>,
/// Dynamically injected verification steps.
#[serde(default, alias = "injected_steps")]
pub injected_steps: Vec<Value>,
/// Reflection fixes (when reflection_mode is enabled).
#[serde(default, alias = "reflection_fixes")]
pub reflection_fixes: Vec<ReflectionFixOutput>,
/// Findings reported by the AI.
#[serde(default, alias = "findings")]
pub findings: Vec<FindingOutput>,
}