| 105 | } |
| 106 | |
| 107 | async fn execute(&self, args: &serde_json::Value, ctx: &ToolContext) -> Result<ToolOutput> { |
| 108 | let command = match args.get("command").and_then(|v| v.as_str()) { |
| 109 | Some(c) => c, |
| 110 | None => return Ok(ToolOutput::error("command parameter is required")), |
| 111 | }; |
| 112 | |
| 113 | let Some(git) = ctx.workspace_services.git() else { |
| 114 | return Ok(ToolOutput::error( |
| 115 | "Git is not available for this workspace backend", |
| 116 | )); |
| 117 | }; |
| 118 | |
| 119 | match git.is_repository().await { |
| 120 | Ok(true) => {} |
| 121 | Ok(false) => { |
| 122 | return Ok(ToolOutput::error(format!( |
| 123 | "Not a git repository: {}", |
| 124 | ctx.workspace_services.workspace_ref().display_root |
| 125 | ))) |
| 126 | } |
| 127 | Err(e) => { |
| 128 | return Ok(ToolOutput::error(format!( |
| 129 | "Failed to inspect git repository: {e}" |
| 130 | ))) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | match command { |
| 135 | "status" => self.status(ctx, git.as_ref()).await, |
| 136 | "log" => self.log(args, git.as_ref()).await, |
| 137 | "branch" => self.branch(args, git.as_ref()).await, |
| 138 | "checkout" => self.checkout(args, git.as_ref()).await, |
| 139 | "diff" => self.diff(args, git.as_ref()).await, |
| 140 | "stash" => { |
| 141 | let Some(stash) = ctx.workspace_services.git_stash() else { |
| 142 | return Ok(ToolOutput::error( |
| 143 | "Stash operations are not supported by this workspace backend", |
| 144 | )); |
| 145 | }; |
| 146 | self.stash(args, stash.as_ref()).await |
| 147 | } |
| 148 | "remote" => self.remote(git.as_ref()).await, |
| 149 | "worktree" => { |
| 150 | let Some(worktree) = ctx.workspace_services.git_worktree() else { |
| 151 | return Ok(ToolOutput::error( |
| 152 | "Worktree operations are not supported by this workspace backend", |
| 153 | )); |
| 154 | }; |
| 155 | self.worktree(args, worktree.as_ref()).await |
| 156 | } |
| 157 | _ => Ok(ToolOutput::error(format!( |
| 158 | "Unknown command: {command}. Use: status, log, branch, checkout, diff, stash, remote, worktree" |
| 159 | ))), |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | impl GitTool { |