gigi-cli 1.0.1

Gigi — A Claude Code-like AI coding assistant CLI in Rust
use anyhow::Result;
use async_trait::async_trait;
use serde_json::Value;
use std::path::Path;

use super::{Tool, ToolOutput};
use crate::tools::file_ops::glob_search_in_workspace;

pub struct GlobSearchTool;

impl GlobSearchTool {
    pub fn new() -> Self {
        Self
    }
}

impl Default for GlobSearchTool {
    fn default() -> Self {
        Self::new()
    }
}

#[async_trait]
impl Tool for GlobSearchTool {
    fn name(&self) -> &str {
        "glob_search"
    }

    fn description(&self) -> &str {
        "Find files by glob pattern."
    }

    fn parameters_schema(&self) -> Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "pattern": { "type": "string" },
                "path": { "type": "string" }
            },
            "required": ["pattern"],
            "additionalProperties": false
        })
    }

    async fn execute(&self, input: Value) -> Result<ToolOutput> {
        let pattern = input["pattern"]
            .as_str()
            .ok_or_else(|| anyhow::anyhow!("Missing required parameter: pattern"))?;

        let path = input["path"].as_str();

        let workspace_root = std::env::current_dir()?;

        match glob_search_in_workspace(pattern, path, &workspace_root) {
            Ok(output) => {
                let serialized = serde_json::to_string_pretty(&output)?;
                Ok(ToolOutput::success(serialized))
            }
            Err(e) => Ok(ToolOutput::error(format!("Error performing glob search: {}", e))),
        }
    }
}