use crate::toolbox::SashikoToolContext;
use crate::toolbox::framework::LlmTool;
use crate::toolbox::utils::validate_path;
use anyhow::{Result, anyhow};
use async_trait::async_trait;
use serde_json::{Value, json};
use tokio::fs;
pub struct ReadPromptTool;
#[async_trait]
impl LlmTool<SashikoToolContext> for ReadPromptTool {
fn name(&self) -> &'static str {
"read_prompt"
}
fn description(&self) -> &'static str {
"Read a specific prompt file from the prompt registry (e.g., 'mm.md', 'locking.md')."
}
fn parameters(&self) -> Value {
json!({
"type": "object",
"properties": {
"name": { "type": "string", "description": "Name of the prompt file (e.g., 'patterns/BPF-001.md')." }
},
"required": ["name"]
})
}
async fn call(&self, args: Value, context: &SashikoToolContext) -> Result<Value> {
let prompts_path = context
.prompts_path
.as_ref()
.ok_or_else(|| anyhow!("read_prompt tool is not available"))?;
let name = args["name"]
.as_str()
.ok_or_else(|| anyhow!("Missing prompt name"))?;
let path = validate_path(name, prompts_path)?;
let content = fs::read_to_string(path).await?;
Ok(json!({ "content": content }))
}
}