Full Code Review Feature (/review)
Relevant source files
The following files were used as context for generating this wiki page:
The Full Code Review feature, triggered by the /review command, performs a comprehensive analysis of Pull Request (PR) changes, including security assessments and test analysis. It operates as part of the PR-Agent suite to provide automated feedback and inline suggestions to developers.
This feature integrates with an autonomous repair system that processes the findings generated during the review. When the review bot identifies issues, the autofix.py script consumes these findings to generate and apply code repairs using the Gemini AI model.
Sources: README.md:27-28, scripts/autofix.py:5-13
Review Execution and Command Triggering
Users trigger the full code review by commenting /review on any Pull Request. The system then evaluates the code changes against security standards and testing requirements. Global configurations for this behavior are managed in the pr-agent-settings repository, though individual repositories can override these settings via a local .pr_agent.toml file.
Sources: README.md:8-13, README.md:28
Interaction Workflow
The following diagram illustrates the interaction between a user, the GitHub interface, and the PR-Agent backend when a review is requested.
Sources: README.md:27-32, scripts/autofix.py:202-212
Autonomous Repair Logic (review-fix mode)
The /review command generates findings that the autonomous fixer uses to repair code. The autofix.py script enters review-fix mode when it detects inline review comments or summary findings on the PR.
Finding Collection
The system gathers review data through the GitHub REST API. It identifies:
- Inline Comments: Specific code-level feedback including the file path, line number, and comment body.
- Review Summaries: High-level summaries often posted by
github-actions[bot].
Sources: scripts/autofix.py:171-199
Repair Process Flow
Once findings are collected, the system uses the Gemini API to generate corrections.
Sources: scripts/autofix.py:239-277
Technical Components and Configuration
Key Functions for Review Processing
| Function | Description |
|---|---|
get_review_findings | Queries GitHub API for /pulls/{number}/comments and /issues/{number}/comments. |
review_fix_mode | Orchestrates the transition from review findings to AI-generated repairs. |
call_gemini | Sends the prompt containing review findings and file context to the AI model. |
apply_repair_files | Validates file paths and writes the AI-generated content to the local filesystem. |
| Sources: scripts/autofix.py:108-129, scripts/autofix.py:171-199, scripts/autofix.py:230-256, scripts/autofix.py:260-288 |
AI Prompting Logic
The system uses a specific REVIEW_SYSTEM_PROMPT to instruct the AI. It requires the AI to:
- Fix genuine bugs, errors, and security issues.
- Skip style nitpicks and open questions.
- Provide minimal and surgical changes in a specific JSON format.
Sources: scripts/autofix.py:202-218
# From scripts/autofix.py:214-218
{
"summary": "Short explanation of what was fixed",
"files": [
{"path": "relative/path/to/file", "content": "Full, complete updated file contents"}
]
}
Sources: scripts/autofix.py:214-218
Validation and Safety
After repairs are generated based on review findings, the system executes a validation step. It detects the project's environment (e.g., Cargo.toml, package.json, pyproject.toml) and runs the appropriate test command. If the validation fails, the system executes git checkout -- . to revert changes, ensuring that the /review process does not introduce breaking changes.
Sources: scripts/autofix.py:53-83, scripts/autofix.py:291-309
The Full Code Review feature provides a closed-loop system where automated analysis leads to verified, autonomous improvements to the codebase.
Sources: scripts/autofix.py:5-13