codepromptforge is a Python tool that merges the contents of multiple code (or text) files into one consolidated prompt. This prompt can then be used by Large Language Models (LLMs) to assist in tasks like bug fixing, code improvements, and other automated coding workflows.
codepromptforge comes in two parts:
- A command-line interface (CLI) that quickly and easily merges files based on specified extensions.
- A Python class (
PromptForge
) providing programmatic control to locate files, optionally include a directory tree, and write them into a single output file.
- Search by Extensions: Recursively scans a base directory for files matching given extensions (e.g.,
.py
,.txt
,.md
). - Single Output: Consolidates matched file contents into a single text file, streamlining code reviews or preparing context for an LLM.
- Customizable Output Paths: Specify where the merged file should be placed.
- Optional Directory Tree: Include a text-based directory tree at the top of your output for extra context.
- Simple, Lightweight: Minimal dependencies and straightforward usage.
- Clone or Download this repository.
- Navigate to the root directory (containing the
setup.py
file) in your terminal. - Install the package:
pip install .
- After installation, you can run codepromptforge directly from the command line if you configure your
setup.py
to expose a script (for example,codepromptforge
). Alternatively, you can import and use thePromptForge
class in Python scripts.
Assuming you have configured your setup.py
to create a console script named codepromptforge
:
codepromptforge <extensions> [OPTIONS]
For example:
codepromptforge py txt --base-dir="./codebase" --output-file="./prompts/merged_prompt.txt"
This looks for .py
and .txt
files in ./codebase
, then writes them into ./prompts/merged_prompt.txt
.
You can also invoke codepromptforge’s functionality programmatically:
from codepromptforge.main import PromptForge
def combine_files():
forge = PromptForge(
base_dir="./codebase",
output_file="./prompts/merged_prompt.txt",
dry_run=False,
force=False,
include_tree=True
)
forge.run(["py", "txt"])
print("Files have been merged successfully!")
if __name__ == "__main__":
combine_files()
When you call forge.run(["py", "txt"])
, it searches for .py
and .txt
files under ./codebase
and merges them into ./prompts/merged_prompt.txt
. If include_tree=True
, it also prepends a directory tree structure to the beginning of the output file.
Argument | Required? | Default | Description |
---|---|---|---|
extensions |
Yes | None | File extensions to search for, without dots. Multiple can be specified (e.g., py txt md ). |
--base-dir |
No | ./codebase |
Base directory to search in. |
--output-file |
No | ./prompts/merged_prompt.txt |
File where the merged content is written. |
--dry-run |
No | False |
Lists the files that would be merged without writing to the output file. |
--force |
No | False |
Overwrites an existing output file without prompting if set. |
--include-tree |
No | False |
Includes a directory tree listing at the top of your output file when set. |
codepromptforge py
- Searches
./codebase
(by default) for.py
files, merging them into./prompts/merged_prompt.txt
.
codepromptforge md --base-dir="./docs" --output-file="./prompts/combined_docs.txt"
- Locates all
.md
files in./docs
, writing them into./prompts/combined_docs.txt
.
codepromptforge py txt --include-tree
- Merges
.py
and.txt
files from./codebase
into./prompts/merged_prompt.txt
and prepends a directory tree view at the top of the output.
codepromptforge py --dry-run
- Lists all
.py
files in./codebase
without creating or overwriting the output file.
codepromptforge/
├── __init__.py # Package initializer
├── cli.py # Command-line interface
├── main.py # Core logic, including PromptForge class
tests/
├── test_codepromptforge.py # Unit tests (requires pytest or similar)
__init__.py
: Makescodepromptforge
a Python package.cli.py
: Defines the CLI entry point using Python’sargparse
.main.py
: Contains thePromptForge
class to find and merge files.tests/
: Holds tests verifying functionality of the package.
Contributions of any kind are welcome! Submit issues or pull requests to enhance features or fix bugs. Before opening a PR:
- Adhere to Python’s PEP 8 style guidelines.
- Write or update tests to confirm correct behavior.
- Update the documentation (including this README) if your changes affect usage.
This project is distributed under the MIT License. You’re free to use, modify, and distribute codepromptforge under these terms. If you find it helpful, consider giving a shout-out or contributing back to the repository.
Enjoy codepromptforge and happy coding!