|
3 | 3 |
|
4 | 4 | # llmstxt |
5 | 5 |
|
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. |
| 6 | +A Python tool to compress code files into a single, LLM-friendly text file. |
7 | 7 |
|
8 | 8 | ## Features |
9 | 9 |
|
10 | | -- **Smart Code Compression** |
11 | | - - Preserves docstrings and important comments |
12 | | - - Removes redundant whitespace and formatting |
13 | | - - Maintains code structure and readability |
14 | | - - Handles multiple programming languages |
15 | | - |
16 | | -- **Language Support** |
17 | | - - Python (with AST-based compression) |
18 | | - - JavaScript |
19 | | - - Java |
20 | | - - C/C++ |
21 | | - - Shell scripts |
22 | | - - HTML/CSS |
23 | | - - Configuration files (JSON, YAML, TOML, INI) |
24 | | - - Markdown |
25 | | - |
26 | | -- **LLM-Friendly Output** |
27 | | - - XML-style semantic markers |
28 | | - - File metadata and type information |
29 | | - - Organized imports section |
30 | | - - Clear file boundaries |
31 | | - - Consistent formatting |
| 10 | +- Preserves important comments and docstrings |
| 11 | +- Removes unnecessary content |
| 12 | +- Structured, LLM-friendly output |
| 13 | +- GitHub Actions integration for automatic updates |
32 | 14 |
|
33 | 15 | ## Installation |
34 | 16 |
|
35 | | -This project uses [uv](https://github.com/astral-sh/uv) for dependency management. |
36 | | - |
37 | 17 | ```bash |
38 | | -# Install uv if you haven't already |
39 | | -curl -LsSf https://astral.sh/uv/install.sh | sh |
40 | | - |
41 | | -# Install the package and its dependencies |
42 | | -uv pip install . |
43 | | - |
44 | | -# For development |
45 | | -uv pip install -e ".[dev]" |
| 18 | +pip install git+https://github.com/ngmisl/llmstxt.git |
46 | 19 | ``` |
47 | 20 |
|
48 | 21 | ## Usage |
49 | 22 |
|
50 | | -### Local Usage |
| 23 | +### Command Line |
51 | 24 |
|
52 | 25 | ```bash |
53 | | -# Generate llms.txt from current directory |
54 | | -python llms.py |
55 | | -``` |
| 26 | +# Generate llms.txt in current directory |
| 27 | +python -m llmstxt |
56 | 28 |
|
57 | | -The script will: |
58 | | -1. Scan the current directory recursively |
59 | | -2. Process files according to .gitignore rules |
60 | | -3. Generate `llms.txt` with compressed content |
| 29 | +# Or import and use in your code |
| 30 | +from llmstxt import generate_llms_txt |
| 31 | +generate_llms_txt() |
| 32 | +``` |
61 | 33 |
|
62 | 34 | ### GitHub Actions Integration |
63 | 35 |
|
64 | | -There are two ways to use this tool with GitHub Actions: |
65 | | - |
66 | | -1. **For Your Own Repository** |
67 | | - ```bash |
68 | | - # Create a workflow file |
69 | | - mkdir -p .github/workflows |
70 | | - curl -o .github/workflows/update-llms.yml https://raw.githubusercontent.com/ngmisl/llmstxt/main/.github/workflows/update-llms.yml |
71 | | - ``` |
72 | | - |
73 | | - The workflow will: |
74 | | - - Run automatically on pushes to main/master |
75 | | - - Create a PR with updated llms.txt when changes are detected |
76 | | - - Can be manually triggered from the Actions tab |
77 | | - |
78 | | -2. **For Remote Repositories** |
79 | | - You can trigger the action for any repository using the GitHub API: |
80 | | - |
81 | | - ```bash |
82 | | - curl -X POST \ |
83 | | - -H "Authorization: token $GITHUB_TOKEN" \ |
84 | | - -H "Accept: application/vnd.github.v3+json" \ |
85 | | - https://api.github.com/repos/ngmisl/llmstxt/dispatches \ |
86 | | - -d '{"event_type": "update-llms", "client_payload": {"repository": "https://github.com/user/repo.git"}}' |
87 | | - ``` |
88 | | - |
89 | | - This will: |
90 | | - - Clone the target repository |
91 | | - - Generate llms.txt |
92 | | - - Create a PR with the changes |
93 | | - |
94 | | -The workflow uses GitHub's PR system to ensure changes are reviewed before being merged. |
95 | | - |
96 | | -## Output Format |
97 | | - |
98 | | -The generated `llms.txt` file follows this structure: |
99 | | - |
100 | | -```python |
101 | | -# Project: llmstxt |
102 | | - |
103 | | -## Project Structure |
104 | | -This file contains the compressed and processed contents of the project. |
105 | | - |
106 | | -### File Types |
107 | | -- .py |
108 | | -- .js |
109 | | -- .java |
110 | | -... |
111 | | - |
112 | | -<file>src/main.py</file> |
113 | | -<metadata> |
114 | | -path: src/main.py |
115 | | -type: py |
116 | | -size: 1234 bytes |
117 | | -</metadata> |
118 | | - |
119 | | -<imports> |
120 | | -import ast |
121 | | -from typing import Optional |
122 | | -</imports> |
123 | | - |
124 | | -<code lang='python'> |
125 | | -def example(): |
126 | | - """Docstring preserved.""" |
127 | | - return True |
128 | | -</code> |
129 | | - |
130 | | -<file>src/utils.js</file> |
131 | | -<metadata> |
132 | | -path: src/utils.js |
133 | | -type: js |
134 | | -size: 567 bytes |
135 | | -</metadata> |
136 | | - |
137 | | -<code lang='javascript'> |
138 | | -function helper() { |
139 | | - return true; |
140 | | -} |
141 | | -</code> |
| 36 | +To automatically update `llms.txt` in your repository: |
| 37 | + |
| 38 | +1. Create `.github/workflows/update-llms.yml` with: |
| 39 | + |
| 40 | +```yaml |
| 41 | +name: Update llms.txt |
| 42 | + |
| 43 | +on: |
| 44 | + push: |
| 45 | + branches: [main, master] |
| 46 | + pull_request: |
| 47 | + branches: [main, master] |
| 48 | + workflow_dispatch: # Allow manual triggering |
| 49 | + |
| 50 | +permissions: |
| 51 | + contents: write |
| 52 | + |
| 53 | +jobs: |
| 54 | + update-llms: |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout repository |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Set up Python |
| 61 | + uses: actions/setup-python@v4 |
| 62 | + with: |
| 63 | + python-version: "3.12" |
| 64 | + cache: "pip" |
| 65 | + |
| 66 | + - name: Install llmstxt tool |
| 67 | + run: | |
| 68 | + python -m venv .venv |
| 69 | + . .venv/bin/activate |
| 70 | + python -m pip install --upgrade pip |
| 71 | + pip install git+https://github.com/ngmisl/llmstxt.git |
| 72 | +
|
| 73 | + - name: Generate llms.txt |
| 74 | + run: | |
| 75 | + . .venv/bin/activate |
| 76 | + rm -f llms.txt |
| 77 | + python -c "from llmstxt import generate_llms_txt; generate_llms_txt()" |
| 78 | +
|
| 79 | + - name: Configure Git |
| 80 | + run: | |
| 81 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 82 | + git config --local user.name "github-actions[bot]" |
| 83 | +
|
| 84 | + - name: Commit and push changes |
| 85 | + run: | |
| 86 | + git add llms.txt |
| 87 | + if git diff --staged --quiet; then |
| 88 | + echo "No changes to commit" |
| 89 | + else |
| 90 | + git commit -m "chore: update llms.txt" |
| 91 | + git push |
| 92 | + fi |
142 | 93 | ``` |
143 | 94 |
|
144 | | -## Configuration |
145 | | - |
146 | | -The tool can be configured through function parameters: |
147 | | - |
148 | | -```python |
149 | | -generate_llms_txt( |
150 | | - output_file="llms.txt", # Output filename |
151 | | - max_file_size=100 * 1024, # Max file size (100KB) |
152 | | - allowed_extensions=( # Supported file types |
153 | | - ".py", ".js", ".java", |
154 | | - ".c", ".cpp", ".h", ".hpp", |
155 | | - ".sh", ".txt", ".md", |
156 | | - ".json", ".xml", ".yaml", |
157 | | - ".yml", ".toml", ".ini" |
158 | | - ) |
159 | | -) |
160 | | -``` |
| 95 | +The workflow will: |
| 96 | +- Run on push to main/master |
| 97 | +- Run on pull requests |
| 98 | +- Can be triggered manually |
| 99 | +- Generate and commit `llms.txt` automatically |
161 | 100 |
|
162 | 101 | ## Development |
163 | 102 |
|
164 | | -Requirements: |
165 | | - |
166 | | -- Python 3.8+ |
167 | | -- [uv](https://github.com/astral-sh/uv) for dependency management |
168 | | - |
169 | 103 | ```bash |
170 | | -# Install dev dependencies |
171 | | -uv pip install -e ".[dev]" |
| 104 | +# Clone the repository |
| 105 | +git clone https://github.com/ngmisl/llmstxt.git |
| 106 | +cd llmstxt |
| 107 | +
|
| 108 | +# Install development dependencies |
| 109 | +pip install -e ".[dev]" |
172 | 110 |
|
173 | 111 | # Run type checking |
174 | | -mypy llms.py |
| 112 | +mypy llmstxt |
175 | 113 |
|
176 | | -# Run linting and formatting |
177 | | -ruff check . |
178 | | -ruff format . |
| 114 | +# Run linting |
| 115 | +ruff check llmstxt |
179 | 116 | ``` |
180 | 117 |
|
181 | 118 | ## License |
182 | 119 |
|
183 | | -MIT License - See LICENSE file for details |
| 120 | +MIT |
0 commit comments