A Swift Package Plugin that automatically generates llms.txt files for Swift packages to provide LLM-friendly documentation.
The LLMSTxtGenerator plugin analyzes your Swift package's public API and generates a comprehensive llms.txt file that contains structured documentation optimized for Large Language Models. This follows the llms.txt standard for providing LLM-friendly content to websites and packages, making it easier for LLMs to understand and work with your Swift package.
- ✅ Cross-platform support (macOS, iOS, tvOS, watchOS, visionOS, and Linux)
- ✅ Automatic detection of public APIs
- ✅ Extraction of documentation comments with examples
- ✅ Support for classes, structs, enums, protocols, and functions
- ✅ Clean Swift-style method signatures (e.g.,
add(_:_:),create(key:value:)) - ✅ Markdown-formatted output optimized for LLMs
- ✅ Swift Testing framework support
Add this package as a dependency in your Package.swift:
dependencies: [
.package(url: "https://github.com/edgeengineer/llmstxt-generator.git", from: "1.0.0")
]To generate an llms.txt file for your Swift package, run the following command in your package directory:
swift package plugin generate-llms-txtThis will create an llms.txt file in your package root containing documentation for all public APIs.
This repository includes a complete example demonstrating the plugin's capabilities. To test it:
-
Clone the repository:
git clone https://github.com/edgeengineer/llmstxt-generator.git cd llmstxt-generator -
Run the tests to verify everything works:
swift test -
Generate the llms.txt file:
swift package plugin generate-llms-txt
-
View the generated documentation:
cat llms.txt
The ExampleLibrary includes:
- MathUtils: Mathematical operations (
add,multiply,factorial,isPrime) - StringProcessor: String manipulation (
reverse,toTitleCase,countVowels, etc.) - Error types:
MathErrorandStringProcessingError - Protocols:
StringProcessablefor processing contracts
The generated llms.txt file will contain structured documentation like this:
# LLMSTxtGenerator API Documentation
### MathUtils.swift
#### Function: `add(_:_:)`
Calculates the sum of two integers
- Parameters:
- a: The first integer
- b: The second integer
- Returns: The sum of a and b
- Example:
```swift
let result = MathUtils.add(5, 3) // Returns 8public static func add(_ a: Int, _ b: Int) -> Intpublic static func factorial(_ n: Int) throws -> Int
### Integration with Your Swift Package
The plugin works by:
1. **Scanning** your `Sources` directory for Swift files
2. **Parsing** Swift source code using regex patterns
3. **Extracting** public declarations and their documentation comments
4. **Generating** a structured markdown file optimized for LLMs
### Supported Declaration Types
- **Classes**: Public class declarations with inheritance information
- **Structs**: Public struct declarations with protocol conformances
- **Enums**: Public enum declarations with associated types
- **Protocols**: Public protocol declarations with requirements
- **Functions**: Public function declarations with proper signatures (e.g., `create(key:value:)`)
- **Variables/Constants**: Public properties with type information
## Requirements
- Swift 6.0 or later
- Supports all Apple platforms (macOS 14+, iOS 17+, tvOS 17+, watchOS 10+, visionOS 1+)
- Linux support included
## Development
### Running Tests
This project uses Swift Testing framework:
```bash
swift test
swift buildContributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
This project is available under the Apache 2.0 license. See the LICENSE file for more info.