# Packages
# README
Grimoire
Grimoire is a command-line tool that converts the contents of a directory into structured output formats optimized for interpretation by large language models (LLMs). It is lightweight, highly configurable, and user-friendly.
Quick Start
# Convert current directory to Markdown and copy to clipboard (macOS)
grimoire . | pbcopy
# Convert current directory to Markdown and copy to clipboard (Linux with xclip)
grimoire . | xclip -selection clipboard
# Convert current directory and save to file
grimoire -o output.md .
# Convert current directory to XML format
grimoire --format xml -o output.xml .
# Convert current directory to plain text format
grimoire --format txt -o output.txt .
Features
- Multiple Output Formats: Generate output in Markdown, XML, or plain text formats to suit your needs.
- Recursive File Scanning: Automatically traverses directories and subdirectories to identify eligible files based on customizable extensions.
- Content Filtering: Skips ignored directories, temporary files, and patterns defined in the configuration.
- Directory Tree Visualization: Includes an optional directory structure representation at the beginning of the output.
- Git Integration: Prioritizes files by commit frequency when working within a Git repository.
- Flexible Output: Supports output to stdout or a specified file.
Installation
Prerequisites
- Git (required for repositories using Git-based sorting).
Recommended: Download Pre-compiled Binary
The easiest way to install Grimoire is by downloading a pre-compiled binary from the releases page.
- Visit the releases page.
- Download the appropriate archive for your system (e.g.,
grimoire-1.1.3-linux-amd64.tar.gz
orgrimoire-1.1.3-darwin-arm64.tar.gz
). - Extract the archive to retrieve the
grimoire
executable. - Move the
grimoire
executable to a directory in your system'sPATH
(e.g.,/usr/local/bin
or~/.local/bin
). You may need to usesudo
for system-wide locations:tar -xzf grimoire-1.1.3-linux-amd64.tar.gz cd grimoire-1.1.3-linux-amd64 sudo mv grimoire /usr/local/bin/
- Verify the installation:
grimoire --version
Install using go install
For users with Go installed, go install
offers a straightforward installation method:
go install github.com/foresturquhart/grimoire/cmd/grimoire@latest
Build from Source
To build Grimoire from source (useful for development or customization):
- Clone the repository:
git clone https://github.com/foresturquhart/grimoire.git cd grimoire
- Build the binary:
go build -o grimoire ./cmd/grimoire
- Move the binary to your
PATH
:mv grimoire /usr/local/bin/
- Verify the installation:
grimoire --version
Usage
Basic Command
grimoire [options] <target directory>
Options
-o, --output <path>
: Specify an output file. Defaults to stdout if omitted.-f, --force
: Overwrite the output file if it already exists.--format <format>
: Specify the output format. Options aremd
(ormarkdown
),xml
, andtxt
(ortext
,plain
,plaintext
). Defaults tomd
.--no-tree
: Disable the directory tree visualization at the beginning of the output.--no-sort
: Disable sorting files by Git commit frequency.--version
: Display the current version.
Examples
- Convert a directory into Markdown and print the output to stdout:
grimoire ./myproject
- Save the output to a file:
grimoire -o output.md ./myproject
- Overwrite an existing file:
grimoire -o output.md -f ./myproject
- Generate XML output without a directory tree:
grimoire --format xml --no-tree -o output.xml ./myproject
- Generate plain text output without Git-based sorting:
grimoire --format txt --no-sort -o output.txt ./myproject
Configuration
Allowed File Extensions
Grimoire processes files with specific extensions. You can customize these by modifying the DefaultAllowedFileExtensions
constant in the codebase.
Ignored Path Patterns
Files and directories matching patterns in the DefaultIgnoredPathPatterns
constant are excluded from processing. This includes temporary files, build artifacts, and version control directories.
In addition, Grimoire honors ignore files located within the target directory. It supports both the traditional .gitignore
and the new .grimoireignore
. These files allow you to specify additional ignore rules on a per-directory basis. The rules defined in these files follow the same syntax as Git ignore rules, giving you fine-grained control over which files and directories should be omitted during the conversion process.
Output Formats
Grimoire supports three output formats:
- Markdown (md) - Default format that wraps file contents in code blocks with file paths as headings.
- XML (xml) - Structures the content in an XML format with file paths as attributes.
- Plain Text (txt) - Uses separator lines to distinguish between files.
Each format includes metadata, a summary section, an optional directory tree, and the content of all files.
Contributing
Contributions are welcome! To get started:
- Fork the repository.
- Create a new branch for your feature or fix:
git checkout -b feature/my-new-feature
- Commit your changes:
git commit -m "Add my new feature"
- Push the branch to your fork:
git push origin feature/my-new-feature
- Open a pull request.
License
Grimoire is licensed under the MIT License.
Acknowledgements
Grimoire uses the following libraries:
- zerolog for structured logging.
Feedback and Support
For issues, suggestions, or feedback, please open an issue on the GitHub repository.