Files
zesdex/apps/infrastructure/src/tools/git/git_worktree.rs
T
asepharyana da2ed6da25 feat(tui): add usage overlay and sidebar for displaying usage statistics and tasks
feat(tui): implement status bar with connection and turn state indicators
feat(tui): create workflow panel for agent status and progress visualization
feat(web): introduce web frontend interface with static file serving
feat(ws): add WebSocket interface for real-time communication and session management
2026-07-20 09:04:57 +07:00

76 lines
2.4 KiB
Rust

//! 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<String> {
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),
}
}
}