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)