//! Git worktree management tool. use crate::tools::{execute_cmd, Tool, ToolCtx}; use anyhow::Result; use serde_json::{json, Value}; pub struct GitWorktree; impl Tool for GitWorktree { fn name(&self) -> &'static str { "git_worktree" } fn description(&self) -> &'static str { "Manage git worktrees (add, list, remove, prune)" } fn parameters(&self) -> Value { json!({ "type": "object", "properties": { "action": { "type": "string", "enum": ["add", "list", "remove", "prune"], "description": "Worktree action to perform" }, "path": { "type": "string", "description": "Path for the new worktree (for 'add')" }, "branch": { "type": "string", "description": "Branch name for the new worktree (for 'add')" } }, "required": ["action"] }) } fn run(&self, _ctx: &ToolCtx, args: &Value) -> Result { let action = crate::tools::arg_str(args, "action")?; match action.as_str() { "add" => { let path = crate::tools::arg_str(args, "path")?; let branch = crate::tools::arg_str(args, "branch")?; let output = execute_cmd( std::process::Command::new("git") .args(["worktree", "add", &path, &branch]), )?; Ok(output) } "list" => { let output = execute_cmd( std::process::Command::new("git").args(["worktree", "list"]), )?; Ok(output) } "remove" => { let path = crate::tools::arg_str(args, "path")?; let output = execute_cmd( std::process::Command::new("git").args(["worktree", "remove", &path]), )?; Ok(output) } "prune" => { let output = execute_cmd( std::process::Command::new("git").args(["worktree", "prune"]), )?; Ok(output) } _ => anyhow::bail!("unknown action: {}", action), } } }