From 25eb15a1c15bc862c6f0ea8454a9cbe92a8a157c Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:34:34 +0000 Subject: [PATCH 1/4] Add params to edit_sweep_comment function --- sweepai/handlers/on_ticket.py | 45 +++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/sweepai/handlers/on_ticket.py b/sweepai/handlers/on_ticket.py index 12de88b47e..506637e30d 100644 --- a/sweepai/handlers/on_ticket.py +++ b/sweepai/handlers/on_ticket.py @@ -264,12 +264,18 @@ def on_ticket( def edit_sweep_comment( message: str, index: int, + current_index: int, + user_token: str, + g: Github, + repo: Repository, + issue_comment: IssueComment, + initial_sandbox_response: int, + initial_sandbox_response_file: str, pr_message="", done=False, step_complete=True, add_bonus_message=True, ): - nonlocal current_index, user_token, g, repo, issue_comment, initial_sandbox_response, initial_sandbox_response_file message = sanitize_string_for_github(message) if pr_message: pr_message = sanitize_string_for_github(pr_message) @@ -391,7 +397,14 @@ def edit_sweep_comment( edit_sweep_comment( "I've just finished validating the issue. I'm now going to start searching for relevant files.", - 0 + 0, + current_index, + user_token, + g, + repo, + issue_comment, + initial_sandbox_response, + initial_sandbox_response_file ) prs_extracted = PRReader.extract_prs(repo, summary) @@ -456,6 +469,13 @@ def edit_sweep_comment( else "" ), 1, + current_index, + user_token, + g, + repo, + issue_comment, + initial_sandbox_response, + initial_sandbox_response_file, step_complete=False ) else: @@ -484,6 +504,13 @@ def edit_sweep_comment( else "" ), 1, + current_index, + user_token, + g, + repo, + issue_comment, + initial_sandbox_response, + initial_sandbox_response_file ) # # Search agent @@ -549,6 +576,13 @@ def edit_sweep_comment( edit_sweep_comment( "I'm currently validating your changes using parsers and linters to check for mistakes like syntax errors or undefined variables. If I see any of these errors, I will automatically fix them.", 3, + current_index, + user_token, + g, + repo, + issue_comment, + initial_sandbox_response, + initial_sandbox_response_file ) pull_request: SweepPullRequest = SweepPullRequest( title="Sweep: " + title, @@ -586,6 +620,13 @@ def edit_sweep_comment( edit_sweep_comment( f"Your changes have been successfully made to the branch [`{pull_request.branch_name}`](https://github.com/{repo_full_name}/tree/{pull_request.branch_name}). I have validated these changes using a syntax checker and a linter.", 3, + current_index, + user_token, + g, + repo, + issue_comment, + initial_sandbox_response, + initial_sandbox_response_file ) except Exception as e: logger.exception(e) From 4012a5d36417827c2052aa1200bcdb387a04400f Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:39:18 +0000 Subject: [PATCH 2/4] Add imports to sweep_bot.py and on_ticket.py --- sweepai/core/sweep_bot.py | 1 + sweepai/handlers/on_ticket.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sweepai/core/sweep_bot.py b/sweepai/core/sweep_bot.py index 5b2185ef38..78b95a7841 100644 --- a/sweepai/core/sweep_bot.py +++ b/sweepai/core/sweep_bot.py @@ -58,6 +58,7 @@ from sweepai.core.entities import parse_fcr from sweepai.utils.str_utils import extract_object_fields_from_string from sweepai.utils.streamable_functions import streamable +from sweepai.core.entities import validate_file_change_requests BOT_ANALYSIS_SUMMARY = "bot_analysis_summary" SNIPPET_TOKEN_BUDGET = int(150_000 * 3.5) # 140k tokens diff --git a/sweepai/handlers/on_ticket.py b/sweepai/handlers/on_ticket.py index 506637e30d..5b1c7e8bf8 100644 --- a/sweepai/handlers/on_ticket.py +++ b/sweepai/handlers/on_ticket.py @@ -8,8 +8,9 @@ import traceback from time import time -from github import BadCredentialsException +from github import BadCredentialsException, Github, IssueComment from github.PullRequest import PullRequest as GithubPullRequest +from github.Repository import Repository from loguru import logger From cce28627f4b03c75d15e421341721c502edca3bd Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 21:07:26 +0000 Subject: [PATCH 3/4] Improve file handling and error reporting in sweep --- sweepai/core/sweep_bot.py | 4 ++-- sweepai/handlers/on_comment.py | 4 ++-- sweepai/handlers/on_ticket.py | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sweepai/core/sweep_bot.py b/sweepai/core/sweep_bot.py index 78b95a7841..0c0c2c91b6 100644 --- a/sweepai/core/sweep_bot.py +++ b/sweepai/core/sweep_bot.py @@ -58,7 +58,7 @@ from sweepai.core.entities import parse_fcr from sweepai.utils.str_utils import extract_object_fields_from_string from sweepai.utils.streamable_functions import streamable -from sweepai.core.entities import validate_file_change_requests + BOT_ANALYSIS_SUMMARY = "bot_analysis_summary" SNIPPET_TOKEN_BUDGET = int(150_000 * 3.5) # 140k tokens @@ -1161,7 +1161,7 @@ def get_files_to_change_for_chat( logger.debug("New indices", error_indices) yield renames_dict, user_facing_message + "Here are the changes we decided to make. I'm currently just making some edits:\n", file_change_requests - validate_file_change_requests(file_change_requests, cloned_repo, renames_dict=renames_dict) + yield renames_dict, user_facing_message + "Here are the changes we decided to make. I'm done making edits and now I'm just validating the changes using a linter to catch any mistakes like syntax errors or undefined variables:\n", file_change_requests return renames_dict, file_change_requests, files_to_change_response except RegexMatchError as e: diff --git a/sweepai/handlers/on_comment.py b/sweepai/handlers/on_comment.py index be76520ec1..8ac9d3064b 100644 --- a/sweepai/handlers/on_comment.py +++ b/sweepai/handlers/on_comment.py @@ -345,8 +345,8 @@ def edit_comment(new_comment: str) -> None: username, "polluted_commits_error", properties={ - "old_keys": ",".join(previous_file_contents_to_commit.keys()), - "new_keys": ",".join(new_file_contents_to_commit.keys()) + "old_keys": ",".join(previous_file_contents_to_commit), + "new_keys": ",".join(new_file_contents_to_commit) }, ) commit = commit_multi_file_changes(cloned_repo, new_file_contents_to_commit, commit_message, branch_name) diff --git a/sweepai/handlers/on_ticket.py b/sweepai/handlers/on_ticket.py index 5b1c7e8bf8..a6a04370e7 100644 --- a/sweepai/handlers/on_ticket.py +++ b/sweepai/handlers/on_ticket.py @@ -419,6 +419,13 @@ def edit_sweep_comment( ), ), 1, + current_index, + user_token, + g, + repo, + issue_comment, + initial_sandbox_response, + initial_sandbox_response_file ) try: @@ -483,6 +490,13 @@ def edit_sweep_comment( edit_sweep_comment( message, 1, + current_index, + user_token, + g, + repo, + issue_comment, + initial_sandbox_response, + initial_sandbox_response_file, step_complete=False ) @@ -614,7 +628,7 @@ def edit_sweep_comment( "polluted_commits_error", properties={ "old_keys": ",".join(previous_file_contents_to_commit.keys()), - "new_keys": ",".join(new_file_contents_to_commit.keys()) + "new_keys": ",".join(new_file_contents_to_commit.keys()) }, ) commit = commit_multi_file_changes(cloned_repo, new_file_contents_to_commit, commit_message, pull_request.branch_name, renames_dict=renames_dict) From 0d3aa34921591d70a89f106d6ebd6c2e4564bbb5 Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Mon, 17 Jun 2024 21:21:43 +0000 Subject: [PATCH 4/4] Update modify_files_dict loop in create_pr.py --- sweepai/handlers/create_pr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sweepai/handlers/create_pr.py b/sweepai/handlers/create_pr.py index 824cc02fe8..18c95ad685 100644 --- a/sweepai/handlers/create_pr.py +++ b/sweepai/handlers/create_pr.py @@ -91,7 +91,7 @@ def handle_file_change_requests( if not previous_modify_files_dict: previous_modify_files_dict = {} if modify_files_dict: - for file_name, file_content in modify_files_dict.items(): + for file_name, file_content in dict(modify_files_dict).items(): previous_modify_files_dict[file_name] = copy.deepcopy(file_content) # update status of corresponding fcr to be succeeded for file_change_request in file_change_requests: