diff --git a/README.md b/README.md index e96d31b5..bfc7ded4 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,26 @@ Qode Merge PR-Agent aims to help efficiently review and handle pull requests, by ## News and Updates +### November 7, 2024 + +Added new option: `--pr_code_suggestions.focus_only_on_problems=true` + +When enabled, this option reduces the number of code suggestions and categorizes them into just two groups: "Possible Issues" and "General". The suggestions will focus primarily on identifying and fixing code problems, rather than style considerations like best practices, maintainability, or readability. + +This mode is ideal for developers who want to concentrate specifically on finding and fixing potential bugs in their pull request code. + + +**Example results:** + +Original mode + + + +Focused mode + + + + ### November 4, 2024 Qodo Merge PR Agent will now leverage context from Jira or GitHub tickets to enhance the PR Feedback. Read more about this feature diff --git a/docs/docs/tools/improve.md b/docs/docs/tools/improve.md index fed8101c..524f49b8 100644 --- a/docs/docs/tools/improve.md +++ b/docs/docs/tools/improve.md @@ -275,6 +275,10 @@ Using a combination of both can help the AI model to provide relevant and tailor dual_publishing_score_threshold Minimum score threshold for suggestions to be presented as commitable PR comments in addition to the table. Default is -1 (disabled). + + focus_only_on_problems + If set to true, suggestions will focus primarily on identifying and fixing code problems, and less on style considerations like best practices, maintainability, or readability. Default is false. + persistent_comment If set to true, the improve comment will be persistent, meaning that every new improve request will edit the previous one. Default is false. diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 80e2ad84..97d8d363 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -107,10 +107,11 @@ enable_help_text=false [pr_code_suggestions] # /improve # -max_context_tokens=14000 +max_context_tokens=16000 # commitable_code_suggestions = false dual_publishing_score_threshold=-1 # -1 to disable, [0-10] to set the threshold (>=) for publishing a code suggestion both in a table and as commitable +focus_only_on_problems=false # extra_instructions = "" rank_suggestions = false diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index b08a3a2a..c25e4bb2 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -1,7 +1,10 @@ [pr_code_suggestions_prompt] system="""You are PR-Reviewer, an AI specializing in Pull Request (PR) code analysis and suggestions. -Your task is to examine the provided code diff, focusing on new code (lines prefixed with '+'), and offer concise, actionable suggestions to fix possible bugs and problems, and enhance code quality, readability, and performance. - +{%- if not focus_only_on_problems %} +Your task is to examine the provided code diff, focusing on new code (lines prefixed with '+'), and offer concise, actionable suggestions to fix possible bugs and problems, and enhance code quality and performance. +{%- else %} +Your task is to examine the provided code diff, focusing on new code (lines prefixed with '+'), and offer concise, actionable suggestions to fix critical bugs and problems. +{%- endif %} The PR code diff will be in the following structured format: ====== @@ -42,9 +45,17 @@ __new hunk__ Specific guidelines for generating code suggestions: +{%- if not focus_only_on_problems %} - Provide up to {{ num_code_suggestions }} distinct and insightful code suggestions. +{%- else %} +- Provide up to {{ num_code_suggestions }} distinct and insightful code suggestions. Return less suggestions if no pertinent ones are applicable. +{%- endif %} - Focus solely on enhancing new code introduced in the PR, identified by '+' prefixes in '__new hunk__' sections. +{%- if not focus_only_on_problems %} - Prioritize suggestions that address potential issues, critical problems, and bugs in the PR code. Avoid repeating changes already implemented in the PR. If no pertinent suggestions are applicable, return an empty list. +{%- else %} +- Only give suggestions that address critical problems and bugs in the PR code. If no relevant suggestions are applicable, return an empty list. +{%- endif %} - Don't suggest to add docstring, type hints, or comments, to remove unused imports, or to use more specific exception types. - When referencing variables or names from the code, enclose them in backticks (`). Example: "ensure that `variable_name` is..." - Be mindful you are viewing a partial PR code diff, not the full codebase. Avoid suggestions that might conflict with unseen code or alerting variables not declared in the visible scope, as the context is incomplete. @@ -69,7 +80,11 @@ class CodeSuggestion(BaseModel): existing_code: str = Field(description="A short code snippet from a '__new hunk__' section that the suggestion aims to enhance or fix. Include only complete code lines. Use ellipsis (...) for brevity if needed. This snippet should represent the specific PR code targeted for improvement.") improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion.") one_sentence_summary: str = Field(description="A concise, single-sentence overview of the suggested improvement. Focus on the 'what'. Be general, and avoid method or variable names.") +{%- if not focus_only_on_problems %} label: str = Field(description="A single, descriptive label that best characterizes the suggestion type. Possible labels include 'security', 'possible bug', 'possible issue', 'performance', 'enhancement', 'best practice', 'maintainability', 'typo'. Other relevant labels are also acceptable.") +{%- else %} + label: str = Field(description="A single, descriptive label that best characterizes the suggestion type. Possible labels include 'security', 'critical bug', 'general'. The 'general' section should be used for suggestions that address a major issue, but are necessarily on a critical level.") +{%- endif %} class PRCodeSuggestions(BaseModel): diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index e510bcb0..98fbb629 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -76,6 +76,7 @@ class PRCodeSuggestions: "commit_messages_str": self.git_provider.get_commit_messages(), "relevant_best_practices": "", "is_ai_metadata": get_settings().get("config.enable_ai_metadata", False), + "focus_only_on_problems": get_settings().get("pr_code_suggestions.focus_only_on_problems", False), } self.pr_code_suggestions_prompt_system = get_settings().pr_code_suggestions_prompt.system @@ -451,6 +452,11 @@ class PRCodeSuggestions: if not is_valid_keys: continue + if get_settings().get("pr_code_suggestions.focus_only_on_problems", False): + CRITICAL_LABEL = 'critical' + if CRITICAL_LABEL in suggestion['label'].lower(): # we want the published labels to be less declarative + suggestion['label'] = 'possible issue' + if suggestion['one_sentence_summary'] in one_sentence_summary_list: get_logger().debug(f"Skipping suggestion {i + 1}, because it is a duplicate: {suggestion}") continue