From d2663f959ae040667abe27e2f937741193957f09 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 6 Nov 2024 21:22:58 +0200 Subject: [PATCH 1/5] Add focus_only_on_problems setting for targeted code suggestions --- pr_agent/settings/configuration.toml | 3 ++- .../settings/pr_code_suggestions_prompts.toml | 19 +++++++++++++++++-- pr_agent/tools/pr_code_suggestions.py | 6 ++++++ 3 files changed, 25 insertions(+), 3 deletions(-) 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 From a8c97bfa7398bcfe938aa7de5005f3f9981a21a5 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Nov 2024 08:30:18 +0200 Subject: [PATCH 2/5] Add documentation for focus_only_on_problems setting in improve.md and README.md --- README.md | 8 ++++++++ docs/docs/tools/improve.md | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index e96d31b5..9f04c539 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,14 @@ 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. + ### 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. From 7a5e9102fd33690bc03d36a2464deff2338bf1db Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Nov 2024 08:59:10 +0200 Subject: [PATCH 3/5] Add documentation for focus_only_on_problems setting in improve.md and README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 9f04c539..8eaae23d 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,16 @@ When enabled, this option reduces the number of code suggestions and categorizes This mode is ideal for developers who want to concentrate specifically on finding and fixing potential bugs in their pull request code. +Example result: + +Original mode + +![image](https://qodo.ai/images/pr_agent/code_suggestions_original_mode.png) + +Focused mode + +![image](https://qodo.ai/images/pr_agent/code_suggestions_focused_mode.png) + ### 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 From ee26bf35c17c46999cd036bfbeedee796708512b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Nov 2024 09:06:30 +0200 Subject: [PATCH 4/5] Add documentation for focus_only_on_problems setting in improve.md and README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8eaae23d..0d94c49b 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,12 @@ Example result: Original mode -![image](https://qodo.ai/images/pr_agent/code_suggestions_original_mode.png) + Focused mode -![image](https://qodo.ai/images/pr_agent/code_suggestions_focused_mode.png) + + ### November 4, 2024 From 84d0f80c81f4d1d8ceeabb4ac6de2a9387f0099c Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Nov 2024 09:07:16 +0200 Subject: [PATCH 5/5] Add documentation for focus_only_on_problems setting in improve.md and README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d94c49b..bfc7ded4 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,8 @@ When enabled, this option reduces the number of code suggestions and categorizes This mode is ideal for developers who want to concentrate specifically on finding and fixing potential bugs in their pull request code. -Example result: + +**Example results:** Original mode