Adding Custom Commands
Relevant source files
The following files were used as context for generating this wiki page:
Custom commands allow users to trigger specific PR-Agent functionalities through GitHub Pull Request comments. These commands interface with the central configuration and automated scripts to perform code reviews, descriptions, and autonomous repairs.
Sources: README.md:1-25, scripts/autofix.py:1-25
Interactive Command Interface
Users trigger PR-Agent actions by posting specific comment strings on a Pull Request. The system recognizes these triggers to initiate defined workflows.
| Command | Action Performed |
|---|---|
/review | Performs a full code review including security and test analysis. |
/describe | Generates a PR description and changelog. |
/improve | Provides inline code suggestions ready for commitment. |
/ask <question> | Responds to specific queries regarding changes in the PR. |
/autofix | Triggers the autonomous repair script to fix review findings or CI failures. |
Sources: README.md:21-25, scripts/autofix.py:175-185
Autonomous Command Execution
The /autofix command executes the autofix.py script, which operates in two distinct modes based on the state of the Pull Request.
Workflow Logic
The script determines the execution path by checking for existing review findings from the PR-Agent.
This diagram illustrates the decision logic within main() to choose between repairing review comments or fixing build failures.
Sources: scripts/autofix.py:382-410
Review Fix Mode
When the bot detects review comments (excluding /autofix itself), it gathers the flagged file contents and the comment body. It then sends this context to the Gemini model to generate minimal, surgical fixes.
Sources: scripts/autofix.py:304-343
CI Fix Mode
If no findings exist, the system attempts to run a local test command. If the command fails, the script extracts error snippets and affected file paths to request a repair from the AI.
Sources: scripts/autofix.py:355-380
Configuration and Environment
Custom commands rely on environment variables and global configuration files to function across the repository fleet.
| Variable | Requirement | Description |
|---|---|---|
GEMINI_API_KEY | Required | Google AI Studio key for model access. |
GH_TOKEN | Required | GitHub token for API interactions and Git operations. |
REPO | Required | Target repository in owner/repo format. |
PR_NUMBER | Required | The identification number of the Pull Request. |
GEMINI_MODEL | Optional | Specifies the AI model (default: gemini-3.8-flash). |
Sources: scripts/autofix.py:22-35, README.md:5-10
Validation and Commitment
Every change initiated by a custom command undergoes a verification process before being pushed to the branch.
- Detection: The script identifies the project type (e.g., Rust, Node.js, Python, Go) and selects the appropriate test runner.
- Execution: It runs the detected test command (e.g.,
cargo check,npm test,pytest). - Verification: If the command returns a non-zero exit code after a fix, the script rolls back changes using
git checkout -- .. - Persistence: On success, the script configures the
github-actions[bot]user and pushes the commit to theHEAD_REF.
Sources: scripts/autofix.py:76-105, scripts/autofix.py:266-300
Global Configuration Management
Custom commands are governed by the .pr_agent.toml file. This central file provides global settings inherited by all repositories under the organization, though individual repositories may provide overrides.
Sources: README.md:5-15