use crate::core::tools::index::{ToolError, ToolResult, resolve_tool_path};
pub async fn execute_write(path: &str, content: &str, cwd: &str) -> Result<ToolResult, ToolError> {
let absolute_path = resolve_tool_path(path, cwd);
if let Some(parent) = absolute_path.parent()
&& !parent.as_os_str().is_empty()
{
_ = std::fs::create_dir_all(parent);
}
match std::fs::write(&absolute_path, content) {
Ok(_) => Ok(ToolResult::text(format!("Successfully wrote to {}", path))),
Err(e) => Err(ToolError(format!(
"Could not write file: {}. Error: {}",
path, e
))),
}
}