use crate::phase::{NextStep, Phase, PhaseContext, PhaseMetadata, PhaseResult};
use crate::status::artifact::{Artifact, ArtifactType};
use anyhow::Result;
use super::FixupMode;
use super::parse::FixupParser;
#[derive(Debug, Clone)]
pub struct FixupPhase {
mode: FixupMode,
}
impl FixupPhase {
#[must_use]
pub const fn new_with_mode(mode: FixupMode) -> Self {
Self { mode }
}
#[must_use]
pub const fn new() -> Self {
Self {
mode: FixupMode::Preview,
}
}
}
impl Phase for FixupPhase {
fn id(&self) -> crate::types::PhaseId {
xchecker_utils::types::PhaseId::Fixup
}
fn deps(&self) -> &'static [xchecker_utils::types::PhaseId] {
&[xchecker_utils::types::PhaseId::Review]
}
fn can_resume(&self) -> bool {
true
}
fn prompt(&self, _ctx: &PhaseContext) -> String {
String::new()
}
fn make_packet(&self, _ctx: &PhaseContext) -> Result<crate::packet::Packet> {
let empty_content = String::new();
let blake3_hash = blake3::hash(empty_content.as_bytes()).to_hex().to_string();
let evidence = crate::types::PacketEvidence {
files: vec![],
max_bytes: 65536,
max_lines: 1200,
};
let budget_used = crate::packet::BudgetUsage::new(65536, 1200);
Ok(crate::packet::Packet::new(
empty_content,
blake3_hash,
evidence,
budget_used,
))
}
fn postprocess(&self, raw: &str, ctx: &PhaseContext) -> Result<PhaseResult> {
let parser = FixupParser::new(self.mode, ctx.spec_dir.clone())?;
match parser.parse_diffs(raw) {
Ok(diffs) => {
let fixup_content = format!(
"# Fixup Report\n\nMode: {:?}\n\nParsed {} diff(s) from review output.\n",
self.mode,
diffs.len()
);
let fixup_artifact = Artifact {
name: "40-fixup.md".to_string(),
content: fixup_content.clone(),
artifact_type: ArtifactType::Markdown,
blake3_hash: blake3::hash(fixup_content.as_bytes()).to_hex().to_string(),
};
let artifacts = vec![fixup_artifact];
let metadata = PhaseMetadata::default();
Ok(PhaseResult {
artifacts,
next_step: NextStep::Continue, metadata,
})
}
Err(e) => Err(e.into()),
}
}
}
impl Default for FixupPhase {
fn default() -> Self {
Self::new()
}
}