@@ -11,6 +11,28 @@ use crate::AgentError;
1111use crate :: analysis:: AnalysisResult ;
1212use crate :: providers:: LlmClient ;
1313
14+ /// Output from a single chunk's translation.
15+ #[ derive( Debug , Clone ) ]
16+ pub struct ChunkOutput {
17+ /// Chunk index (0-based).
18+ pub index : usize ,
19+ /// Translated Rust source for this chunk.
20+ pub rust_source : String ,
21+ }
22+
23+ /// Result of chunked translation including per-chunk details.
24+ #[ derive( Debug , Clone ) ]
25+ pub struct ChunkedTranslationResult {
26+ /// Combined Rust source from all chunks.
27+ pub combined : String ,
28+ /// Individual chunk outputs (before combination).
29+ pub chunks : Vec < ChunkOutput > ,
30+ /// P11 agreed signatures (if generated).
31+ pub agreed_signatures : Option < String > ,
32+ /// P9 foundation context from chunk 0 (if generated).
33+ pub foundation : Option < String > ,
34+ }
35+
1436/// System prompt for the translation agent, loaded from the prompts directory at compile time.
1537const TRANSLATION_PREAMBLE : & str = include_str ! ( "../../../prompts/translation.md" ) ;
1638
@@ -157,7 +179,7 @@ pub async fn translate_chunked(
157179 analysis : & AnalysisResult ,
158180 patterns : & [ & MigrationPattern ] ,
159181 temperature : Option < f64 > ,
160- ) -> Result < String , AgentError > {
182+ ) -> Result < ChunkedTranslationResult , AgentError > {
161183 info ! (
162184 chunks = chunks. len( ) ,
163185 model, "starting chunked multi-pass translation"
@@ -168,6 +190,7 @@ pub async fn translate_chunked(
168190 // P9: Foundation context — chunk 0's output (types, data model) is passed to all
169191 // subsequent chunks so they can reference the translated Rust types.
170192 let mut foundation_rust: Option < String > = None ;
193+ let mut chunk_outputs: Vec < ChunkOutput > = Vec :: new ( ) ;
171194
172195 // P11: Signature agreement pass — for files with many chunks, generate agreed-upon
173196 // Rust signatures for all functions before translating bodies. This prevents
@@ -265,6 +288,10 @@ pub async fn translate_chunked(
265288 temperature,
266289 )
267290 . await ?;
291+ chunk_outputs. push ( ChunkOutput {
292+ index : i,
293+ rust_source : rust_code. clone ( ) ,
294+ } ) ;
268295 accumulated_rust. push ( rust_code) ;
269296 continue ;
270297 }
@@ -404,6 +431,12 @@ pub async fn translate_chunked(
404431 rust_code
405432 } ;
406433
434+ // Capture per-chunk output before combination
435+ chunk_outputs. push ( ChunkOutput {
436+ index : i,
437+ rust_source : rust_code. clone ( ) ,
438+ } ) ;
439+
407440 // Extract signatures from this chunk's output for next chunk's context
408441 let new_sigs = noricum_tools:: ast:: extract_rust_signatures ( & rust_code) ;
409442 accumulated_sigs. extend ( new_sigs) ;
@@ -481,7 +514,12 @@ pub async fn translate_chunked(
481514 "chunked translation complete"
482515 ) ;
483516
484- Ok ( final_output)
517+ Ok ( ChunkedTranslationResult {
518+ combined : final_output,
519+ chunks : chunk_outputs,
520+ agreed_signatures,
521+ foundation : foundation_rust,
522+ } )
485523}
486524
487525/// Build a condensed structural summary of a large C source file.
0 commit comments