From dfa4f22be2289b351dea56d40227042378985079 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 1 Oct 2024 08:01:27 +0300 Subject: [PATCH 1/4] feat: add dual publishing mode for PR code suggestions - Introduced dual publishing mode to present high-scoring suggestions as both table entries and commitable PR comments. - Updated documentation to include configuration options for dual publishing mode. - Enhanced `pr_code_suggestions.py` to handle dual publishing logic and error handling. - Modified `configuration.toml` to include `duel_publishing_score_threshold` setting. --- docs/docs/tools/improve.md | 39 ++++++++++++++++++++------- pr_agent/settings/configuration.toml | 5 +++- pr_agent/tools/pr_code_suggestions.py | 21 ++++++++++++++- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/docs/docs/tools/improve.md b/docs/docs/tools/improve.md index b4e24a38..42610bdd 100644 --- a/docs/docs/tools/improve.md +++ b/docs/docs/tools/improve.md @@ -1,7 +1,7 @@ ## Overview The `improve` tool scans the PR code changes, and automatically generates [meaningful](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_code_suggestions_prompts.toml#L41) suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is [opened](../usage-guide/automations_and_usage.md#github-app-automatic-tools-when-a-new-pr-is-opened), or it can be invoked manually by commenting on any PR: -``` +```toml /improve ``` @@ -19,12 +19,12 @@ Note that the `Apply this suggestion` checkbox, which interactively converts a s Invoke the tool manually by commenting `/improve` on any PR. The code suggestions by default are presented as a single comment: To edit [configurations](#configuration-options) related to the improve tool, use the following template: -``` +```toml /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` For example, you can choose to present all the suggestions as commitable code comments, by running the following command: -``` +```toml /improve --pr_code_suggestions.commitable_code_suggestions=true ``` @@ -37,7 +37,7 @@ Also note that collapsible are not supported in _Bitbucket_. Hence, the suggesti ### Automatic triggering To run the `improve` automatically when a PR is opened, define in a [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/#wiki-configuration-file): -``` +```toml [github_app] pr_commands = [ "/improve", @@ -70,15 +70,32 @@ In post-process, Qodo Merge counts the number of suggestions that were implement ## Usage Tips +### Duel publishing mode +Our recommended approach for presenting code suggestions is through a [table](https://qodo-merge-docs.qodo.ai/tools/improve/#overview) (`--pr_code_suggestions.commitable_code_suggestions=false`). +This method significantly reduces the PR footprint and allows for quick and easy digestion of multiple suggestions. + +We also offer a complementary **dual publishing mode**. When enabled, suggestions exceeding a certain score threshold are not only displayed in the table, but also presented as commitable PR comments. +This mode helps highlight suggestions deemed more critical. + +To activate dual publishing mode, use the following setting: + +```toml +[pr_code_suggestions] +duel_publishing_score_threshold = x +``` + +Where x represents the minimum score threshold (>=) for suggestions to be presented as commitable PR comments in addition to the table. Default is -1 (disabled). + ### Self-review If you set in a configuration file: -``` +```toml [pr_code_suggestions] demand_code_suggestions_self_review = true ``` + The `improve` tool will add a checkbox below the suggestions, prompting user to acknowledge that they have reviewed the suggestions. You can set the content of the checkbox text via: -``` +```toml [pr_code_suggestions] code_suggestions_self_review_text = "... (your text here) ..." ``` @@ -91,7 +108,7 @@ code_suggestions_self_review_text = "... (your text here) ..." !!! tip "Tip - demanding self-review from the PR author 💎" By setting: - ``` + ```toml [pr_code_suggestions] approve_pr_on_self_review = true ``` @@ -139,7 +156,7 @@ You can use the `extra_instructions` configuration option to give the AI model a Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on. Examples for possible instructions: -``` +```toml [pr_code_suggestions] extra_instructions="""\ (1) Answer in japanese @@ -176,7 +193,7 @@ By default, Qodo Merge will look for a local `best_practices.md` wiki file in th If you want to enable also a global `best_practices.md` wiki file, set first in the global configuration file: -``` +```toml [best_practices] enable_global_best_practices = true ``` @@ -209,6 +226,10 @@ Using a combination of both can help the AI model to provide relevant and tailor commitable_code_suggestions If set to true, the tool will display the suggestions as commitable code comments. Default is false. + + duel_publishing_score_threshold + Minimum score threshold for suggestions to be presented as commitable PR comments in addition to the table. Default is -1 (disabled). + 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 9a55c494..1de42af3 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -109,7 +109,10 @@ enable_help_text=false [pr_code_suggestions] # /improve # max_context_tokens=14000 +# commitable_code_suggestions = false +duel_publishing_score_threshold=7 # -1 to disable, [0-10] to set the threshold (>=) for publishing a code suggestion both in a table and as commitable +# extra_instructions = "" rank_suggestions = false enable_help_text=false @@ -121,7 +124,7 @@ max_history_len=4 apply_suggestions_checkbox=true # suggestions scoring self_reflect_on_suggestions=true -suggestions_score_threshold=0 # [0-10]. highly recommend not to set this value above 8, since above it may clip highly relevant suggestions +suggestions_score_threshold=0 # [0-10]| recommend not to set this value above 8, since above it may clip highly relevant suggestions # params for '/improve --extended' mode auto_extended_mode=true num_code_suggestions_per_chunk=4 diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index ff9a9a2f..90baaf67 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -151,11 +151,11 @@ class PRCodeSuggestions: pr_body += HelpMessage.get_improve_usage_guide() pr_body += "\n\n" - # Output the relevant configurations if enabled if get_settings().get('config', {}).get('output_relevant_configurations', False): pr_body += show_relevant_configurations(relevant_section='pr_code_suggestions') + # publish the PR comment if get_settings().pr_code_suggestions.persistent_comment: final_update_message = False self.publish_persistent_comment_with_history(pr_body, @@ -165,6 +165,25 @@ class PRCodeSuggestions: final_update_message=final_update_message, max_previous_comments=get_settings().pr_code_suggestions.max_history_len, progress_response=self.progress_response) + + # duel publishing mode + if int(get_settings().pr_code_suggestions.duel_publishing_score_threshold) > 0: + data_above_threshold = {'code_suggestions': []} + try: + for suggestion in data['code_suggestions']: + if int(suggestion.get('score', 0)) >= int(get_settings().pr_code_suggestions.duel_publishing_score_threshold) \ + and suggestion.get('improved_code'): + data_above_threshold['code_suggestions'].append(suggestion) + if not data_above_threshold['code_suggestions'][-1]['existing_code']: + get_logger().info(f'Identical existing and improved code for duel publishing found') + data_above_threshold['code_suggestions'][-1]['existing_code'] = suggestion[ + 'improved_code'] + if data_above_threshold['code_suggestions']: + get_logger().info( + f"Publishing {len(data_above_threshold['code_suggestions'])} suggestions in duel publishing mode") + self.push_inline_code_suggestions(data_above_threshold) + except Exception as e: + get_logger().error(f"Failed to publish duel publishing suggestions, error: {e}") else: if self.progress_response: self.git_provider.edit_comment(self.progress_response, body=pr_body) From b42ded61f84bdf5a34ddcd869fe355b8085fa775 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 1 Oct 2024 08:16:51 +0300 Subject: [PATCH 2/4] docs: add guidelines for implementing proposed code suggestions in improve.md --- docs/docs/tools/improve.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/docs/tools/improve.md b/docs/docs/tools/improve.md index 42610bdd..5bba9d54 100644 --- a/docs/docs/tools/improve.md +++ b/docs/docs/tools/improve.md @@ -70,6 +70,17 @@ In post-process, Qodo Merge counts the number of suggestions that were implement ## Usage Tips +### Implementing the proposed code suggestions +Each generated suggestion consists of three key elements: + +1. A single-line summary of the proposed change +2. An expandable section containing a comprehensive description of the suggestion +3. A diff snippet showing the recommended code modification (before and after) + +We advise users to apply critical analysis and judgment when implementing the proposed suggestions. +In addition to mistakes (which may happen, but are rare), sometimes the presented code modification may serve more as an _illustrative example_ than a direct applicable solution. +In such cases, we recommend prioritizing the suggestion's detailed description, using the diff snippet primarily as a supporting reference. + ### Duel publishing mode Our recommended approach for presenting code suggestions is through a [table](https://qodo-merge-docs.qodo.ai/tools/improve/#overview) (`--pr_code_suggestions.commitable_code_suggestions=false`). This method significantly reduces the PR footprint and allows for quick and easy digestion of multiple suggestions. From da0bd847468b7c0862290a27008faf040f810074 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 1 Oct 2024 08:20:16 +0300 Subject: [PATCH 3/4] dual --- docs/docs/tools/improve.md | 6 +++--- pr_agent/settings/configuration.toml | 2 +- pr_agent/tools/pr_code_suggestions.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/docs/tools/improve.md b/docs/docs/tools/improve.md index 5bba9d54..d18ed182 100644 --- a/docs/docs/tools/improve.md +++ b/docs/docs/tools/improve.md @@ -81,7 +81,7 @@ We advise users to apply critical analysis and judgment when implementing the pr In addition to mistakes (which may happen, but are rare), sometimes the presented code modification may serve more as an _illustrative example_ than a direct applicable solution. In such cases, we recommend prioritizing the suggestion's detailed description, using the diff snippet primarily as a supporting reference. -### Duel publishing mode +### Dual publishing mode Our recommended approach for presenting code suggestions is through a [table](https://qodo-merge-docs.qodo.ai/tools/improve/#overview) (`--pr_code_suggestions.commitable_code_suggestions=false`). This method significantly reduces the PR footprint and allows for quick and easy digestion of multiple suggestions. @@ -92,7 +92,7 @@ To activate dual publishing mode, use the following setting: ```toml [pr_code_suggestions] -duel_publishing_score_threshold = x +dual_publishing_score_threshold = x ``` Where x represents the minimum score threshold (>=) for suggestions to be presented as commitable PR comments in addition to the table. Default is -1 (disabled). @@ -238,7 +238,7 @@ Using a combination of both can help the AI model to provide relevant and tailor If set to true, the tool will display the suggestions as commitable code comments. Default is false. - duel_publishing_score_threshold + 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). diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 1de42af3..fb90685b 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -111,7 +111,7 @@ enable_help_text=false max_context_tokens=14000 # commitable_code_suggestions = false -duel_publishing_score_threshold=7 # -1 to disable, [0-10] to set the threshold (>=) for publishing a code suggestion both in a table and as commitable +dual_publishing_score_threshold=7 # -1 to disable, [0-10] to set the threshold (>=) for publishing a code suggestion both in a table and as commitable # extra_instructions = "" rank_suggestions = false diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 90baaf67..ecc352f2 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -166,24 +166,24 @@ class PRCodeSuggestions: max_previous_comments=get_settings().pr_code_suggestions.max_history_len, progress_response=self.progress_response) - # duel publishing mode - if int(get_settings().pr_code_suggestions.duel_publishing_score_threshold) > 0: + # dual publishing mode + if int(get_settings().pr_code_suggestions.dual_publishing_score_threshold) > 0: data_above_threshold = {'code_suggestions': []} try: for suggestion in data['code_suggestions']: - if int(suggestion.get('score', 0)) >= int(get_settings().pr_code_suggestions.duel_publishing_score_threshold) \ + if int(suggestion.get('score', 0)) >= int(get_settings().pr_code_suggestions.dual_publishing_score_threshold) \ and suggestion.get('improved_code'): data_above_threshold['code_suggestions'].append(suggestion) if not data_above_threshold['code_suggestions'][-1]['existing_code']: - get_logger().info(f'Identical existing and improved code for duel publishing found') + get_logger().info(f'Identical existing and improved code for dual publishing found') data_above_threshold['code_suggestions'][-1]['existing_code'] = suggestion[ 'improved_code'] if data_above_threshold['code_suggestions']: get_logger().info( - f"Publishing {len(data_above_threshold['code_suggestions'])} suggestions in duel publishing mode") + f"Publishing {len(data_above_threshold['code_suggestions'])} suggestions in dual publishing mode") self.push_inline_code_suggestions(data_above_threshold) except Exception as e: - get_logger().error(f"Failed to publish duel publishing suggestions, error: {e}") + get_logger().error(f"Failed to publish dual publishing suggestions, error: {e}") else: if self.progress_response: self.git_provider.edit_comment(self.progress_response, body=pr_body) From 8ff8b1d48ec6931ddcc250864d16a1845f6879a3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 1 Oct 2024 08:22:28 +0300 Subject: [PATCH 4/4] default --- pr_agent/settings/configuration.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index fb90685b..5f4e14ab 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -111,7 +111,7 @@ enable_help_text=false max_context_tokens=14000 # commitable_code_suggestions = false -dual_publishing_score_threshold=7 # -1 to disable, [0-10] to set the threshold (>=) for publishing a code suggestion both in a table and as commitable +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 # extra_instructions = "" rank_suggestions = false