use crate::agents::{AgentHarness, AgentType, ExecutionConfig, ExecutionOutput};
use crate::parser::ToolCall;
use std::path::PathBuf;
pub fn prompt(text: &str) -> PromptBuilder {
PromptBuilder::new(text)
}
#[derive(Debug, Clone)]
pub struct PromptBuilder {
text: String,
working_dir: Option<PathBuf>,
agent: Option<AgentType>,
}
impl PromptBuilder {
pub fn new(text: &str) -> Self {
Self {
text: text.to_string(),
working_dir: None,
agent: None,
}
}
pub fn in_dir(mut self, dir: &str) -> Self {
self.working_dir = Some(PathBuf::from(dir));
self
}
pub fn in_dir_path(mut self, dir: PathBuf) -> Self {
self.working_dir = Some(dir);
self
}
pub fn agent(mut self, agent: AgentType) -> Self {
self.agent = Some(agent);
self
}
pub fn run_full(self) -> anyhow::Result<ExecutionOutput> {
let harness = AgentHarness::new();
let mut config = ExecutionConfig::new();
if let Some(dir) = self.working_dir {
config = config.with_working_dir(dir);
}
harness.execute(self.agent, &self.text, config)
}
pub fn run(self) -> anyhow::Result<Vec<ToolCall>> {
Ok(self.run_full()?.result.tool_calls)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_prompt_builder_creation() {
let builder = prompt("Test prompt");
assert_eq!(builder.text, "Test prompt");
assert!(builder.working_dir.is_none());
assert!(builder.agent.is_none());
}
#[test]
fn test_prompt_builder_in_dir() {
let builder = prompt("Test").in_dir("/tmp");
assert_eq!(builder.working_dir, Some(PathBuf::from("/tmp")));
}
#[test]
fn test_prompt_builder_agent() {
let builder = prompt("Test").agent(AgentType::Claude);
assert_eq!(builder.agent, Some(AgentType::Claude));
}
#[test]
fn test_prompt_builder_chaining() {
let builder = prompt("Test")
.in_dir("/tmp")
.agent(AgentType::Claude);
assert_eq!(builder.text, "Test");
assert_eq!(builder.working_dir, Some(PathBuf::from("/tmp")));
assert_eq!(builder.agent, Some(AgentType::Claude));
}
}