Skip to content

Commit 6c1fccc

Browse files
committed
Merge branch 'feat/artifact-persistence' into feat/deepseek-provider
# Conflicts: # crates/noricum-cli/src/commands/migrate.rs # crates/noricum-cli/src/main.rs
2 parents 9f62539 + 5a814e6 commit 6c1fccc

9 files changed

Lines changed: 785 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
/demo.cast
1010
/demo.gif
1111
.noricum-cache/
12+
.noricum-artifacts/
13+
proptest-regressions/
1214
.worktrees/
1315
check

crates/noricum-agents/src/translation.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ use crate::AgentError;
1111
use crate::analysis::AnalysisResult;
1212
use 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.
1537
const 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.

crates/noricum-cli/src/commands/migrate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct MigrateParams {
2525
pub ollama_model: Option<String>,
2626
pub skip_c2rust: bool,
2727
pub provider: Option<String>,
28+
pub artifacts_dir: std::path::PathBuf,
2829
}
2930

3031
pub async fn cmd_migrate(opts: MigrateParams) -> Result<()> {
@@ -62,6 +63,7 @@ pub async fn cmd_migrate(opts: MigrateParams) -> Result<()> {
6263
generate_docs: opts.docs,
6364
ollama_model: opts.ollama_model,
6465
skip_c2rust: opts.skip_c2rust,
66+
artifacts_dir: opts.artifacts_dir,
6567
max_tokens_budget: match opts.max_tokens {
6668
Some(0) => None,
6769
Some(n) => Some(n),

crates/noricum-cli/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ struct MigrateOpts {
171171
/// LLM provider: anthropic, deepseek, or ollama (default: auto-detect from available API keys)
172172
#[arg(long)]
173173
provider: Option<String>,
174+
/// Directory for intermediate artifact persistence (default: .noricum-artifacts)
175+
#[arg(long, default_value = ".noricum-artifacts")]
176+
artifacts_dir: PathBuf,
174177
}
175178

176179
fn setup_tracing(verbosity: u8) {
@@ -212,6 +215,7 @@ async fn main() {
212215
ollama_model: opts.ollama_model,
213216
skip_c2rust: opts.skip_c2rust,
214217
provider: opts.provider,
218+
artifacts_dir: opts.artifacts_dir,
215219
})
216220
.await
217221
}

0 commit comments

Comments
 (0)