-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathprompt.py
More file actions
125 lines (103 loc) · 3.97 KB
/
prompt.py
File metadata and controls
125 lines (103 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
PR Review Prompt Template
This module contains the prompt template used by the OpenHands agent
for conducting pull request reviews.
The template uses skill triggers:
- {skill_trigger} will be replaced with '/codereview' or '/codereview-roasted'
- /github-pr-review provides instructions for posting review comments via GitHub API
The template includes:
- {diff} - The complete git diff for the PR (may be truncated for large files)
- {pr_number} - The PR number
- {commit_id} - The HEAD commit SHA
- {review_context} - Previous review comments and thread resolution status
"""
# Template for when there is review context available
_REVIEW_CONTEXT_SECTION = """
## Previous Review History
The following shows previous reviews and review threads on this PR. Pay attention to:
- **Unresolved threads**: These issues may still need to be addressed
- **Resolved threads**: These provide context on what was already discussed
- **Previous review decisions**: See what other reviewers have said
{review_context}
When reviewing, consider:
1. Don't repeat comments that have already been made and are still relevant
2. If an issue is still unresolved in the code, you may reference it
3. If resolved, don't bring it up unless the fix introduced new problems
4. Focus on NEW issues in the current diff that haven't been discussed yet
"""
PROMPT = """{skill_trigger}
/github-pr-review
When posting a review, keep the review body brief unless your active review
instructions require a longer structured format.
## Review decision policy (eval / benchmark risk)
You MAY approve clearly low-risk changes (docs, typo fixes, formatting, or
pure refactors with no behavior changes).
Do NOT submit an APPROVE review when the PR changes agent behavior or anything
that affects benchmark/evaluation performance.
Examples include: prompt templates, tool calling/execution, planning/loop logic,
memory/condenser behavior, terminal/stdin/stdout handling, or evaluation harness code.
If a PR is in this category (or you are uncertain), leave a COMMENTED review and
explicitly flag it for a human maintainer to decide after running lightweight evals.
Review the PR changes below and identify issues that need to be addressed.
## Pull Request Information
- **Title**: {title}
- **Description**: {body}
- **Repository**: {repo_name}
- **Base Branch**: {base_branch}
- **Head Branch**: {head_branch}
- **PR Number**: {pr_number}
- **Commit ID**: {commit_id}
{review_context_section}
## Git Diff
```diff
{diff}
```
Analyze the changes and post your review using the GitHub API.
"""
def format_prompt(
skill_trigger: str,
title: str,
body: str,
repo_name: str,
base_branch: str,
head_branch: str,
pr_number: str,
commit_id: str,
diff: str,
review_context: str = "",
) -> str:
"""Format the PR review prompt with all parameters.
Args:
skill_trigger: The skill trigger (e.g., '/codereview' or '/codereview-roasted')
title: PR title
body: PR description
repo_name: Repository name (owner/repo)
base_branch: Base branch name
head_branch: Head branch name
pr_number: PR number
commit_id: HEAD commit SHA
diff: Git diff content
review_context: Formatted previous review context. If empty or whitespace-only,
the review context section is omitted from the prompt.
Returns:
Formatted prompt string
"""
# Only include the review context section if there is actual context
if review_context and review_context.strip():
review_context_section = _REVIEW_CONTEXT_SECTION.format(
review_context=review_context
)
else:
review_context_section = ""
return PROMPT.format(
skill_trigger=skill_trigger,
title=title,
body=body,
repo_name=repo_name,
base_branch=base_branch,
head_branch=head_branch,
pr_number=pr_number,
commit_id=commit_id,
review_context_section=review_context_section,
diff=diff,
)