|
3 | 3 |
|
4 | 4 | # llmstxt |
5 | 5 |
|
6 | | -A Python tool to compress code files into a single, LLM-friendly text file. |
| 6 | +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. |
7 | 7 |
|
8 | 8 | ## Features |
9 | 9 |
|
10 | | -- Preserves important comments and docstrings |
11 | | -- Removes unnecessary content |
12 | | -- Structured, LLM-friendly output |
13 | | -- GitHub Actions integration for automatic updates |
| 10 | +### Smart Code Compression |
| 11 | + |
| 12 | +- Preserves docstrings and important comments |
| 13 | +- Removes redundant whitespace and formatting |
| 14 | +- Maintains code structure and readability |
| 15 | +- Handles multiple programming languages |
| 16 | + |
| 17 | +### Language Support |
| 18 | + |
| 19 | +- Python (with AST-based compression) |
| 20 | +- JavaScript |
| 21 | +- Java |
| 22 | +- C/C++ |
| 23 | +- Shell scripts |
| 24 | +- HTML/CSS |
| 25 | +- Configuration files (JSON, YAML, TOML, INI) |
| 26 | +- Markdown |
| 27 | + |
| 28 | +### LLM-Friendly Output |
| 29 | + |
| 30 | +- XML-style semantic markers |
| 31 | +- File metadata and type information |
| 32 | +- Organized imports section |
| 33 | +- Clear file boundaries |
| 34 | +- Consistent formatting |
| 35 | + |
| 36 | +### Automation |
| 37 | + |
| 38 | +- GitHub Actions integration |
| 39 | +- Automatic updates on code changes |
| 40 | +- CI/CD friendly |
14 | 41 |
|
15 | 42 | ## Installation |
16 | 43 |
|
| 44 | +This project uses [uv](https://github.com/astral-sh/uv) for dependency management, but can also be installed directly with pip. |
| 45 | + |
17 | 46 | ```bash |
| 47 | +# Using pip |
18 | 48 | pip install git+https://github.com/ngmisl/llmstxt.git |
| 49 | + |
| 50 | +# Using uv (recommended for development) |
| 51 | +curl -LsSf https://astral.sh/uv/install.sh | sh |
| 52 | +uv pip install . |
| 53 | + |
| 54 | +# For development |
| 55 | +uv pip install -e ".[dev]" |
19 | 56 | ``` |
20 | 57 |
|
21 | 58 | ## Usage |
22 | 59 |
|
23 | | -### Command Line |
| 60 | +### Local Usage |
24 | 61 |
|
25 | 62 | ```bash |
26 | | -# Generate llms.txt in current directory |
| 63 | +# Generate llms.txt from current directory |
27 | 64 | python -m llmstxt |
28 | 65 |
|
29 | 66 | # Or import and use in your code |
30 | 67 | from llmstxt import generate_llms_txt |
31 | 68 | generate_llms_txt() |
32 | 69 | ``` |
33 | 70 |
|
| 71 | +The script will: |
| 72 | + |
| 73 | +1. Scan the current directory recursively |
| 74 | +2. Process files according to .gitignore rules |
| 75 | +3. Generate `llms.txt` with compressed content |
| 76 | + |
34 | 77 | ### GitHub Actions Integration |
35 | 78 |
|
36 | | -To automatically update `llms.txt` in your repository: |
| 79 | +There are two ways to use this tool with GitHub Actions: |
37 | 80 |
|
38 | | -1. Create `.github/workflows/update-llms.yml` with: |
| 81 | +1. **For Your Own Repository** |
| 82 | + |
| 83 | +Create `.github/workflows/update-llms.yml` with: |
39 | 84 |
|
40 | 85 | ```yaml |
41 | 86 | name: Update llms.txt |
@@ -93,28 +138,112 @@ jobs: |
93 | 138 | ``` |
94 | 139 |
|
95 | 140 | The workflow will: |
| 141 | +
|
96 | 142 | - Run on push to main/master |
97 | 143 | - Run on pull requests |
98 | 144 | - Can be triggered manually |
99 | 145 | - Generate and commit `llms.txt` automatically |
100 | 146 |
|
| 147 | +2. **For Remote Repositories** |
| 148 | + You can trigger the action for any repository using the GitHub API: |
| 149 | + |
| 150 | +```bash |
| 151 | +curl -X POST \ |
| 152 | + -H "Authorization: token $GITHUB_TOKEN" \ |
| 153 | + -H "Accept: application/vnd.github.v3+json" \ |
| 154 | + https://api.github.com/repos/ngmisl/llmstxt/dispatches \ |
| 155 | + -d '{"event_type": "update-llms", "client_payload": {"repository": "https://github.com/user/repo.git"}}' |
| 156 | +``` |
| 157 | + |
| 158 | +## Output Format |
| 159 | + |
| 160 | +The generated `llms.txt` file follows this structure: |
| 161 | + |
| 162 | +```python |
| 163 | +# Project: llmstxt |
| 164 | +
|
| 165 | +## Project Structure |
| 166 | +This file contains the compressed and processed contents of the project. |
| 167 | +
|
| 168 | +### File Types |
| 169 | +- .py |
| 170 | +- .js |
| 171 | +- .java |
| 172 | +... |
| 173 | +
|
| 174 | +<file>src/main.py</file> |
| 175 | +<metadata> |
| 176 | +path: src/main.py |
| 177 | +type: py |
| 178 | +size: 1234 bytes |
| 179 | +</metadata> |
| 180 | +
|
| 181 | +<imports> |
| 182 | +import ast |
| 183 | +from typing import Optional |
| 184 | +</imports> |
| 185 | +
|
| 186 | +<code lang='python'> |
| 187 | +def example(): |
| 188 | + """Docstring preserved.""" |
| 189 | + return True |
| 190 | +</code> |
| 191 | +
|
| 192 | +<file>src/utils.js</file> |
| 193 | +<metadata> |
| 194 | +path: src/utils.js |
| 195 | +type: js |
| 196 | +size: 567 bytes |
| 197 | +</metadata> |
| 198 | +
|
| 199 | +<code lang='javascript'> |
| 200 | +function helper() { |
| 201 | + return true; |
| 202 | +} |
| 203 | +</code> |
| 204 | +``` |
| 205 | + |
| 206 | +## Configuration |
| 207 | + |
| 208 | +The tool can be configured through function parameters: |
| 209 | + |
| 210 | +```python |
| 211 | +generate_llms_txt( |
| 212 | + output_file="llms.txt", # Output filename |
| 213 | + max_file_size=100 * 1024, # Max file size (100KB) |
| 214 | + allowed_extensions=( # Supported file types |
| 215 | + ".py", ".js", ".java", |
| 216 | + ".c", ".cpp", ".h", ".hpp", |
| 217 | + ".sh", ".txt", ".md", |
| 218 | + ".json", ".xml", ".yaml", |
| 219 | + ".yml", ".toml", ".ini" |
| 220 | + ) |
| 221 | +) |
| 222 | +``` |
| 223 | + |
101 | 224 | ## Development |
102 | 225 |
|
| 226 | +Requirements: |
| 227 | + |
| 228 | +- Python 3.8+ |
| 229 | +- [uv](https://github.com/astral-sh/uv) for dependency management (recommended) |
| 230 | + |
103 | 231 | ```bash |
104 | 232 | # Clone the repository |
105 | 233 | git clone https://github.com/ngmisl/llmstxt.git |
106 | 234 | cd llmstxt |
107 | 235 |
|
108 | 236 | # Install development dependencies |
109 | | -pip install -e ".[dev]" |
| 237 | +uv pip install -e ".[dev]" |
110 | 238 |
|
111 | 239 | # Run type checking |
112 | 240 | mypy llmstxt |
113 | 241 |
|
114 | | -# Run linting |
| 242 | +# Run linting and formatting |
115 | 243 | ruff check llmstxt |
| 244 | +ruff format llmstxt |
116 | 245 | ``` |
117 | 246 |
|
118 | 247 | ## License |
119 | 248 |
|
120 | | -MIT |
| 249 | +MIT License - See LICENSE file for details |
0 commit comments