Lich 5 Documentation Generator
Automated YARD documentation generation for the Lich 5 Ruby scripting engine using AI (OpenAI, Anthropic, or Gemini).
π Documentation Website[https://nisugi.github.io/lich-5-docs/]
Overview
This project uses AI to automatically generate comprehensive YARD documentation for the Lich 5 Ruby codebase. The system processes 120 Ruby files, adding professional documentation comments that enable:
-
β 120/120 files with complete YARD documentation
-
π 1,805 methods documented with parameters, return types, and examples
-
π Cross-references between classes and modules
-
π Searchable HTML website hosted on GitHub Pages
-
β‘ Incremental builds that only reprocess changed files
Features
π€ AI-Powered Documentation
-
Supports OpenAI GPT-4, Anthropic Claude, and Google Gemini
-
Generates YARD-compliant comments with
@param,@return,@exampletags -
Preserves existing documentation (never overwrites manual edits)
β‘ Intelligent Incremental Builds
-
SHA256 hash tracking detects changed files
-
Only reprocesses files that have been modified
-
Saves time and API costs (~$0.50 β $0.00 for unchanged codebases)
π Modular 3-Stage Workflow
Generate β Validate β Build HTML
Each stage is manually triggered, giving full control over the documentation process.
π― 100% Validation Success
-
All generated documentation passes YARD validation
-
Automatically fixes common issues (parameter syntax, duplicate tags)
-
Clean, professional output ready for publication
Quick Start
Prerequisites
-
Python 3.11+
-
Ruby 3.0+ with YARD gem
-
API key for OpenAI, Anthropic, or Gemini
Setup
-
Clone the repository
bash git clone https://github.com/Nisugi/lich-5-docs.git cd lich-5-docs -
Install Python dependencies
bash pip install -r requirements.txt -
Install YARD
bash gem install yard -
Configure API key
bash cp .env.example .env # Edit .env and add your API key
Usage
Generate Documentation
# Incremental build (skip unchanged files)
python generate_docs.py /path/to/lich-5/lib \
--provider openai \
--output-structure mirror
# Full rebuild (reprocess all files)
python generate_docs.py /path/to/lich-5/lib \
--provider openai \
--output-structure mirror \
--force-rebuild
# Single file (for testing)
python generate_docs.py \
--file /path/to/lich-5/lib/gemstone/psms/feat.rb \
--provider openai \
--output-structure mirror
Validate Documentation
# Validate all files
python validate_docs.py --dir documented
# Validate single file
python validate_docs.py --file documented/global_defs.rb
Build HTML Documentation
# Generate HTML website
python build_html.py --input ./documented --output ./docs --clean
GitHub Actions Workflows
The project includes 4 GitHub Actions workflows for automated documentation:
1. Generate Batch Documentation
Path: .github/workflows/generate-batch.yml
Generates documentation for all Ruby files from the lich-5 repository.
Inputs: - provider: LLM provider (openai, anthropic, gemini) - source_repo: Source repository (default: elanthia-online/lich-5) - source_branch: Branch to document (default: main) - full_rebuild: Force reprocess all files (default: false)
2. Generate Single File
Path: .github/workflows/generate-single.yml
Fast iteration on a single file for testing and debugging.
3. Validate Documentation
Path: .github/workflows/validate-docs.yml
Validates all documented files using YARD.
4. Build HTML
Path: .github/workflows/build-html.yml
Generates the static HTML documentation website.
Inputs: - title: Documentation title (default: βLich 5 Documentationβ) - clean: Clean output directory before building (default: true)
Project Structure
lich-5-docs/
βββ documented/ # YARD-documented Ruby files (mirrors lich-5/lib structure)
β βββ common/
β βββ gemstone/
β βββ attributes/
β βββ ...
βββ docs/ # Generated HTML documentation (GitHub Pages)
βββ output/latest/ # Build artifacts
β βββ manifest.json # Incremental build tracking
βββ src/providers/ # LLM provider implementations
β βββ openai_provider.py
β βββ anthropic_provider.py
β βββ gemini.py
βββ generate_docs.py # Main documentation generator
βββ validate_docs.py # YARD validation wrapper
βββ build_html.py # HTML documentation builder
How It Works
1. Generation
-
Clones the lich-5 repository
-
Processes each Ruby file with AI to generate YARD comments
-
Returns structured JSON:
[{line_number, anchor, indent, comment}, ...] -
Inserts comments at the correct positions in the source code
-
Commits documented files to the
documented/directory
2. Incremental Builds
-
Calculates SHA256 hash of each file (code only, excluding comments)
-
Compares with hashes in
manifest.json -
Skips files that havenβt changed
-
Only reprocesses modified files
3. Validation
-
Runs
yard stats --list-undocon all documented files -
Parses warnings and errors
-
Reports validation success rate
4. HTML Generation
-
Runs
yard docto generate static HTML website -
Verifies output (checks for index.html, counts documented items)
-
Commits to
docs/directory -
GitHub Pages automatically deploys the website
Configuration
Environment Variables
# LLM Provider (openai, anthropic, gemini)
LLM_PROVIDER=openai
# API Keys (only one required based on provider)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GEMINI_API_KEY=...
Provider Options
The system supports three LLM providers:
-
OpenAI: Uses
gpt-4o-minimodel (paid, see OpenAI pricing) -
Anthropic: Uses
claude-3-haiku-20240307model (paid, see Anthropic pricing) -
Gemini: Uses
gemini-2.0-flash-expmodel (free tier available, see Google AI pricing)
For current pricing and rate limits, consult the providerβs official documentation.
Development
Running Tests
pytest tests/
Testing Without API Costs
# Use mock provider (no API calls)
python generate_docs.py /path/to/source --provider mock
Checking Provider Status
from providers import ProviderFactory
validation = ProviderFactory.validate_environment()
print(validation) # Shows provider, API key status, warnings
Documentation
-
CLAUDE.md[CLAUDE.md] - Detailed technical documentation for developers
-
env.env.example[.env.example] - Environment variable template
-
Documentation[https://nisugi.github.io/lich-5-docs/] - Live documentation website
Contributing
-
Fork the repository
-
Create a feature branch (
git checkout -b feature/amazing-feature) -
Commit your changes (
git commit -m 'Add amazing feature') -
Push to the branch (
git push origin feature/amazing-feature) -
Open a Pull Request
License
This project is independent of the Lich 5 project and is used for documentation purposes.
Acknowledgments
-
Lich 5 - elanthia-online/lich-5
-
YARD - Ruby documentation tool
-
OpenAI, Anthropic, Google - AI providers for documentation generation
Built with β€οΈ using AI-powered documentation generation