use super::super::args::{EnrichArgs, EnrichMode, EnrichOperation};
use super::super::events::{run_preflight_probe, PhaseEvent, PreflightOutcome};
use crate::errors::AppError;
use crate::output::emit_json_line as emit_json;
use std::path::PathBuf;
pub(super) fn resolve_provider_binary(args: &EnrichArgs) -> Result<Option<PathBuf>, AppError> {
if args.dry_run || matches!(args.operation(), EnrichOperation::ReEmbed) {
return Ok(None);
}
Ok(Some(match args.mode() {
EnrichMode::OpenRouter => {
emit_json(&PhaseEvent {
phase: "validate",
binary_path: None,
version: None,
items_total: None,
items_pending: None,
llm_parallelism: None,
});
PathBuf::new()
}
}))
}
pub(super) fn check_system_load(args: &EnrichArgs) -> Result<(), AppError> {
if args.max_load_check && !args.dry_run && crate::system_load::is_system_saturated() {
let load = crate::system_load::load_average_one();
let n = crate::system_load::ncpus();
return Err(AppError::Validation(
crate::i18n::validation::system_load_exceeded(load, n),
));
}
Ok(())
}
pub(super) fn run_preflight(args: &EnrichArgs) -> Result<(), AppError> {
if !(args.preflight_check
&& !args.dry_run
&& !matches!(args.operation(), EnrichOperation::ReEmbed))
{
return Ok(());
}
let preflight_result = run_preflight_probe(args);
match preflight_result {
PreflightOutcome::Healthy => {
tracing::info!(target: "enrich", mode = ?args.mode(), "preflight probe healthy");
Ok(())
}
PreflightOutcome::Error(e) => Err(e),
}
}