INTRODUCTION ================================== This script automates pull request (PR) review using a large language model. It is a command line tool. It is intended to be used locally to validate a PR before pushing and having colleagues review your work. The goal is to catch mistakes early and avoid back-and-forth on PR reviews. Depending on the context provided, it can catch: - Spelling mistakes - Ambigious variables - SQL mistakes like missing indexes - Inconsistent code styling - Unclear comments INSTALLATION ================================== Download bun ---------------------------------- - This project requires bun to run, which is a typescript runtime - Install bun here: https://bun.sh/docs/installation - Ensure it's installed by running `bun --version` in your terminal, and follow further directions as needed Clone this repo ---------------------------------- - Open your terminal - Navigate to a suitable directory - Run the command `git clone https://gitfront.io/r/robertpkoenig/yQGcR37JshKE/pr-check.git` - Now the contents of this repository will be copied into a folder in your current directory called `pr-check` Install dependencies ---------------------------------- - Within terminal, navigate into the `pr-check` directory - Run the command `bun install` Get an Open AI API Key ---------------------------------- - Create a developer account and get a key here: https://openai.com/ - You get $5 free credit, which will give you plenty to play with Specify the environmental variables needed for this script ---------------------------------- - Create a file called `.env` in the root directory of the project - Follow the directions in the `sample-env.md` Create context and instruction files ---------------------------------- - Copy the `prompt/sample/samp/e.baseContext.md` file into a new file `prompt/context/baseContext.md` - Copy the `prompt/sample/sample.finalInstruction.md` file into a new file `prompt/instruction/finalInstruction.md` - Edit these files as necessary, see the 'Context and Instruction' section below for more detail Create a terminal shortcut (optional) ---------------------------------- - Depending on your shell environment, add an alias for running this script - For the `zsh` shell, you'd add the following line to your `zshrc` config file: - `alias pr-check="bun /path/to/pr-check/src/index.ts` - You'll need to run `source ~./zshrc` in terminal for the shortcut to be available BASIC USAGE ================================== 1. Create a new git branch, write code, and commit your changes to your branch 2. Run this script from your repo directory - use your shortcut created in step 5 above - run the script directly with the command `bun /path/to/pr-check/src/index.ts` 3. The AI PR review will begin printing to your terminal CONTEXT AND INSTRUCTION ================================== When sending a PR for review by the AI, a 'prompt' is generated. This prompt is essentially a text message sent to the AI, including the context of your PR (such as files changed and lines altered) and a final instruction. You can modify both the context and the final instruction as needed. Context Customization ---------------------------------- The context can include rules the AI should follow, things to look out for, or domain knowledge. You could even include, for instance, a database schema that would enable the AI to validate SQL that you have written within your PR. Creating Context Files ---------------------------------- - To define the context, create either a markdown (.md) or text (.txt) file in the prompt/context directory. - Write the context as if explaining to another person, using clear headings for better structure. - Multiple context files can be added, and you can choose which ones to include during the script run through a checkbox interface. Default Context Files ---------------------------------- - In the .env file, specify default context files as a space-separated list of filenames. - These default files will be pre-selected in the checkbox UI. - Refer to sample-env.md for more details on defaults. You can add as many context files as you want. When you run the script, you will be able to select which context files to include in the current review. You will select the context files you wish to consider by checking them in a checkbox. Mandatory baseContext.md File ---------------------------------- - A prompt/context/baseContext.md file is required by the script. - It can be blank but must exist. This file contains basic directives for the AI. - You can modify this file as needed, maintaining some basic context. - For a start, copy the sample from prompt/sample/sample.baseContext.md into the required directory. Context File Ordering ---------------------------------- - The baseContext.md content is added first in the prompt text. - Other context files follow in alphabetical order. Prompt Instructions ---------------------------------- In addition to custom context files, each prompt includes a final instruction to keep the AI focused, especially in cases of long context descriptions. - The final instruction is defined in prompt/instruction/finalInstruction.md. - Copy the sample from prompt/sample/sample.finalInstruction.md to this location. - This instruction can be customized as per your requirement. Code Map ================================== If you want to change the code, this code map will help you get oriented. ``` ├── prompt │ ├── context // Files referenced by the AI when reviewing your PR │ ├── instruction // Instruction to the AI defining the goal, output format, etc. │ └── sample // Sample context and instruction files for you to copy and edit ├── src │ ├── commandline // Helper function for interacting with command line from Bun │ ├── filesystem // Helper functions for reading context/instruction files │ ├── git // Helper functions for interacting with git (ie. getting commits) │ ├── interfaces // Data models used within the application │ ├── openai // Simple wrapper for OpenAI API │ ├── parsers // Helper functions for parsing / generating text │ ├── userinput // Helper functions for the terminal user interface │ └── validation // Function to prevent users running the script in an invalid state └── index.ts // The entry point for the application ```