From da4759ab5eb4f5cee582e52fcc80082b32c40ef8 Mon Sep 17 00:00:00 2001 From: tomjuggler Date: Mon, 20 Oct 2025 17:07:50 +0200 Subject: [PATCH 1/4] attempt 1 not running --- aider/coders/navigator_coder.py | 23 +++++- aider/tools/__init__.py | 10 +++ aider/tools/git.py | 136 ++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 aider/tools/git.py diff --git a/aider/coders/navigator_coder.py b/aider/coders/navigator_coder.py index f871962b104..a3d33bb4dd2 100644 --- a/aider/coders/navigator_coder.py +++ b/aider/coders/navigator_coder.py @@ -75,7 +75,20 @@ # Import tool functions from aider.tools.view_files_matching import execute_view_files_matching -from aider.tools.view_files_with_symbol import _execute_view_files_with_symbol +from .view_files_with_symbol import ( + _execute_view_files_with_symbol, + view_files_with_symbol_schema, +) +from .git import ( + _execute_git_diff, + _execute_git_log, + _execute_git_show, + _execute_git_status, + git_diff_schema, + git_log_schema, + git_show_schema, + git_status_schema, +) from .base_coder import ChatChunks, Coder from .editblock_coder import do_replace, find_original_update_blocks, find_similar_lines @@ -203,6 +216,10 @@ def get_local_tool_schemas(self): extract_lines_schema, show_numbered_context_schema, update_todo_list_schema, + git_diff_schema, + git_log_schema, + git_show_schema, + git_status_schema, ] async def initialize_mcp_tools(self): @@ -279,6 +296,10 @@ async def _execute_local_tool_calls(self, tool_calls_list): "extractlines": _execute_extract_lines, "shownumberedcontext": execute_show_numbered_context, "updatetodolist": _execute_update_todo_list, + "git_diff": _execute_git_diff, + "git_log": _execute_git_log, + "git_show": _execute_git_show, + "git_status": _execute_git_status, } func = tool_functions.get(norm_tool_name) diff --git a/aider/tools/__init__.py b/aider/tools/__init__.py index 6d280977276..ee43f51a2a4 100644 --- a/aider/tools/__init__.py +++ b/aider/tools/__init__.py @@ -35,3 +35,13 @@ _execute_view_files_with_symbol, view_files_with_symbol_schema, ) +from .git import ( + _execute_git_diff, + _execute_git_log, + _execute_git_show, + _execute_git_status, + git_diff_schema, + git_log_schema, + git_show_schema, + git_status_schema, +) diff --git a/aider/tools/git.py b/aider/tools/git.py new file mode 100644 index 00000000000..2859a65ec43 --- /dev/null +++ b/aider/tools/git.py @@ -0,0 +1,136 @@ +# aider/tools/git.py + +import traceback +from aider.repo import ANY_GIT_ERROR + +git_diff_schema = { + "type": "function", + "function": { + "name": "git_diff", + "description": "Show the diff between the current working directory and a git branch or commit.", + "parameters": { + "type": "object", + "properties": { + "branch": { + "type": "string", + "description": "The branch or commit hash to diff against. Defaults to HEAD.", + }, + }, + "required": [], + }, + }, +} + +def _execute_git_diff(coder, branch=None): + """ + Show the diff between the current working directory and a git branch or commit. + """ + if not coder.repo: + return "Not in a git repository." + + try: + if branch: + diff = coder.repo.diff_commits(False, branch, "HEAD") + else: + diff = coder.repo.diff_commits(False, "HEAD", None) + + if not diff: + return "No differences found." + return diff + except ANY_GIT_ERROR as e: + coder.io.tool_error(f"Error running git diff: {e}") + return f"Error running git diff: {e}" + +git_log_schema = { + "type": "function", + "function": { + "name": "git_log", + "description": "Show the git log.", + "parameters": { + "type": "object", + "properties": { + "limit": { + "type": "integer", + "description": "The maximum number of commits to show. Defaults to 10.", + }, + }, + "required": [], + }, + }, +} + +def _execute_git_log(coder, limit=10): + """ + Show the git log. + """ + if not coder.repo: + return "Not in a git repository." + + try: + commits = list(coder.repo.repo.iter_commits(max_count=limit)) + log_output = [] + for commit in commits: + short_hash = commit.hexsha[:8] + message = commit.message.strip().split('\n')[0] + log_output.append(f"{short_hash} {message}") + return "\n".join(log_output) + except ANY_GIT_ERROR as e: + coder.io.tool_error(f"Error running git log: {e}") + return f"Error running git log: {e}" + +git_show_schema = { + "type": "function", + "function": { + "name": "git_show", + "description": "Show various types of objects (blobs, trees, tags, and commits).", + "parameters": { + "type": "object", + "properties": { + "object": { + "type": "string", + "description": "The object to show. Defaults to HEAD.", + }, + }, + "required": [], + }, + }, +} + +def _execute_git_show(coder, object="HEAD"): + """ + Show various types of objects (blobs, trees, tags, and commits). + """ + if not coder.repo: + return "Not in a git repository." + + try: + return coder.repo.repo.git.show(object) + except ANY_GIT_ERROR as e: + coder.io.tool_error(f"Error running git show: {e}") + return f"Error running git show: {e}" + +git_status_schema = { + "type": "function", + "function": { + "name": "git_status", + "description": "Show the working tree status.", + "parameters": { + "type": "object", + "properties": {}, + "required": [], + }, + }, +} + +def _execute_git_status(coder): + """ + Show the working tree status. + """ + if not coder.repo: + return "Not in a git repository." + + try: + return coder.repo.repo.git.status() + except ANY_GIT_ERROR as e: + coder.io.tool_error(f"Error running git status: {e}") + return f"Error running git status: {e}" From 4a978b7a074749e0678db835ed6832e62291e799 Mon Sep 17 00:00:00 2001 From: tomjuggler Date: Mon, 20 Oct 2025 17:09:09 +0200 Subject: [PATCH 2/4] added new git to pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0858c9d8331..c39e82e813d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ playwright = { file = "requirements/requirements-playwright.in" } include-package-data = true [tool.setuptools.packages.find] -include = ["aider"] +include = ["aider*"] [build-system] requires = ["setuptools>=68", "setuptools_scm[toml]>=8"] From 7b649358bb2fa9e9ddbea16c16579f06c370f7d4 Mon Sep 17 00:00:00 2001 From: tomjuggler Date: Mon, 20 Oct 2025 17:11:16 +0200 Subject: [PATCH 3/4] fixed import? --- aider/coders/navigator_coder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aider/coders/navigator_coder.py b/aider/coders/navigator_coder.py index a3d33bb4dd2..47cf8c09d71 100644 --- a/aider/coders/navigator_coder.py +++ b/aider/coders/navigator_coder.py @@ -75,11 +75,11 @@ # Import tool functions from aider.tools.view_files_matching import execute_view_files_matching -from .view_files_with_symbol import ( +from aider.tools.view_files_with_symbol import ( _execute_view_files_with_symbol, view_files_with_symbol_schema, ) -from .git import ( +from aider.tools.git import ( _execute_git_diff, _execute_git_log, _execute_git_show, From 637d02f2afbcd5738b44b3e437323e7280a5fa70 Mon Sep 17 00:00:00 2001 From: tomjuggler Date: Wed, 22 Oct 2025 12:56:21 +0200 Subject: [PATCH 4/4] ran pre-commit to fix formatting removed un-used import in git.py, navigator_coder.py --- aider/coders/navigator_coder.py | 25 +++++++++++-------------- aider/tools/__init__.py | 20 ++++++++++---------- aider/tools/git.py | 16 +++++++++++----- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/aider/coders/navigator_coder.py b/aider/coders/navigator_coder.py index 47cf8c09d71..df7e4159ccd 100644 --- a/aider/coders/navigator_coder.py +++ b/aider/coders/navigator_coder.py @@ -56,6 +56,16 @@ from aider.tools.delete_line import _execute_delete_line 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_diff, + _execute_git_log, + _execute_git_show, + _execute_git_status, + git_diff_schema, + git_log_schema, + git_show_schema, + git_status_schema, +) from aider.tools.grep import _execute_grep from aider.tools.indent_lines import _execute_indent_lines from aider.tools.insert_block import _execute_insert_block @@ -75,20 +85,7 @@ # Import tool functions from aider.tools.view_files_matching import execute_view_files_matching -from aider.tools.view_files_with_symbol import ( - _execute_view_files_with_symbol, - view_files_with_symbol_schema, -) -from aider.tools.git import ( - _execute_git_diff, - _execute_git_log, - _execute_git_show, - _execute_git_status, - git_diff_schema, - git_log_schema, - git_show_schema, - git_status_schema, -) +from aider.tools.view_files_with_symbol import _execute_view_files_with_symbol from .base_coder import ChatChunks, Coder from .editblock_coder import do_replace, find_original_update_blocks, find_similar_lines diff --git a/aider/tools/__init__.py b/aider/tools/__init__.py index ee43f51a2a4..3de1c4945fc 100644 --- a/aider/tools/__init__.py +++ b/aider/tools/__init__.py @@ -10,6 +10,16 @@ from .delete_line import _execute_delete_line, delete_line_schema 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_diff, + _execute_git_log, + _execute_git_show, + _execute_git_status, + git_diff_schema, + git_log_schema, + git_show_schema, + git_status_schema, +) from .grep import _execute_grep, grep_schema from .indent_lines import _execute_indent_lines, indent_lines_schema from .insert_block import _execute_insert_block, insert_block_schema @@ -35,13 +45,3 @@ _execute_view_files_with_symbol, view_files_with_symbol_schema, ) -from .git import ( - _execute_git_diff, - _execute_git_log, - _execute_git_show, - _execute_git_status, - git_diff_schema, - git_log_schema, - git_show_schema, - git_status_schema, -) diff --git a/aider/tools/git.py b/aider/tools/git.py index 2859a65ec43..f9fefb7f507 100644 --- a/aider/tools/git.py +++ b/aider/tools/git.py @@ -1,13 +1,12 @@ -# aider/tools/git.py - -import traceback from aider.repo import ANY_GIT_ERROR git_diff_schema = { "type": "function", "function": { "name": "git_diff", - "description": "Show the diff between the current working directory and a git branch or commit.", + "description": ( + "Show the diff between the current working directory and a git branch or commit." + ), "parameters": { "type": "object", "properties": { @@ -21,6 +20,7 @@ }, } + def _execute_git_diff(coder, branch=None): """ Show the diff between the current working directory and a git branch or commit. @@ -41,6 +41,7 @@ def _execute_git_diff(coder, branch=None): coder.io.tool_error(f"Error running git diff: {e}") return f"Error running git diff: {e}" + git_log_schema = { "type": "function", "function": { @@ -59,6 +60,7 @@ def _execute_git_diff(coder, branch=None): }, } + def _execute_git_log(coder, limit=10): """ Show the git log. @@ -71,13 +73,14 @@ def _execute_git_log(coder, limit=10): log_output = [] for commit in commits: short_hash = commit.hexsha[:8] - message = commit.message.strip().split('\n')[0] + message = commit.message.strip().split("\n")[0] log_output.append(f"{short_hash} {message}") return "\n".join(log_output) except ANY_GIT_ERROR as e: coder.io.tool_error(f"Error running git log: {e}") return f"Error running git log: {e}" + git_show_schema = { "type": "function", "function": { @@ -96,6 +99,7 @@ def _execute_git_log(coder, limit=10): }, } + def _execute_git_show(coder, object="HEAD"): """ Show various types of objects (blobs, trees, tags, and commits). @@ -109,6 +113,7 @@ def _execute_git_show(coder, object="HEAD"): coder.io.tool_error(f"Error running git show: {e}") return f"Error running git show: {e}" + git_status_schema = { "type": "function", "function": { @@ -122,6 +127,7 @@ def _execute_git_show(coder, object="HEAD"): }, } + def _execute_git_status(coder): """ Show the working tree status.