|
1 | 1 | # llmstxt |
| 2 | + |
| 3 | +A Python tool for compressing and organizing code files into a single, LLM-friendly text file. This tool is designed to help prepare codebases for analysis by Large Language Models by removing unnecessary content while preserving important semantic information. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Smart Code Compression** |
| 8 | + - Preserves docstrings and important comments |
| 9 | + - Removes redundant whitespace and formatting |
| 10 | + - Maintains code structure and readability |
| 11 | + - Handles multiple programming languages |
| 12 | + |
| 13 | +- **Language Support** |
| 14 | + - Python (with AST-based compression) |
| 15 | + - JavaScript |
| 16 | + - Java |
| 17 | + - C/C++ |
| 18 | + - Shell scripts |
| 19 | + - HTML/CSS |
| 20 | + - Configuration files (JSON, YAML, TOML, INI) |
| 21 | + - Markdown |
| 22 | + |
| 23 | +- **LLM-Friendly Output** |
| 24 | + - XML-style semantic markers |
| 25 | + - File metadata and type information |
| 26 | + - Organized imports section |
| 27 | + - Clear file boundaries |
| 28 | + - Consistent formatting |
| 29 | + |
| 30 | +## Installation |
| 31 | + |
| 32 | +```bash |
| 33 | +# Using pip |
| 34 | +pip install -r requirements.txt |
| 35 | + |
| 36 | +# Using uv (recommended) |
| 37 | +uv pip install -r requirements.txt |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +```python |
| 43 | +# Basic usage |
| 44 | +python llms.py |
| 45 | + |
| 46 | +# The script will: |
| 47 | +# 1. Scan the current directory |
| 48 | +# 2. Process files according to .gitignore rules |
| 49 | +# 3. Generate llms.txt with compressed content |
| 50 | +``` |
| 51 | + |
| 52 | +## Output Format |
| 53 | + |
| 54 | +The generated `llms.txt` file follows this structure: |
| 55 | + |
| 56 | +``` |
| 57 | +# Project metadata |
| 58 | +<file>path/to/file.py</file> |
| 59 | +<metadata> |
| 60 | +path: path/to/file.py |
| 61 | +type: py |
| 62 | +size: 1234 bytes |
| 63 | +</metadata> |
| 64 | +
|
| 65 | +<imports> |
| 66 | +import ast |
| 67 | +from typing import Optional |
| 68 | +</imports> |
| 69 | +
|
| 70 | +<code lang='python'> |
| 71 | +def example(): |
| 72 | + """Docstring preserved.""" |
| 73 | + return True |
| 74 | +</code> |
| 75 | +``` |
| 76 | + |
| 77 | +## Configuration |
| 78 | + |
| 79 | +- Maximum file size: 100KB (configurable) |
| 80 | +- Supported file extensions: .py, .js, .java, .c, .cpp, .h, .hpp, .sh, .txt, .md, .json, .xml, .yaml, .yml, .toml, .ini |
| 81 | +- Respects .gitignore rules |
| 82 | + |
| 83 | +## Development |
| 84 | + |
| 85 | +Requirements: |
| 86 | +- Python 3.8+ |
| 87 | +- mypy for type checking |
| 88 | +- ruff for linting |
| 89 | + |
| 90 | +```bash |
| 91 | +# Install dev dependencies |
| 92 | +uv pip install -e ".[dev]" |
| 93 | + |
| 94 | +# Run type checking |
| 95 | +mypy llms.py |
| 96 | + |
| 97 | +# Run linting |
| 98 | +ruff check . |
| 99 | +``` |
| 100 | + |
| 101 | +## License |
| 102 | + |
| 103 | +MIT License - See LICENSE file for details |
0 commit comments