to_llm 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -128
- data/lib/tasks/to_llm.rake +114 -54
- data/lib/to_llm/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79e005ef579c63795093a10bc0318048894fdaef71f959eaac97ec46d9d12340
|
4
|
+
data.tar.gz: 297867c42b4a9caf4d803798edd51deae0fcf63815f47a3e742ddd60cbf918ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aaa9070c20e815f41aebb34bb933e4ac289e45b0640edb0abe80af02b818ed3e42d7c902194df3571363229c0b5fd839cd3fc3c8d90e04f6bed6f61f15523a1
|
7
|
+
data.tar.gz: 9bde15f9c6be326a6659fd7d6d497234de245928c59179c0d5bc2487c254d446228684be518cbca768ec5a479e1449de2410db75ac02ff545cfd1426b7f17e65
|
data/README.md
CHANGED
@@ -1,166 +1,75 @@
|
|
1
1
|
# to_llm
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/to_llm)
|
4
|
-
[](LICENSE.txt)
|
5
4
|
|
6
|
-
**to_llm** is a lightweight Ruby gem that
|
7
|
-
|
8
|
-
---
|
9
|
-
|
10
|
-
## Table of Contents
|
11
|
-
|
12
|
-
- [Features](#features)
|
13
|
-
- [Installation](#installation)
|
14
|
-
- [Usage](#usage)
|
15
|
-
- [Commands](#commands)
|
16
|
-
- [Configuration](#configuration)
|
17
|
-
- [Examples](#examples)
|
18
|
-
- [Contributing](#contributing)
|
19
|
-
- [License](#license)
|
20
|
-
|
21
|
-
---
|
5
|
+
**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.
|
22
6
|
|
23
7
|
## Features
|
24
8
|
|
25
|
-
- **Simple extraction**: Automatically scans
|
26
|
-
- **Configurable**:
|
27
|
-
- **Rake tasks**:
|
28
|
-
- **
|
29
|
-
|
30
|
-
---
|
9
|
+
- **Simple extraction**: Automatically scans core Rails directories (`app/models`, `app/controllers`, `app/views`, etc.).
|
10
|
+
- **Configurable**: Extracts `.rb`, `.erb`, `.js`, `.yml`, `.ts`, and `.tsx` by default; easy to adjust.
|
11
|
+
- **Rake tasks**: Single entry point for extracting everything or selective directories.
|
12
|
+
- **Flexible formats**: Outputs to `.txt` or `.md`.
|
31
13
|
|
32
14
|
## Installation
|
33
15
|
|
34
|
-
Add
|
16
|
+
Add to your `Gemfile`:
|
35
17
|
|
36
18
|
```ruby
|
37
|
-
gem 'to_llm'
|
19
|
+
gem 'to_llm'
|
38
20
|
```
|
39
|
-
|
40
|
-
> Or using RubyGems
|
41
|
-
> ```ruby
|
42
|
-
> gem 'to_llm'
|
43
|
-
> ```
|
44
|
-
|
45
|
-
Then execute:
|
21
|
+
And then:
|
46
22
|
|
47
23
|
```bash
|
48
24
|
bundle install
|
49
25
|
```
|
50
26
|
|
51
|
-
|
27
|
+
*(Alternatively, you can point `gem 'to_llm', git: 'https://github.com/jcmaciel/to_llm.git'` to the GitHub repo.)*
|
52
28
|
|
53
29
|
## Usage
|
54
30
|
|
55
|
-
|
31
|
+
With **v0.1.3**, you can run the following commands inside your Rails app:
|
56
32
|
|
57
33
|
```bash
|
58
|
-
rails to_llm:extract
|
34
|
+
rails "to_llm:extract[TYPE,FORMAT]"
|
59
35
|
```
|
60
36
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
## Commands
|
66
|
-
|
67
|
-
### 1. `rails to_llm:extract -ALL`
|
68
|
-
|
69
|
-
- **Description**: Extracts from all supported Rails directories:
|
70
|
-
- `app/models` -> `models.txt`
|
71
|
-
- `app/controllers` -> `controllers.txt`
|
72
|
-
- `app/views` -> `views.txt`
|
73
|
-
- `app/helpers` -> `helpers.txt`
|
74
|
-
- `config` -> `config.txt` (including `config/initializers`)
|
75
|
-
- `db/schema.rb` -> `schema.txt`
|
76
|
-
- **Result**: Creates a folder named `to_llm/` with separate `.txt` files.
|
77
|
-
|
78
|
-
### 2. `rails to_llm:extract -MODELS`
|
79
|
-
|
80
|
-
- **Description**: Extracts only files from `app/models`.
|
81
|
-
- **Output**: Creates (or overwrites) `to_llm/models.txt`.
|
82
|
-
|
83
|
-
### 3. `rails to_llm:extract -CONTROLLERS`
|
84
|
-
|
85
|
-
- **Description**: Extracts only from `app/controllers`.
|
86
|
-
- **Output**: `to_llm/controllers.txt`.
|
87
|
-
|
88
|
-
### 4. `rails to_llm:extract -VIEWS`
|
89
|
-
|
90
|
-
- **Description**: Extracts from `app/views`.
|
91
|
-
- **Output**: `to_llm/views.txt`.
|
92
|
-
|
93
|
-
### 5. `rails to_llm:extract -CONFIG`
|
94
|
-
|
95
|
-
- **Description**: Extracts from `config`, including `config/initializers`.
|
96
|
-
- **Output**: `to_llm/config.txt`.
|
97
|
-
|
98
|
-
### 6. `rails to_llm:extract -SCHEMA`
|
99
|
-
|
100
|
-
- **Description**: Extracts only `db/schema.rb`.
|
101
|
-
- **Output**: `to_llm/schema.txt`.
|
37
|
+
Where:
|
38
|
+
- **TYPE** can be `ALL`, `MODELS`, `CONTROLLERS`, `VIEWS`, `CONFIG`, `SCHEMA`, `JAVASCRIPT`, `HELPERS`.
|
39
|
+
- **FORMAT** can be `txt` or `md`.
|
102
40
|
|
103
|
-
|
41
|
+
**Examples**:
|
104
42
|
|
105
|
-
|
106
|
-
|
107
|
-
If you want to customize what extensions are included or which directories map to which output files, open the `lib/tasks/to_llm.rake` file (inside this gem) and edit:
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
file_extensions = %w[.rb .erb .js .yml]
|
111
|
-
directories_to_files = {
|
112
|
-
"app/models" => "models.txt",
|
113
|
-
"app/controllers" => "controllers.txt",
|
114
|
-
# ...
|
115
|
-
}
|
116
|
-
```
|
117
|
-
|
118
|
-
This gem is intentionally minimalist. Feel free to fork or override these settings in your local app.
|
119
|
-
|
120
|
-
---
|
121
|
-
|
122
|
-
## Examples
|
123
|
-
|
124
|
-
1. **Extract everything**:
|
43
|
+
1. Extract *everything* to Markdown:
|
125
44
|
```bash
|
126
|
-
rails to_llm:extract
|
127
|
-
```
|
128
|
-
Generates:
|
45
|
+
rails "to_llm:extract[ALL,md]"
|
129
46
|
```
|
130
|
-
|
131
|
-
models.txt
|
132
|
-
controllers.txt
|
133
|
-
views.txt
|
134
|
-
helpers.txt
|
135
|
-
config.txt
|
136
|
-
schema.txt
|
137
|
-
```
|
138
|
-
|
139
|
-
2. **Extract only views**:
|
47
|
+
2. Extract only models to plain text:
|
140
48
|
```bash
|
141
|
-
rails to_llm:extract
|
142
|
-
```
|
143
|
-
Generates:
|
49
|
+
rails "to_llm:extract[MODELS,txt]"
|
144
50
|
```
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
51
|
+
3. If you omit the second parameter, it defaults to `.txt` (old usage triggers a warning but still works).
|
52
|
+
|
53
|
+
## Examples
|
54
|
+
|
55
|
+
- **Extract everything**:
|
56
|
+
```bash
|
57
|
+
rails "to_llm:extract[ALL,md]"
|
58
|
+
```
|
59
|
+
Produces a `to_llm/` folder with separate `.md` files (e.g., `models.md`, `views.md`, etc.).
|
149
60
|
|
150
|
-
|
61
|
+
- **Extract only controllers**:
|
62
|
+
```bash
|
63
|
+
rails "to_llm:extract[CONTROLLERS,txt]"
|
64
|
+
```
|
65
|
+
Creates/overwrites `to_llm/controllers.txt`.
|
151
66
|
|
152
67
|
## Contributing
|
153
68
|
|
154
|
-
1. Fork the
|
155
|
-
2. Create a new branch
|
69
|
+
1. Fork the repository.
|
70
|
+
2. Create a new branch (`git checkout -b my-new-feature`).
|
156
71
|
3. Commit your changes (`git commit -am 'Add new feature'`).
|
157
72
|
4. Push to your branch (`git push origin my-new-feature`).
|
158
|
-
5.
|
159
|
-
|
160
|
-
We welcome issues, PRs, and general feedback!
|
161
|
-
|
162
|
-
---
|
163
|
-
|
164
|
-
## License
|
73
|
+
5. Open a Pull Request on GitHub.
|
165
74
|
|
166
|
-
|
75
|
+
Feedback, issues, and PRs are always welcome!
|
data/lib/tasks/to_llm.rake
CHANGED
@@ -1,39 +1,29 @@
|
|
1
|
+
# lib/tasks/to_llm.rake
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
#
|
4
|
-
# rails to_llm:extract -ALL
|
5
|
-
# rails to_llm:extract -MODELS
|
6
|
-
# rails to_llm:extract -CONTROLLERS
|
7
|
-
# rails to_llm:extract -VIEWS
|
8
|
-
# rails to_llm:extract -CONFIG
|
9
|
-
# rails to_llm:extract -SCHEMA
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
4
|
namespace :to_llm do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
puts "----- to_llm:extract started with type=#{extract_type} -----"
|
5
|
+
def run_extraction(extract_type, output_format)
|
6
|
+
extract_type = extract_type&.upcase || "ALL"
|
7
|
+
output_format = output_format&.downcase || "txt"
|
8
|
+
|
9
|
+
puts ">> to_llm:extract started with type=#{extract_type}, format=#{output_format}"
|
20
10
|
|
21
11
|
# Directory where extracted files will be stored
|
22
12
|
output_dir = "to_llm"
|
23
13
|
FileUtils.mkdir_p(output_dir)
|
24
14
|
|
25
|
-
|
15
|
+
|
26
16
|
directories_to_files = {
|
27
|
-
"app/models" => "models
|
28
|
-
"app/controllers" => "controllers
|
29
|
-
"app/views" => "views
|
30
|
-
"app/helpers" => "helpers
|
31
|
-
"app/javascript" => "javascript
|
32
|
-
"config" => "config
|
33
|
-
"db/schema.rb" => "schema
|
17
|
+
"app/models" => "models",
|
18
|
+
"app/controllers" => "controllers",
|
19
|
+
"app/views" => "views",
|
20
|
+
"app/helpers" => "helpers",
|
21
|
+
"app/javascript" => "javascript",
|
22
|
+
"config" => "config",
|
23
|
+
"db/schema.rb" => "schema"
|
34
24
|
}
|
35
25
|
|
36
|
-
|
26
|
+
|
37
27
|
filter_map = {
|
38
28
|
"ALL" => %w[app/models app/controllers app/views app/helpers app/javascript config db/schema.rb],
|
39
29
|
"MODELS" => %w[app/models],
|
@@ -41,50 +31,120 @@ namespace :to_llm do
|
|
41
31
|
"VIEWS" => %w[app/views],
|
42
32
|
"CONFIG" => %w[config],
|
43
33
|
"SCHEMA" => %w[db/schema.rb],
|
44
|
-
"JAVASCRIPT"
|
45
|
-
"HELPERS"
|
34
|
+
"JAVASCRIPT" => %w[app/javascript],
|
35
|
+
"HELPERS" => %w[app/helpers]
|
46
36
|
}
|
47
37
|
|
48
|
-
#
|
38
|
+
# File extensions to extract
|
49
39
|
file_extensions = %w[.rb .erb .js .yml .ts .tsx]
|
50
40
|
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
# Clean old outputs
|
42
|
+
directories_to_files.values.each do |base_filename|
|
43
|
+
path = File.join(output_dir, "#{base_filename}.#{output_format}")
|
44
|
+
File.delete(path) if File.exist?(path)
|
54
45
|
end
|
55
46
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
f.puts "\n"
|
66
|
-
end
|
47
|
+
# Detects a language for syntax highlighting if output_format = md
|
48
|
+
def detect_language(ext)
|
49
|
+
case ext
|
50
|
+
when ".rb" then "ruby"
|
51
|
+
when ".erb" then "erb"
|
52
|
+
when ".js" then "javascript"
|
53
|
+
when ".ts", ".tsx" then "typescript"
|
54
|
+
when ".yml" then "yaml"
|
55
|
+
else "plaintext"
|
67
56
|
end
|
68
57
|
end
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
# Writes file content in either txt or md format
|
60
|
+
def write_content(path, content, output_format, output_file)
|
61
|
+
if output_format == "md"
|
62
|
+
language = detect_language(File.extname(path))
|
63
|
+
<<~MARKDOWN
|
64
|
+
## #{path}
|
65
|
+
```#{language}
|
66
|
+
#{content}
|
67
|
+
```
|
68
|
+
MARKDOWN
|
69
|
+
else
|
70
|
+
# txt format
|
71
|
+
<<~TXT
|
72
|
+
#{path}:
|
73
|
+
----------------------------------------------------
|
74
|
+
#{content}
|
75
|
+
|
76
|
+
TXT
|
77
|
+
end
|
78
|
+
end
|
73
79
|
|
80
|
+
# Method to handle directories or single-file extraction
|
81
|
+
def extract_content(dir_or_file, file_extensions, output_format, base_output_name, output_dir)
|
74
82
|
if File.file?(dir_or_file)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
83
|
+
|
84
|
+
return unless File.exist?(dir_or_file)
|
85
|
+
|
86
|
+
content = File.read(dir_or_file)
|
87
|
+
formatted = write_content(dir_or_file, content, output_format, base_output_name)
|
88
|
+
File.open(File.join(output_dir, "#{base_output_name}.#{output_format}"), "a") do |f|
|
89
|
+
f.puts formatted
|
82
90
|
end
|
83
91
|
else
|
84
|
-
|
92
|
+
|
93
|
+
Dir.glob(File.join(dir_or_file, "**", "*")) do |path|
|
94
|
+
next if File.directory?(path)
|
95
|
+
next unless file_extensions.include?(File.extname(path))
|
96
|
+
|
97
|
+
content = File.read(path)
|
98
|
+
formatted = write_content(path, content, output_format, base_output_name)
|
99
|
+
File.open(File.join(output_dir, "#{base_output_name}.#{output_format}"), "a") do |f|
|
100
|
+
f.puts formatted
|
101
|
+
end
|
102
|
+
end
|
85
103
|
end
|
86
104
|
end
|
87
105
|
|
88
|
-
|
106
|
+
|
107
|
+
(filter_map[extract_type] || []).each do |dir_or_file|
|
108
|
+
next unless directories_to_files.key?(dir_or_file)
|
109
|
+
|
110
|
+
base_output_name = directories_to_files[dir_or_file]
|
111
|
+
extract_content(dir_or_file, file_extensions, output_format, base_output_name, output_dir)
|
112
|
+
end
|
113
|
+
|
114
|
+
puts ">> to_llm:extract finished! See '#{output_dir}' for .#{output_format} files."
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
desc "Extract code into txt or md. Usage: rails \"to_llm:extract[TYPE,FORMAT]\"\n" \
|
119
|
+
"Examples:\n" \
|
120
|
+
" rails \"to_llm:extract[ALL,md]\"\n" \
|
121
|
+
" rails \"to_llm:extract[MODELS,txt]\""
|
122
|
+
task :extract, [:type_and_format] => :environment do |_t, args|
|
123
|
+
if args[:type_and_format].blank?
|
124
|
+
# No parameters passed -> show help message
|
125
|
+
puts "--------------------------------------------------------------------"
|
126
|
+
puts "Usage: rails \"to_llm:extract[TYPE,FORMAT]\""
|
127
|
+
puts "Types: ALL, MODELS, CONTROLLERS, VIEWS, CONFIG, SCHEMA, JAVASCRIPT, HELPERS"
|
128
|
+
puts "Format: txt or md (Markdown)"
|
129
|
+
puts "Examples:"
|
130
|
+
puts " rails \"to_llm:extract[ALL,md]\""
|
131
|
+
puts " rails \"to_llm:extract[MODELS,txt]\""
|
132
|
+
puts "--------------------------------------------------------------------"
|
133
|
+
next
|
134
|
+
end
|
135
|
+
|
136
|
+
# Attempt to parse "TYPE,FORMAT"
|
137
|
+
type, format = args[:type_and_format].split(",")
|
138
|
+
|
139
|
+
if format.nil?
|
140
|
+
# Old usage
|
141
|
+
puts "You are using the old usage: rails to_llm:extract #{type}"
|
142
|
+
puts "Please use: rails \"to_llm:extract[#{type},md]\" or rails \"to_llm:extract[#{type},txt]\"."
|
143
|
+
|
144
|
+
run_extraction(type, "txt")
|
145
|
+
else
|
146
|
+
# New usage
|
147
|
+
run_extraction(type, format)
|
148
|
+
end
|
89
149
|
end
|
90
150
|
end
|
data/lib/to_llm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_llm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Carlos Maciel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
27
|
description: A simple gem that provides a Rails command or Rake tasks to export .rb,
|
28
|
-
.erb, .js, and .yml files into .txt for LLM ingestion.
|
28
|
+
.erb, .js, and .yml files into .txt or .md for LLM ingestion.
|
29
29
|
email:
|
30
30
|
- jcmacielp@gmail.com
|
31
31
|
executables: []
|