use crate::coding::blueprint::{render, select_blueprint, BlueprintExecution};
use crate::coding::program_language_by_alias;
use crate::coding::WRITE_PROGRAM_INTENT;
use crate::engine::SymbolicAnswer;
use crate::event_log::EventLog;
use crate::language::detect as detect_language;
use crate::solver::BlueprintComposition;
use super::finalize_simple;
pub fn try_program_blueprint(
prompt: &str,
normalized: &str,
language_hint: Option<&str>,
composition: BlueprintComposition,
log: &mut EventLog,
) -> Option<SymbolicAnswer> {
let language_slug = language_hint.map(str::to_owned).or_else(|| {
program_language_by_alias(normalized).map(|language| language.slug.to_owned())
})?;
let blueprint = select_blueprint(normalized, &language_slug)?;
let response_language = detect_language(prompt);
let body = render(&blueprint, response_language, composition);
log.append("program_blueprint:recipe", blueprint.recipe.slug.to_owned());
log.append(
"program_blueprint:composition",
composition.slug().to_owned(),
);
log.append("program_parameter:language", language_slug.clone());
log.append(
"program_parameter:task",
format!("blueprint:{}", blueprint.recipe.slug),
);
for capability in &blueprint.capabilities {
log.append("program_blueprint:capability", capability.slug.to_owned());
}
let (status, environment) = match blueprint.program.execution {
BlueprintExecution::LocalSourceAnalysis => (
"not run — standard-library source analysis blueprint",
"answer renderer did not compile generated Cargo program in place",
),
BlueprintExecution::ReviewDataAssumptions => (
"not run — assumptions require review",
"offline sandbox did not execute reviewed report blueprint",
),
BlueprintExecution::ExternalLibrariesAndNetwork => (
"not run — requires external libraries and network access",
"offline sandbox cannot install libraries or reach the network",
),
};
log.append("execution_status", status.to_owned());
log.append("execution_environment", environment.to_owned());
let response_link = format!(
"response:write_program:blueprint:{}:{language_slug}",
blueprint.recipe.slug
);
Some(finalize_simple(
prompt,
log,
WRITE_PROGRAM_INTENT,
&response_link,
&body,
0.7,
))
}