to_llm is a lightweight Ruby gem that allows you to extract code from your Rails application into text files. It’s especially handy if you want to feed your Rails codebase into a Large Language Model (LLM) or any text-based analysis tool.
- Simple extraction: Automatically scans core Rails directories (
app/models,app/controllers,app/views, etc.). - Configurable: Extracts
.rb,.erb,.js,.yml,.ts, and.tsxby default; easy to adjust. - Rake tasks: Single entry point for extracting everything or selective directories.
- Flexible formats: Outputs to
.txtor.md.
Add to your Gemfile:
gem 'to_llm'And then:
bundle install(Alternatively, you can point gem 'to_llm', git: 'https://github.com/jcmaciel/to_llm.git' to the GitHub repo.)
With v0.1.4, you can run the following commands inside your Rails app:
rails "to_llm:extract[TYPE,FORMAT]"Where:
- TYPE can be
ALL,MODELS,CONTROLLERS,VIEWS,CONFIG,SCHEMA,JAVASCRIPT,HELPERS. - FORMAT can be
txtormd.
Examples:
- Extract everything to Markdown:
rails "to_llm:extract[ALL,md]" - Extract only models to plain text:
rails "to_llm:extract[MODELS,txt]" - If you omit the second parameter, it defaults to
.txt(old usage triggers a warning but still works).
-
Extract everything:
rails "to_llm:extract[ALL,md]"Produces a
to_llm/folder with separate.mdfiles (e.g.,models.md,views.md, etc.). -
Extract only controllers:
rails "to_llm:extract[CONTROLLERS,txt]"Creates/overwrites
to_llm/controllers.txt.
- Fork the repository.
- Create a new branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Add new feature'). - Push to your branch (
git push origin my-new-feature). - Open a Pull Request on GitHub.
Feedback, issues, and PRs are always welcome!