diff --git a/src/agent/prompt.rs b/src/agent/prompt.rs index bdc426f..0b85119 100644 --- a/src/agent/prompt.rs +++ b/src/agent/prompt.rs @@ -77,21 +77,25 @@ impl PromptSection for IdentitySection { fn build(&self, ctx: &PromptContext<'_>) -> Result { let mut prompt = String::from("## Project Context\n\n"); + let mut has_aieos = false; if let Some(config) = ctx.identity_config { if identity::is_aieos_configured(config) { if let Ok(Some(aieos)) = identity::load_aieos_identity(config, ctx.workspace_dir) { let rendered = identity::aieos_to_system_prompt(&aieos); if !rendered.is_empty() { prompt.push_str(&rendered); - return Ok(prompt); + prompt.push_str("\n\n"); + has_aieos = true; } } } } - prompt.push_str( - "The following workspace files define your identity, behavior, and context.\n\n", - ); + if !has_aieos { + prompt.push_str( + "The following workspace files define your identity, behavior, and context.\n\n", + ); + } for file in [ "AGENTS.md", "SOUL.md", @@ -285,6 +289,48 @@ mod tests { } } + #[test] + fn identity_section_with_aieos_includes_workspace_files() { + let workspace = + std::env::temp_dir().join(format!("zeroclaw_prompt_test_{}", uuid::Uuid::new_v4())); + std::fs::create_dir_all(&workspace).unwrap(); + std::fs::write( + workspace.join("AGENTS.md"), + "Always respond with: AGENTS_MD_LOADED", + ) + .unwrap(); + + let identity_config = crate::config::IdentityConfig { + format: "aieos".into(), + aieos_path: None, + aieos_inline: Some(r#"{"identity":{"names":{"first":"Nova"}}}"#.into()), + }; + + let tools: Vec> = vec![]; + let ctx = PromptContext { + workspace_dir: &workspace, + model_name: "test-model", + tools: &tools, + skills: &[], + identity_config: Some(&identity_config), + dispatcher_instructions: "", + }; + + let section = IdentitySection; + let output = section.build(&ctx).unwrap(); + + assert!( + output.contains("Nova"), + "AIEOS identity should be present in prompt" + ); + assert!( + output.contains("AGENTS_MD_LOADED"), + "AGENTS.md content should be present even when AIEOS is configured" + ); + + let _ = std::fs::remove_dir_all(workspace); + } + #[test] fn prompt_builder_assembles_sections() { let tools: Vec> = vec![Box::new(TestTool)];