From df8290a29045997f580155a689d29c60fdf65a0f Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Wed, 2 Jul 2025 18:07:54 +0530 Subject: [PATCH] add support for PR sequence diagram in description markers --- docs/docs/tools/describe.md | 6 +++++- pr_agent/servers/help.py | 1 + pr_agent/settings/pr_description_prompts.toml | 2 +- pr_agent/tools/pr_description.py | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/docs/tools/describe.md b/docs/docs/tools/describe.md index f00903d1..627e6dcf 100644 --- a/docs/docs/tools/describe.md +++ b/docs/docs/tools/describe.md @@ -177,9 +177,12 @@ pr_agent:summary ## PR Walkthrough: pr_agent:walkthrough + +## PR Diagram: +pr_agent:diagram ``` -The marker `pr_agent:type` will be replaced with the PR type, `pr_agent:summary` will be replaced with the PR summary, and `pr_agent:walkthrough` will be replaced with the PR walkthrough. +The marker `pr_agent:type` will be replaced with the PR type, `pr_agent:summary` will be replaced with the PR summary, `pr_agent:walkthrough` will be replaced with the PR walkthrough, and `pr_agent:diagram` will be replaced with the sequence diagram (if enabled). ![Describe markers before](https://codium.ai/images/pr_agent/describe_markers_before.png){width=512} @@ -191,6 +194,7 @@ becomes - `use_description_markers`: if set to true, the tool will use markers template. It replaces every marker of the form `pr_agent:marker_name` with the relevant content. Default is false. - `include_generated_by_header`: if set to true, the tool will add a dedicated header: 'Generated by PR Agent at ...' to any automatic content. Default is true. +- `diagram`: if present as a marker, will be replaced by the PR sequence diagram (if enabled). ## Custom labels diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index e3cdf0de..85e2d286 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -81,6 +81,7 @@ the tool will replace every marker of the form `pr_agent:marker_name` in the PR - `type`: the PR type. - `summary`: the PR summary. - `walkthrough`: the PR walkthrough. + - `diagram`: the PR sequence diagram (if enabled). Note that when markers are enabled, if the original PR description does not contain any markers, the tool will not alter the description at all. diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index d8954052..19b8f185 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -48,7 +48,7 @@ class PRDescription(BaseModel): 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_pr_diagram %} - changes_diagram: str = Field(description="a horizontal diagram that represents the main PR changes, in the format of a valid mermaid LR flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant. To create robust Mermaid diagrams, follow this two-step process: (1) Declare the nodes: nodeID["node description"]. (2) Then define the links: nodeID1 -- "link text" --> nodeID2. Node description must always be surrounded with quotation marks.") + changes_diagram: str = Field(description="a horizontal diagram that represents the main PR changes, in the format of a valid mermaid LR flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant. To create robust Mermaid diagrams, follow this two-step process: (1) Declare the nodes: nodeID[\"node description\"]. (2) Then define the links: nodeID1 -- \"link text\" --> nodeID2. Node description must always be surrounded with quotation marks. This field is used for the pr_agent:diagram marker if markers are enabled.") {%- endif %} {%- 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.") diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index c4595140..41cc4006 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -538,6 +538,10 @@ class PRDescription: get_logger().error(f"Failing to process walkthrough {self.pr_id}: {e}") body = body.replace('pr_agent:walkthrough', "") + ai_diagram = self.data.get('changes_diagram') + if ai_diagram and not re.search(r'', body): + body = body.replace('pr_agent:diagram', ai_diagram) + return title, body, walkthrough_gfm, pr_file_changes def _prepare_pr_answer(self) -> Tuple[str, str, str, List[dict]]: