Command line tool for generating code review prompts using the Metaphor format
Project description
commit-critic
commit-critic is an extensible Python-based command-line application that helps developers get AI-powered code reviews. It takes your source code files and review guidelines as input, then generates a detailed prompt that can be used with you favourite AI to perform detailed code reviews.
The code reviewing guidelines are described by a series of files written in "Metaphor", a structured natural language format designed to generate structured prompts for LLMs.
While the application is a demonstration of using Metaphor and the m6rclib parser/prompt compiler, commit-critic was itself coded by an AI, based on a metaphor description.
For more detail you can read how this was designed and built at https://m6r.ai/blog/000005-commit-critic.
Features
- Process multiple source files for review
- Support for custom review guidelines using Metaphor (.m6r) files
- Flexible search paths for finding guideline files
- Output to file or stdout
- Comprehensive error handling and reporting
Installation
The application requires Python 3 and the m6rclib package. Ensure both are installed before using the tool.
Install m6rclib:
pip install m6rclib
To install the commit-critic
command:
pip install .
Usage
Basic syntax:
commit-critic [options] file1 [file2 ...]
Command Line Options
-h, --help
: Show help message and exit-v, --version
: Show program's version number and exit-o OUTPUT, --output OUTPUT
: Specify output file (defaults to stdout)-g PATH, --guideline-path PATH
: Add a directory to search for .m6r review guideline files (defaults to current directory)
Environment Variable
The environment variable COMMIT_CRITIC_GUIDELINE_DIR
can also be used to specify the directory, or directories, to search for .m6r review guidelines files.
Examples
Review a single file using guidelines in the current directory (or the `COMMIT_CRITIC_GUIDELINE_DIR):
commit-critic src/myfile.py
Review multiple files and save the prompt to a file:
commit-critic -o review-prompt.txt src/file1.py src/file2.py
Use guidelines from multiple directories:
commit-critic -g ./guidelines -g ./custom-guidelines src/myfile.py
Review Guidelines
The tool searches for Metaphor guideline files (*.m6r) in:
- The current working directory (default)
- Any directories specified with the
-g
option - Any directories specified with the
COMMIT_CRITIC_GUIDELINE_DIR
environment variable
At least one valid guideline file must be found for the tool to work.
The tool will include all guidelines it can find. If you want to add new ones for a particular language then create a new file for that language and add content in the same format as the examples provides.
There are example guidelines in the git repo for the tool. Please see the review-guides
directory.
Exit Codes
The application uses the following exit codes:
- 0: Success
- 1: Command line usage error
- 2: Data format error (e.g., invalid Metaphor syntax)
- 3: Cannot open input file
- 4: Cannot create output file
Error Handling
The tool provides detailed error messages when issues occur:
- Missing input files
- Invalid command line arguments
- Missing guideline files
- Syntax errors in Metaphor files
- File access problems
Error messages are written to stderr and include:
- Clear description of the error
- Filename (when relevant)
- Line number and column (for syntax errors)
Output Format
The tool generates a structured prompt using the Metaphor language format, which includes:
- A role definition for the AI reviewer
- Review guidelines from .m6r files
- The files to be reviewed
- Specific instructions for the review process
The output can be directed to:
- stdout (default)
- A file specified with the
-o
option
Limitations
- The tool requires at least one .m6r guideline file to be present
- Input files must be text-based source code files
- Large files may need to be reviewed in segments
Troubleshooting
Common issues and solutions:
-
"No .m6r guideline files found":
- Check that guideline files exist in the search paths
- Verify file extensions are correctly set to .m6r
- Use -g to specify additional search paths
-
"Cannot open input file":
- Verify the file exists
- Check file permissions
- Ensure the path is correct
-
"Cannot create output file":
- Check write permissions in the target directory
- Verify the path is valid
- Ensure sufficient disk space
Support
For more information or to report issues, please refer to the project's documentation or issue tracker.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file commit_critic-0.1.tar.gz
.
File metadata
- Download URL: commit_critic-0.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc6a899d725f8ac21d906b2e5c9069bb2ec717f8420abe63832a681b1b67378 |
|
MD5 | a7d2b7995392ce0584b4e4a9ad8a8a3d |
|
BLAKE2b-256 | a97422b4a553fdedcfe9c2ae1e4a2fca07201d73a048ba71305d9e822e4dd936 |
File details
Details for the file commit_critic-0.1-py3-none-any.whl
.
File metadata
- Download URL: commit_critic-0.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d44546a7ab9b792e4666540d1986d9a5178520b4bb7d5b9e37cf140894d5ebe1 |
|
MD5 | 06eef8d6e5c743d8324a5423438059fe |
|
BLAKE2b-256 | 9393b6b956449662da1d0aca1bd93be8983b498ceab571070f3bf882b4630936 |