codetether_agent/agent/builtin/
system_prompt.rs1use crate::agent::build_guidance::BUILD_GITHUB_AUTH_GUIDANCE;
13use std::path::Path;
14
15use super::agents_md::load_all_agents_md;
16use super::prompts::{BUILD_MODE_GUARDRAIL, BUILD_SYSTEM_PROMPT, PLAN_SYSTEM_PROMPT};
17
18pub fn build_system_prompt(cwd: &Path) -> String {
26 let base_prompt = BUILD_SYSTEM_PROMPT.replace("{cwd}", &cwd.display().to_string());
27 let agents_section = render_agents_section(cwd);
28 format!("{base_prompt}{agents_section}{BUILD_GITHUB_AUTH_GUIDANCE}{BUILD_MODE_GUARDRAIL}")
29}
30
31#[allow(dead_code)]
39pub fn build_plan_system_prompt(cwd: &Path) -> String {
40 let base_prompt = PLAN_SYSTEM_PROMPT.replace("{cwd}", &cwd.display().to_string());
41 format!("{base_prompt}{}", render_agents_section(cwd))
42}
43
44fn render_agents_section(cwd: &Path) -> String {
45 let agents_files = load_all_agents_md(cwd);
46 if agents_files.is_empty() {
47 return String::new();
48 }
49 let mut section = String::from(
50 "\n\n## Project Instructions (AGENTS.md)\n\nThe following instructions were loaded from AGENTS.md files in the project.\nFollow these project-specific guidelines when working on this codebase.\n\n",
51 );
52 for (content, path) in agents_files.iter().rev() {
53 section.push_str(&format!("### From {}\n\n{}\n\n", path.display(), content));
54 }
55 section
56}