diff --git a/aider/coders/navigator_coder.py b/aider/coders/navigator_coder.py index df7e4159ccd..efb07362242 100644 --- a/aider/coders/navigator_coder.py +++ b/aider/coders/navigator_coder.py @@ -57,12 +57,16 @@ from aider.tools.delete_lines import _execute_delete_lines from aider.tools.extract_lines import _execute_extract_lines from aider.tools.git import ( + _execute_git_branch, _execute_git_diff, _execute_git_log, + _execute_git_remote, _execute_git_show, _execute_git_status, + git_branch_schema, git_diff_schema, git_log_schema, + git_remote_schema, git_show_schema, git_status_schema, ) @@ -217,6 +221,8 @@ def get_local_tool_schemas(self): git_log_schema, git_show_schema, git_status_schema, + git_branch_schema, + git_remote_schema, ] async def initialize_mcp_tools(self): @@ -297,6 +303,8 @@ async def _execute_local_tool_calls(self, tool_calls_list): "git_log": _execute_git_log, "git_show": _execute_git_show, "git_status": _execute_git_status, + "git_branch": _execute_git_branch, + "git_remote": _execute_git_remote, } func = tool_functions.get(norm_tool_name) diff --git a/aider/tools/__init__.py b/aider/tools/__init__.py index 3de1c4945fc..ed1fc712236 100644 --- a/aider/tools/__init__.py +++ b/aider/tools/__init__.py @@ -11,12 +11,16 @@ from .delete_lines import _execute_delete_lines, delete_lines_schema from .extract_lines import _execute_extract_lines, extract_lines_schema from .git import ( + _execute_git_branch, _execute_git_diff, _execute_git_log, + _execute_git_remote, _execute_git_show, _execute_git_status, + git_branch_schema, git_diff_schema, git_log_schema, + git_remote_schema, git_show_schema, git_status_schema, ) diff --git a/aider/tools/git.py b/aider/tools/git.py index f9fefb7f507..3ca75abb1ae 100644 --- a/aider/tools/git.py +++ b/aider/tools/git.py @@ -140,3 +140,72 @@ def _execute_git_status(coder): except ANY_GIT_ERROR as e: coder.io.tool_error(f"Error running git status: {e}") return f"Error running git status: {e}" + + +git_branch_schema = { + "type": "function", + "function": { + "name": "git_branch", + "description": "List branches in the repository.", + "parameters": { + "type": "object", + "properties": {}, + "required": [], + }, + }, +} + + +def _execute_git_branch(coder): + """ + List branches in the repository. + """ + if not coder.repo: + return "Not in a git repository." + + try: + # Get all branches and current branch + branches = [] + current_branch = coder.repo.repo.active_branch.name + for branch in coder.repo.repo.heads: + prefix = "* " if branch.name == current_branch else " " + branches.append(f"{prefix}{branch.name}") + return "\n".join(branches) + except ANY_GIT_ERROR as e: + coder.io.tool_error(f"Error running git branch: {e}") + return f"Error running git branch: {e}" + + +git_remote_schema = { + "type": "function", + "function": { + "name": "git_remote", + "description": "List remote repositories.", + "parameters": { + "type": "object", + "properties": {}, + "required": [], + }, + }, +} + + +def _execute_git_remote(coder): + """ + List remote repositories. + """ + if not coder.repo: + return "Not in a git repository." + + try: + remotes = coder.repo.repo.remotes + if not remotes: + return "No remotes configured." + + result = [] + for remote in remotes: + result.append(f"{remote.name}\t{remote.url}") + return "\n".join(result) + except ANY_GIT_ERROR as e: + coder.io.tool_error(f"Error running git remote: {e}") + return f"Error running git remote: {e}"