Generate comprehensive llms.txt documentation from local Rust project source code.
Generates comprehensive llms.txt documentation from local Rust project source code.
/plugin marketplace add ZhangHanDong/rust-skills/plugin install zhanghandong-rust-skills@ZhangHanDong/rust-skillsGenerate comprehensive llms.txt documentation from local Rust project source code.
Arguments: $ARGUMENTS
# Check if Cargo.toml exists
if [ ! -f "${source_path}/Cargo.toml" ]; then
echo "Error: No Cargo.toml found at ${source_path}"
exit 1
fi
Extract from Cargo.toml:
name - crate nameversion - crate versiondescription - crate description[features] - feature flags[dependencies] - dependencies list# Parse Cargo.toml
grep -E "^name|^version|^description" Cargo.toml
# Detect workspace
if grep -q "\[workspace\]" Cargo.toml; then
# Parse members
grep -A 20 "^\[workspace\]" Cargo.toml | grep -E "members\s*="
# Process each member separately
fi
Workspace handling:
[workspace] section exists, identify all members# Generate JSON documentation
cargo +nightly rustdoc -- -Z unstable-options --output-format json 2>/dev/null
# Output location
ls target/doc/*.json
rustdoc JSON contains:
Parse JSON for:
.index[*] | select(.visibility == "public") | {
name: .name,
kind: .kind,
docs: .docs,
sig: .inner.decl
}
If rustdoc fails (no nightly, compilation errors):
# Extract crate-level documentation
grep "^//!" src/lib.rs | sed 's/^\/\/! //'
# Extract module documentation
find src -name "*.rs" -exec grep -l "^//!" {} \;
# Extract pub items with doc comments
grep -B 10 "^pub " src/**/*.rs | grep -E "///|^pub "
# Extract pub item signatures
grep -E "^pub (fn|struct|enum|trait|type|mod|const|static)" src/**/*.rs
Extraction targets:
| Pattern | Captures |
|---|---|
//! | Module-level docs |
/// | Item-level docs |
pub fn | Public functions |
pub struct | Public structs |
pub enum | Public enums |
pub trait | Public traits |
pub type | Type aliases |
pub mod | Public modules |
if [ -f "${source_path}/README.md" ]; then
# Extract overview section (first 100 lines or until ## section)
head -100 README.md
fi
# From Cargo.toml [features] section
grep -A 50 "^\[features\]" Cargo.toml | grep -B 50 "^\[" | head -50
Consolidate all extracted content into this format:
# {CrateName}
> {Description from Cargo.toml}
**Version:** {version} | **Source:** local
---
## Overview
{Content from README.md or crate-level //! docs}
## Modules
### {module_name}
{Module documentation from //!}
#### Key Types
| Type | Description |
|------|-------------|
| `StructName` | From /// docs |
| `EnumName` | From /// docs |
#### Key Functions
```rust
/// Function documentation
pub fn function_name(param: Type) -> ReturnType
```
## Code Examples
```rust
// Examples extracted from /// docs or README
```
---
## Feature Flags
| Feature | Dependencies | Description |
|---------|--------------|-------------|
| `feature_name` | dep1, dep2 | From Cargo.toml comments |
---
## Dependencies
| Crate | Version | Features |
|-------|---------|----------|
| `dep_name` | 1.0 | feature1, feature2 |
---
## Source Structure
```
src/
├── lib.rs - Main library entry
├── module1/
│ ├── mod.rs - Module docs
│ └── types.rs - Type definitions
└── module2.rs - Single-file module
```
# Generate timestamp
timestamp=$(date +%Y%m%d%H%M)
# Get crate name
crate_name=$(grep "^name" Cargo.toml | head -1 | cut -d'"' -f2)
# Output path
output="${output_path:-$HOME/tmp/${timestamp}-${crate_name}-llms.txt}"
# Ensure directory exists
mkdir -p "$(dirname "$output")"
# Write file
echo "Output saved to: $output"
1. Try rustdoc JSON
↓ (if failed)
2. Use source code parsing
↓ (always)
3. Supplement with Cargo.toml + README.md
Automatic fallback triggers:
When falling back, inform user:
rustdoc JSON generation failed, using source code parsing.
Some type information may be incomplete.
For workspaces with multiple crates:
Option 1: Combined llms.txt
~/tmp/{timestamp}-{workspace}-llms.txt
Contains sections for each member crate.
Option 2: Separate files
~/tmp/{timestamp}-{crate1}-llms.txt
~/tmp/{timestamp}-{crate2}-llms.txt
Ask user which approach they prefer for workspaces.
This command integrates with the Skills creation workflow:
Local Rust Source
↓
/create-llms-from-source {path}
↓
~/tmp/{timestamp}-{crate}-llms.txt
↓
/create-skills-via-llms {crate} {llms_path}
↓
~/.claude/skills/{crate}-*/
Or via sync-crate-skills:
/sync-crate-skills --from-source {path}
# Generate llms.txt for current directory
/create-llms-from-source
# Generate for specific project
/create-llms-from-source /path/to/my-rust-project
# Specify output path
/create-llms-from-source /path/to/project ~/docs/my-crate-llms.txt
# For workspace project
/create-llms-from-source /path/to/workspace
pub(crate), pub(super)) are excluded