#[cfg(test)]
#[must_use]
pub fn prompt_developer_iteration(
iteration: u32,
total: u32,
context: ContextLevel,
prompt_content: &str,
plan_content: &str,
) -> String {
let partials = get_shared_partials();
let _ = (iteration, total, context);
let template_content = include_str!("../templates/developer_iteration_xml.txt");
let template = Template::new(template_content);
let variables = HashMap::from([
("PROMPT", prompt_content.to_string()),
("PLAN", plan_content.to_string()),
]);
template
.render_with_partials(&variables, &partials)
.unwrap_or_else(|_| {
format!(
"IMPLEMENTATION MODE\n\nORIGINAL REQUEST:\n{prompt_content}\n\nIMPLEMENTATION PLAN:\n{plan_content}\n\nExecute the next steps from the plan above.\n\nOutput format: <ralph-development-result><ralph-status>completed|partial|failed</ralph-status><ralph-summary>Summary</ralph-summary></ralph-development-result>\n"
)
})
}
#[must_use]
pub fn prompt_developer_iteration_with_context(
context: &TemplateContext,
iteration: u32,
total: u32,
ctx_level: ContextLevel,
prompt_content: &str,
plan_content: &str,
) -> String {
let partials = get_shared_partials();
let _ = (iteration, total, ctx_level);
let template_content = context
.registry()
.get_template("developer_iteration_xml")
.unwrap_or_else(|_| {
include_str!("../templates/developer_iteration_xml.txt").to_string()
});
let template = Template::new(&template_content);
let variables = HashMap::from([
("PROMPT", prompt_content.to_string()),
("PLAN", plan_content.to_string()),
]);
template
.render_with_partials(&variables, &partials)
.unwrap_or_else(|_| {
format!(
"IMPLEMENTATION MODE\n\nORIGINAL REQUEST:\n{prompt_content}\n\nIMPLEMENTATION PLAN:\n{plan_content}\n\nExecute the next steps from the plan above.\n\nOutput format: <ralph-development-result><ralph-status>completed|partial|failed</ralph-status><ralph-summary>Summary</ralph-summary></ralph-development-result>\n"
)
})
}
pub fn prompt_developer_iteration_xml_with_context(
context: &TemplateContext,
prompt_content: &str,
plan_content: &str,
workspace: &dyn Workspace,
) -> String {
let partials = get_shared_partials();
let template_content = context
.registry()
.get_template("developer_iteration_xml")
.unwrap_or_else(|_| include_str!("../templates/developer_iteration_xml.txt").to_string());
let template = Template::new(&template_content);
let variables = HashMap::from([
("PROMPT", prompt_content.to_string()),
("PLAN", plan_content.to_string()),
(
"DEVELOPMENT_RESULT_XML_PATH",
workspace.absolute_str(".agent/tmp/development_result.xml"),
),
(
"DEVELOPMENT_RESULT_XSD_PATH",
workspace.absolute_str(".agent/tmp/development_result.xsd"),
),
]);
template
.render_with_partials(&variables, &partials)
.unwrap_or_else(|_| {
format!(
"IMPLEMENTATION MODE\n\nORIGINAL REQUEST:\n{prompt_content}\n\n\
IMPLEMENTATION PLAN:\n{plan_content}\n\n\
Output format: <ralph-development-result><ralph-status>completed|partial|failed</ralph-status><ralph-summary>Summary</ralph-summary></ralph-development-result>\n"
)
})
}
pub fn prompt_developer_iteration_xml_with_references_and_log(
context: &TemplateContext,
refs: &super::content_builder::PromptContentReferences,
workspace: &dyn Workspace,
template_name: &str,
) -> crate::prompts::RenderedTemplate {
use crate::prompts::{
RenderedTemplate, SubstitutionEntry, SubstitutionLog, SubstitutionSource,
};
let partials = get_shared_partials();
let template_content = context
.registry()
.get_template("developer_iteration_xml")
.unwrap_or_else(|_| include_str!("../templates/developer_iteration_xml.txt").to_string());
let template = Template::new(&template_content);
let variables = HashMap::from([
("PROMPT", refs.prompt_for_template()),
("PLAN", refs.plan_for_template()),
(
"DEVELOPMENT_RESULT_XML_PATH",
workspace.absolute_str(".agent/tmp/development_result.xml"),
),
(
"DEVELOPMENT_RESULT_XSD_PATH",
workspace.absolute_str(".agent/tmp/development_result.xsd"),
),
]);
match template.render_with_log(template_name, &variables, &partials) {
Ok(rendered) => rendered,
Err(err) => {
let unsubstituted = match &err {
crate::prompts::template_engine::TemplateError::MissingVariable(name) => {
vec![name.clone()]
}
_ => vec![],
};
let prompt = refs.prompt_for_template();
let plan = refs.plan_for_template();
let prompt_content = format!(
"IMPLEMENTATION MODE\n\nORIGINAL REQUEST:\n{prompt}\n\n\
IMPLEMENTATION PLAN:\n{plan}\n\n\
Output format: <ralph-development-result>...</ralph-development-result>\n"
);
RenderedTemplate {
content: prompt_content,
log: SubstitutionLog {
template_name: template_name.to_string(),
substituted: vec![
SubstitutionEntry {
name: "PROMPT".to_string(),
source: SubstitutionSource::Value,
},
SubstitutionEntry {
name: "PLAN".to_string(),
source: SubstitutionSource::Value,
},
],
unsubstituted,
},
}
}
}
}
pub fn prompt_developer_iteration_xml_with_references(
context: &TemplateContext,
refs: &super::content_builder::PromptContentReferences,
workspace: &dyn Workspace,
) -> String {
let partials = get_shared_partials();
let template_content = context
.registry()
.get_template("developer_iteration_xml")
.unwrap_or_else(|_| include_str!("../templates/developer_iteration_xml.txt").to_string());
let template = Template::new(&template_content);
let variables = HashMap::from([
("PROMPT", refs.prompt_for_template()),
("PLAN", refs.plan_for_template()),
(
"DEVELOPMENT_RESULT_XML_PATH",
workspace.absolute_str(".agent/tmp/development_result.xml"),
),
(
"DEVELOPMENT_RESULT_XSD_PATH",
workspace.absolute_str(".agent/tmp/development_result.xsd"),
),
]);
template
.render_with_partials(&variables, &partials)
.unwrap_or_else(|_| {
let prompt = refs.prompt_for_template();
let plan = refs.plan_for_template();
format!(
"IMPLEMENTATION MODE\n\nORIGINAL REQUEST:\n{prompt}\n\n\
IMPLEMENTATION PLAN:\n{plan}\n\n\
Output format: <ralph-development-result>...</ralph-development-result>\n"
)
})
}