No project description provided
Project description
PatchWork
An open-source framework for automating development chores using large language models. PatchWork allows you to automate workflows like PR reviews, bug fixing, security patching, and more using a self-hosted CLI agent and your preferred LLMs.
Key Components
- Steps: A set of reusable atomic actions that define various operations.
- Patchflows: LLM-assisted automations such as PR reviews, code fixing, debugging.
Patchflows can be run locally in your CLI and IDE, or as part of your CI/CD pipeline.
Installation
Using Pip
PatchWork is available on PyPI and can be installed using pip:
pip install patchwork-cli --upgrade
Using Poetry
PatchWork is built using Poetry, a dependency management and packaging tool for Python. To install PatchWork using Poetry, follow these steps:
-
Make sure you have Poetry installed. If you don't have it installed, you can install it by running:
curl -sSL https://install.python-poetry.org | python3 -
-
Clone the PatchWork repository:
git clone https://github.com/patched-codes/patchwork.git
-
Navigate to the project directory:
cd patchwork
-
Activate a shell using virtual environment:
poetry shell
-
Install the dependencies using Poetry:
poetry install
PatchWork CLI
The CLI runs Patchflows, as follows:
patchwork <Patchflow> <?Arguments>
Where
- Arguments: Allow for overriding default/optional attributes of the Patchflow in the format of
key=value
. Ifkey
does not have any value, it is considered a booleanTrue
flag.
Example
For an AutoFix patchflow which patches vulnerabilities based on a scan using Semgrep:
patchwork AutoFix openai_api_key=<YOUR_OPENAI_API_KEY> github_api_key=<YOUR_GITHUB_TOKEN>
The above command will default to patching code in the current directory, by running Semgrep to identify the vulnerabilities.
You can take a look at the default.yml
file for the list of configurations you can set to manage the AutoFix patchflow. You will need to pass your own openai_api_key
to call the LLM. Otherwise, to get started, you can get a patched_api_key
for free by
by signing in at https://app.patched.codes/signin and generating an API key from the integrations tab. You can then call the patchflow with the key as follows:
patchwork AutoFix patched_api_key=<YOUR_PATCHED_API_KEY> github_api_key=<YOUR_GITHUB_TOKEN>
The patchwork-configs repository contains the default configuration and prompts for all the patchflows. You can clone that repo and pass it as a flag to the CLI:
patchwork AutoFix --config /path/to/patchwork-configs/patchflows
Patchflows
Patchwork comes with a set of predefined patchflows, and more will be added over time. Below is a sample list of patchflows:
- AutoFix: Generate and apply fixes to code vulnerabilities in a repository.
- DependencyUpgrade: Update your dependencies from vulnerable to fixed versions.
- PRReview: On PR creation, extract code diff, summarize changes, and comment on PR.
- GenerateREADME: Create a README.md file for a given folder, to add documentation to your repository.
- ResolveIssue: Identify the files in your repository that need to be updated to resolve an issue (or bug) and create a PR to fix it.
Prompt Templates
Prompt templates are used by patchflows and passed as queries to LLMs. Templates contain prompts with placeholder variables enclosed by {{}} which are replaced by the data from the steps or inputs on every run.
Below is a sample prompt template:
{
"id": "diffreview_summary",
"prompts": [
{
"role": "user",
"content": "Summarize the following code change descriptions in 1 paragraph. {{diffreviews}}"
}
]
}
Each patchflow comes with an optimized default prompt template. But you can specify your own using the prompt_template_file=/path/to/prompt/template/file
option.
Contributing
To create a new patchflow, follow these instructions.
To create a new step, follow these instructions.
We also provide chat assitants to help you create new steps and patchflows easily.
- Patchwork Assistant GPT (requires ChatGPT pro subscription)
- Patchwork Assistant on HuggingChat (free)
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
Hashes for patchwork_cli-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81352bbf113c6fe7a61bd57a8bea1cf0f599f51806dc23a17688a33ca9b0cfb2 |
|
MD5 | a040d57c432ffc08fcdeb59067862a38 |
|
BLAKE2b-256 | 443f5664cf2668e1117e59f46ccbcc0c4c8ba055a586f5595218af73a6c9a245 |