diff --git a/sweepai/agents/modify.py b/sweepai/agents/modify.py index c7188136f2..dcafefa38d 100644 --- a/sweepai/agents/modify.py +++ b/sweepai/agents/modify.py @@ -25,12 +25,12 @@ def generate_code_suggestions( if fcr.filename not in modify_order: modify_order.append(fcr.filename) - code_suggestions = [] + applied_code_suggestions = [] for file_path in modify_order: if file_path in modify_files_dict: file_data = modify_files_dict[file_path] if file_data["original_contents"] != file_data["contents"]: - code_suggestions.append(StatefulCodeSuggestion( + applied_code_suggestions.append(StatefulCodeSuggestion( file_path=file_path, original_code=file_data["original_contents"], new_code=file_data["contents"], @@ -38,26 +38,23 @@ def generate_code_suggestions( state="done" )) - current_fcr_index = next((i for i, fcr in enumerate(fcrs) if not fcr.is_completed), -1) - if current_fcr_index >= 0: - for i, fcr in enumerate(fcrs): - if i < current_fcr_index: - continue - else: - parsed_fcr = parse_fcr(fcr) - try: - file_contents = cloned_repo.get_file_contents(fcr.filename) - except FileNotFoundError: - file_contents = "" - code_suggestions.append(StatefulCodeSuggestion( - file_path=fcr.filename, - original_code=parsed_fcr["original_code"][0] if parsed_fcr["original_code"] else "", - new_code=parsed_fcr["new_code"][0] if parsed_fcr["new_code"] else "", - file_contents=file_contents, - state=("processing" if i == current_fcr_index else "pending"), - error=error_messages_dict.get(i, None) - )) - return code_suggestions + queued_code_suggestions = [] + current_fcr_index = next((i for i, fcr in enumerate(fcrs) if not fcr.is_completed), len(fcrs)) + for i, fcr in enumerate(fcrs): + parsed_fcr = parse_fcr(fcr) + try: + file_contents = cloned_repo.get_file_contents(fcr.filename) + except FileNotFoundError: + file_contents = "" + queued_code_suggestions.append(StatefulCodeSuggestion( + file_path=fcr.filename, + original_code=parsed_fcr["original_code"][0] if parsed_fcr["original_code"] else "", + new_code=parsed_fcr["new_code"][0] if parsed_fcr["new_code"] else "", + file_contents=file_contents, + state=("processing" if i == current_fcr_index else ("pending" if i > current_fcr_index else "done")), + error=error_messages_dict.get(i, None) + )) + return applied_code_suggestions, queued_code_suggestions @streamable def modify( diff --git a/sweepai/chat/api.py b/sweepai/chat/api.py index e8e0c0214d..6152bd3c31 100644 --- a/sweepai/chat/api.py +++ b/sweepai/chat/api.py @@ -825,6 +825,7 @@ def handle_function_call(function_call: AnthropicFunctionCall, repo_name: str, s async def autofix( repo_name: str = Body(...), code_suggestions: list[CodeSuggestion] = Body(...), + modify_files_dict: dict = Body({}), branch: str = Body(None), access_token: str = Depends(get_token_header) ):# -> dict[str, Any] | StreamingResponse: @@ -867,13 +868,17 @@ async def autofix( def stream(): try: - for stateful_code_suggestions in modify.stream( + for applied_code_suggestions, queued_code_suggestions in modify.stream( fcrs=file_change_requests, request="", cloned_repo=cloned_repo, relevant_filepaths=[code_suggestion.file_path for code_suggestion in code_suggestions], + previous_modify_files_dict=modify_files_dict ): - yield json.dumps([stateful_code_suggestion.__dict__ for stateful_code_suggestion in stateful_code_suggestions]) + yield json.dumps({ + "applied_code_suggestions": [stateful_code_suggestion.__dict__ for stateful_code_suggestion in applied_code_suggestions], + "queued_code_suggestions": [stateful_code_suggestion.__dict__ for stateful_code_suggestion in queued_code_suggestions] + }) except Exception as e: yield json.dumps({"error": str(e)}) raise e @@ -1060,7 +1065,9 @@ async def create_pull_metadata( @app.post("/backend/validate_pull") async def validate_pull( repo_name: str = Body(...), + # branch: str = Body(...), pull_request_number: int = Body(...), + modify_files_dict: dict = Body({}), access_token: str = Depends(get_token_header) ): with Timer() as timer: @@ -1163,7 +1170,6 @@ async def write_message_to_disk( repo_name: str = Body(...), messages: list[Message] = Body(...), snippets: list[Snippet] = Body(...), - original_code_suggestions: list = Body([]), code_suggestions: list = Body([]), pull_request: dict | None = Body(None), pull_request_title: str = Body(""), @@ -1180,7 +1186,6 @@ async def write_message_to_disk( "repo_name": repo_name, "messages": [message.model_dump() for message in messages], "snippets": [snippet.model_dump() for snippet in snippets], - "original_code_suggestions": [code_suggestion.__dict__ if isinstance(code_suggestion, CodeSuggestion) else code_suggestion for code_suggestion in original_code_suggestions], "code_suggestions": [code_suggestion.__dict__ if isinstance(code_suggestion, CodeSuggestion) else code_suggestion for code_suggestion in code_suggestions], "pull_request": pull_request, "user_mentioned_pull_request": user_mentioned_pull_request, @@ -1191,6 +1196,7 @@ async def write_message_to_disk( } with open(f"{CACHE_DIRECTORY}/messages/{message_id}.json", "w") as file: json.dump(data, file) + logger.info(f"Saved {len(messages)} messages to {message_id}.json") return {"status": "success", "message": "Message written to disk successfully.", "message_id": message_id} except Exception as e: logger.error(f"Failed to write message to disk: {str(e)}") @@ -1203,6 +1209,7 @@ async def read_message_from_disk( try: with open(f"{CACHE_DIRECTORY}/messages/{message_id}.json", "r") as file: message_data = json.load(file) + logger.info(f"Loaded {len(message_data['messages'])} messages from {message_id}.json") return { "status": "success", "message": "Message read from disk successfully.",