From 16b9ccd0259a8d3a32db2366516b431aa5b20153 Mon Sep 17 00:00:00 2001 From: soprue Date: Sat, 24 May 2025 23:43:16 +0900 Subject: [PATCH 01/12] feat: conditionally include diagram in output example --- pr_agent/settings/pr_description_prompts.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 73ec8459..d37839d5 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -60,6 +60,14 @@ type: - ... description: | ... +{%- if add_diagram %} +diagram: | + sequenceDiagram + participant A as ComponentA + participant B as ComponentB + A->>B: functionCall() + B-->>A: response +{%- endif %} title: | ... {%- if enable_semantic_files_types %} @@ -141,6 +149,14 @@ type: - ... description: | ... +{%- if add_diagram %} +diagram: | + sequenceDiagram + participant A as ComponentA + participant B as ComponentB + A->>B: functionCall() + B-->>A: response +{%- endif %} title: | ... {%- if enable_semantic_files_types %} From d62cbb2fc4058e998c745f76c33b76e6717d9fe7 Mon Sep 17 00:00:00 2001 From: yujindonut Date: Sun, 25 May 2025 10:28:50 +0900 Subject: [PATCH 02/12] feat: add add_diagram flag in configuration.toml --- pr_agent/settings/configuration.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index c6437931..15c99a32 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -103,6 +103,7 @@ enable_pr_type=true final_update_message = true enable_help_text=false enable_help_comment=true +add_diagram=false # describe as comment publish_description_as_comment=false publish_description_as_comment_persistent=true From 5a0affd6cba57b8e08bbc90dc39719de7d214b33 Mon Sep 17 00:00:00 2001 From: ssunbear Date: Sun, 25 May 2025 11:08:52 +0900 Subject: [PATCH 03/12] feat: add add_diagram configuration option to PR description --- pr_agent/tools/pr_description.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index df82db67..bc8983f4 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -73,6 +73,7 @@ class PRDescription: "related_tickets": "", "include_file_summary_changes": len(self.git_provider.get_diff_files()) <= self.COLLAPSIBLE_FILE_LIST_THRESHOLD, 'duplicate_prompt_examples': get_settings().config.get('duplicate_prompt_examples', False), + "add_diagram": get_settings().config.get('pr_description.add_diagram', True), } self.user_description = self.git_provider.get_user_description() From 94e1126b003f056f0da2e53e0af591fa4d510333 Mon Sep 17 00:00:00 2001 From: Judonguk Date: Sun, 25 May 2025 11:09:11 +0900 Subject: [PATCH 04/12] add docs about Mermaid Diagram --- docs/docs/tools/describe.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/docs/tools/describe.md b/docs/docs/tools/describe.md index 0f2c45a7..4f4e2232 100644 --- a/docs/docs/tools/describe.md +++ b/docs/docs/tools/describe.md @@ -1,6 +1,18 @@ ## Overview The `describe` tool scans the PR code changes, and generates a description for the PR - title, type, summary, walkthrough and labels. +### Mermaid Diagram Support +When the `add_diagram` option is enabled in your configuration, the `/describe` tool will include a `Mermaid` sequence diagram in the PR description. + +This diagram represents interactions between components/functions based on the diff content. + +### How to enable + +In your configuration: + +toml +[pr_description] +add_diagram = true 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: @@ -109,6 +121,10 @@ Everything below this marker is treated as previously auto-generated content and enable_help_text If set to true, the tool will display a help text in the comment. Default is false. + + add_diagram + If set to true, the tool will generate a Mermaid sequence diagram (in code block format) describing component interactions based on the code changes. Default is false. + ## Inline file summary 💎 From 3a385b62d6bce11841302775e56a5c601d219684 Mon Sep 17 00:00:00 2001 From: isExample Date: Sun, 25 May 2025 11:51:22 +0900 Subject: [PATCH 05/12] feat: conditionally append Mermaid sequence diagram instruction in pr_description prompt --- pr_agent/settings/pr_description_prompts.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 73ec8459..1dd76d7b 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -44,7 +44,7 @@ class FileDescription(BaseModel): class PRDescription(BaseModel): type: List[PRType] = Field(description="one or more types that describe the PR content. Return the label member value (e.g. 'Bug fix', not 'bug_fix')") - description: str = Field(description="summarize the PR changes in up to four bullet points, each up to 8 words. For large PRs, add sub-bullets if needed. Order bullets by importance, with each bullet highlighting a key change group.") + description: str = Field(description="summarize the PR changes in up to four bullet points, each up to 8 words. For large PRs, add sub-bullets if needed. Order bullets by importance, with each bullet highlighting a key change group. {% if add_diagram %} Also, generate a Mermaid sequence diagram that focuses on the main function call flow between classes or components. {% endif %}") title: str = Field(description="a concise and descriptive title that captures the PR's main theme") {%- if enable_semantic_files_types %} pr_files: List[FileDescription] = Field(max_items=20, description="a list of all the files that were changed in the PR, and summary of their changes. Each file must be analyzed regardless of change size.") From c346d784e394c3a9580a37f7cded10d783fc5b33 Mon Sep 17 00:00:00 2001 From: chilln Date: Sun, 25 May 2025 12:47:09 +0900 Subject: [PATCH 06/12] docs:move sequence diagram section below main explanation of describe --- docs/docs/tools/describe.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/docs/tools/describe.md b/docs/docs/tools/describe.md index 4f4e2232..03cb0c62 100644 --- a/docs/docs/tools/describe.md +++ b/docs/docs/tools/describe.md @@ -1,18 +1,6 @@ ## Overview The `describe` tool scans the PR code changes, and generates a description for the PR - title, type, summary, walkthrough and labels. -### Mermaid Diagram Support -When the `add_diagram` option is enabled in your configuration, the `/describe` tool will include a `Mermaid` sequence diagram in the PR description. - -This diagram represents interactions between components/functions based on the diff content. - -### How to enable - -In your configuration: - -toml -[pr_description] -add_diagram = true 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: @@ -68,6 +56,19 @@ Everything below this marker is treated as previously auto-generated content and ![Describe comment](https://codium.ai/images/pr_agent/pr_description_user_description.png){width=512} +### Sequence Diagram Support +When the `add_diagram` option is enabled in your configuration, the `/describe` tool will include a `Mermaid` sequence diagram in the PR description. + +This diagram represents interactions between components/functions based on the diff content. + +### How to enable + +In your configuration: + +toml +[pr_description] +add_diagram = true + ## Configuration options !!! example "Possible configurations" From f58c40a6aed7cde8ee4a0032d57223bf91af10d9 Mon Sep 17 00:00:00 2001 From: chilln Date: Sun, 25 May 2025 12:48:13 +0900 Subject: [PATCH 07/12] refactor: replace single quotes with double quotes to match existing code style --- pr_agent/tools/pr_description.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index bc8983f4..1f28fb69 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -72,7 +72,7 @@ class PRDescription: "enable_semantic_files_types": get_settings().pr_description.enable_semantic_files_types, "related_tickets": "", "include_file_summary_changes": len(self.git_provider.get_diff_files()) <= self.COLLAPSIBLE_FILE_LIST_THRESHOLD, - 'duplicate_prompt_examples': get_settings().config.get('duplicate_prompt_examples', False), + "duplicate_prompt_examples": get_settings().config.get("duplicate_prompt_examples", False), "add_diagram": get_settings().config.get('pr_description.add_diagram', True), } From e57d3101e4ae2edf4164b78efdf88f0351d1e75d Mon Sep 17 00:00:00 2001 From: chilln Date: Sun, 25 May 2025 12:48:29 +0900 Subject: [PATCH 08/12] fix:set parameter default to false to make the feature opt-in by design --- pr_agent/tools/pr_description.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 1f28fb69..84dd2b47 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -73,7 +73,7 @@ class PRDescription: "related_tickets": "", "include_file_summary_changes": len(self.git_provider.get_diff_files()) <= self.COLLAPSIBLE_FILE_LIST_THRESHOLD, "duplicate_prompt_examples": get_settings().config.get("duplicate_prompt_examples", False), - "add_diagram": get_settings().config.get('pr_description.add_diagram', True), + "add_diagram": get_settings().config.get('pr_description.add_diagram', False), } self.user_description = self.git_provider.get_user_description() From aa3e5b79c89600c03db79c95b8aabae93ca9cd27 Mon Sep 17 00:00:00 2001 From: chilln Date: Sun, 25 May 2025 17:55:14 +0900 Subject: [PATCH 09/12] docs:apply proper formatting to documentation --- docs/docs/tools/describe.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/docs/tools/describe.md b/docs/docs/tools/describe.md index 03cb0c62..1127c875 100644 --- a/docs/docs/tools/describe.md +++ b/docs/docs/tools/describe.md @@ -65,9 +65,11 @@ This diagram represents interactions between components/functions based on the d In your configuration: +``` toml [pr_description] add_diagram = true +``` ## Configuration options From 6aac41a0dfd58c8de0e0f8607fd9845ab9189832 Mon Sep 17 00:00:00 2001 From: chilln Date: Sun, 25 May 2025 18:27:03 +0900 Subject: [PATCH 10/12] refactor:rename to --- 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 15c99a32..5d39796b 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -103,7 +103,7 @@ enable_pr_type=true final_update_message = true enable_help_text=false enable_help_comment=true -add_diagram=false +enable_pr_diagram=false # adds a section with a diagram of the PR changes # describe as comment publish_description_as_comment=false publish_description_as_comment_persistent=true From d5dead5c7f63acd501ce1dd10b1f6175cb8d733f Mon Sep 17 00:00:00 2001 From: chilln Date: Sun, 25 May 2025 18:37:28 +0900 Subject: [PATCH 11/12] refactor: moved diagram logic to 'changes_diagram' in PRDescription and updated prompt for clarity --- pr_agent/settings/pr_description_prompts.toml | 35 +++++++++---------- pr_agent/tools/pr_description.py | 8 +++-- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 8a66f2f9..bbe55252 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -44,11 +44,14 @@ class FileDescription(BaseModel): class PRDescription(BaseModel): type: List[PRType] = Field(description="one or more types that describe the PR content. Return the label member value (e.g. 'Bug fix', not 'bug_fix')") - description: str = Field(description="summarize the PR changes in up to four bullet points, each up to 8 words. For large PRs, add sub-bullets if needed. Order bullets by importance, with each bullet highlighting a key change group. {% if add_diagram %} Also, generate a Mermaid sequence diagram that focuses on the main function call flow between classes or components. {% endif %}") + description: str = Field(description="summarize the PR changes in up to four bullet points, each up to 8 words. For large PRs, add sub-bullets if needed. Order bullets by importance, with each bullet highlighting a key change group.") title: str = Field(description="a concise and descriptive title that captures the PR's main theme") {%- if enable_semantic_files_types %} pr_files: List[FileDescription] = Field(max_items=20, description="a list of all the files that were changed in the PR, and summary of their changes. Each file must be analyzed regardless of change size.") {%- endif %} +{%- if enable_pr_diagram %} + changes_diagram: str = Field(description="a horizontal diagram that represents the main PR changes, in the format of a mermaid flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant.") +{%- endif %} ===== @@ -60,14 +63,6 @@ type: - ... description: | ... -{%- if add_diagram %} -diagram: | - sequenceDiagram - participant A as ComponentA - participant B as ComponentB - A->>B: functionCall() - B-->>A: response -{%- endif %} title: | ... {%- if enable_semantic_files_types %} @@ -84,6 +79,12 @@ pr_files: label_key_1 ... {%- endif %} +{%- if enable_pr_diagram %} + changes_diagram: | + ```mermaid + ... + ``` +{%- endif %} ``` Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|') @@ -149,14 +150,6 @@ type: - ... description: | ... -{%- if add_diagram %} -diagram: | - sequenceDiagram - participant A as ComponentA - participant B as ComponentB - A->>B: functionCall() - B-->>A: response -{%- endif %} title: | ... {%- if enable_semantic_files_types %} @@ -173,6 +166,12 @@ pr_files: label_key_1 ... {%- endif %} +{%- if enable_pr_diagram %} + changes_diagram: | + ```mermaid + ... + ``` +{%- endif %} ``` (replace '...' with the actual values) {%- endif %} @@ -180,4 +179,4 @@ pr_files: Response (should be a valid YAML, and nothing else): ```yaml -""" +""" \ No newline at end of file diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 84dd2b47..3bd4ecf7 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -73,7 +73,7 @@ class PRDescription: "related_tickets": "", "include_file_summary_changes": len(self.git_provider.get_diff_files()) <= self.COLLAPSIBLE_FILE_LIST_THRESHOLD, "duplicate_prompt_examples": get_settings().config.get("duplicate_prompt_examples", False), - "add_diagram": get_settings().config.get('pr_description.add_diagram', False), + "enable_pr_diagram": get_settings().pr_description.get("enable_pr_diagram", False), } self.user_description = self.git_provider.get_user_description() @@ -457,6 +457,10 @@ class PRDescription: self.data['labels'] = self.data.pop('labels') if 'description' in self.data: self.data['description'] = self.data.pop('description') + if 'changes_diagram' in self.data: + changes_diagram = self.data.pop('changes_diagram') + if changes_diagram.strip(): + self.data['changes_diagram'] = changes_diagram if 'pr_files' in self.data: self.data['pr_files'] = self.data.pop('pr_files') @@ -821,4 +825,4 @@ def replace_code_tags(text): parts = text.split('`') for i in range(1, len(parts), 2): parts[i] = '' + parts[i] + '' - return ''.join(parts) + return ''.join(parts) \ No newline at end of file From d2194c7ed9be09a50165e4bf52570bba2b5003be Mon Sep 17 00:00:00 2001 From: chilln Date: Sun, 25 May 2025 18:39:39 +0900 Subject: [PATCH 12/12] docs:rename parameter ('add_diagram' -> 'enable_pr_diagram') --- docs/docs/tools/describe.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/tools/describe.md b/docs/docs/tools/describe.md index 1127c875..a967a6c5 100644 --- a/docs/docs/tools/describe.md +++ b/docs/docs/tools/describe.md @@ -57,7 +57,7 @@ Everything below this marker is treated as previously auto-generated content and ![Describe comment](https://codium.ai/images/pr_agent/pr_description_user_description.png){width=512} ### Sequence Diagram Support -When the `add_diagram` option is enabled in your configuration, the `/describe` tool will include a `Mermaid` sequence diagram in the PR description. +When the `enable_pr_diagram` option is enabled in your configuration, the `/describe` tool will include a `Mermaid` sequence diagram in the PR description. This diagram represents interactions between components/functions based on the diff content. @@ -68,7 +68,7 @@ In your configuration: ``` toml [pr_description] -add_diagram = true +enable_pr_diagram = true ``` ## Configuration options