reweave 0.1.0

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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +202 -0
  4. data/bin/reweave +200 -0
  5. data/lib/reweave/config.rb +119 -0
  6. data/lib/reweave/discovery/file_discoverer.rb +23 -0
  7. data/lib/reweave/editing/edit.rb +52 -0
  8. data/lib/reweave/editing/edit_set.rb +96 -0
  9. data/lib/reweave/editing/editor.rb +53 -0
  10. data/lib/reweave/editing.rb +23 -0
  11. data/lib/reweave/execution/engine.rb +317 -0
  12. data/lib/reweave/execution/execution_context.rb +87 -0
  13. data/lib/reweave/execution/project.rb +45 -0
  14. data/lib/reweave/execution.rb +10 -0
  15. data/lib/reweave/parser.rb +71 -0
  16. data/lib/reweave/recipe/composite_recipe.rb +26 -0
  17. data/lib/reweave/recipe/recipe.rb +118 -0
  18. data/lib/reweave/recipe/recipe_descriptor.rb +35 -0
  19. data/lib/reweave/recipe/recipe_option.rb +46 -0
  20. data/lib/reweave/recipe/recipe_registry.rb +44 -0
  21. data/lib/reweave/recipe/scanning_recipe.rb +29 -0
  22. data/lib/reweave/recipe/validation_error.rb +5 -0
  23. data/lib/reweave/recipe.rb +11 -0
  24. data/lib/reweave/recipes/rails/active_job_continuations.rb +62 -0
  25. data/lib/reweave/recipes/rails/controller_markdown_rendering.rb +48 -0
  26. data/lib/reweave/recipes/rails/remove_deprecated_gems.rb +71 -0
  27. data/lib/reweave/recipes/rails/replace_deprecated_find.rb +63 -0
  28. data/lib/reweave/recipes/rails/solid_cache_migration.rb +60 -0
  29. data/lib/reweave/recipes/rails/solid_queue_migration.rb +52 -0
  30. data/lib/reweave/recipes/rails/update_active_record.rb +70 -0
  31. data/lib/reweave/recipes/rails/update_configuration.rb +59 -0
  32. data/lib/reweave/recipes/rails/update_rails_routes.rb +51 -0
  33. data/lib/reweave/recipes/rails/upgrade_rails.rb +39 -0
  34. data/lib/reweave/recipes/ruby/find_method_calls.rb +72 -0
  35. data/lib/reweave/recipes/ruby/modernize_syntax.rb +81 -0
  36. data/lib/reweave/recipes/ruby/remove_unused_methods.rb +93 -0
  37. data/lib/reweave/recipes/ruby/rename_method.rb +55 -0
  38. data/lib/reweave/results/changeset.rb +96 -0
  39. data/lib/reweave/results/execution_result.rb +104 -0
  40. data/lib/reweave/results.rb +9 -0
  41. data/lib/reweave/source.rb +92 -0
  42. data/lib/reweave/version.rb +5 -0
  43. data/lib/reweave/visitor/cursor.rb +105 -0
  44. data/lib/reweave/visitor/ruby_visitor.rb +397 -0
  45. data/lib/reweave/visitor/visitor.rb +127 -0
  46. data/lib/reweave/visitor.rb +10 -0
  47. data/lib/reweave.rb +27 -0
  48. metadata +164 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 516cd3d09450e49ae73939ddf08c0178f8c0e4ecbd28b04dc4d32896b044dc23
4
+ data.tar.gz: d80aaa265dc8123447e89041789f54540ae421e06bb80cc7d580b1882b8c3de9
5
+ SHA512:
6
+ metadata.gz: 5dc592fbdb8ef108ea78c92dca494b3fac7006617d43f3dab959bcd41e08767a85ab52f779b3e94c5e26901f4fdbca2f053b2bdaac645b6ad8705d48fa73752f
7
+ data.tar.gz: f4cc214832d9469932fe4bda1fb5cd7f0e75b4dd1246e6a902ca3872036476e9d2e9cf0b962703c705d7ccab69169b4f9a85cd69f881b4237d22a6f7c5b45307
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aboobacker MK
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # Reweave
2
+
3
+ > Automated code refactoring and modernization for Ruby. Inspired by OpenRewrite, built for Ruby.
4
+
5
+ Reweave is a native Ruby source code transformation framework that enables safe, composable, and repeatable code transformations across entire codebases. It uses the [Prism](https://github.com/ruby/prism) parser for accurate Ruby syntax analysis and provides a lossless source editing engine.
6
+
7
+ ## Features
8
+
9
+ - **Native Ruby** — No JVM, no JRuby, no external runtimes
10
+ - **Lossless editing** — Preserves formatting, comments, and whitespace
11
+ - **Composable recipes** — Build complex transformations from simple parts
12
+ - **Project-wide execution** — Transform entire repositories safely
13
+ - **Prism-powered** — Uses Ruby's official parser for 100% syntax compatibility
14
+ - **Strong testing** — Built-in RSpec testing DSL for recipes
15
+ - **CLI included** — Run transformations from the command line
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ gem install reweave
21
+ ```
22
+
23
+ Or add to your Gemfile:
24
+
25
+ ```ruby
26
+ gem "reweave"
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ Create a recipe:
32
+
33
+ ```ruby
34
+ # rename_deprecated_method.rb
35
+ require "reweave"
36
+
37
+ class RenameDeprecatedMethod < Reweave::Recipe
38
+ display_name "Rename deprecated method"
39
+ description "Renames old_method to new_method."
40
+
41
+ option :old_name, type: String, required: true
42
+ option :new_name, type: String, required: true
43
+
44
+ def get_visitor(context)
45
+ RenameDeprecatedMethodVisitor.new(context, old_name: config[:old_name], new_name: config[:new_name])
46
+ end
47
+ end
48
+
49
+ class RenameDeprecatedMethodVisitor < Reweave::Visitor::RubyVisitor
50
+ def initialize(context, old_name:, new_name:)
51
+ super(context, nil)
52
+ @old_name = old_name.to_sym
53
+ @new_name = new_name
54
+ end
55
+
56
+ def visit(source_file)
57
+ @source_file = source_file
58
+ visit(source_file.root)
59
+ edits
60
+ end
61
+
62
+ def visit_call_node(node)
63
+ return unless node.name == @old_name
64
+ replace_location(node.message_loc, @new_name) if node.message_loc
65
+ end
66
+ end
67
+ ```
68
+
69
+ Run it:
70
+
71
+ ```bash
72
+ # Dry run (shows diffs, doesn't modify files)
73
+ reweave run RenameDeprecatedMethod --old-name old_method --new-name new_method --dry-run
74
+
75
+ # Apply changes
76
+ reweave run RenameDeprecatedMethod --old-name old_method --new-name new_method
77
+ ```
78
+
79
+ Or programmatically:
80
+
81
+ ```ruby
82
+ require "reweave"
83
+
84
+ result = Reweave.run(
85
+ RenameDeprecatedMethod.new(old_name: "old_method", new_name: "new_method"),
86
+ source: "user.old_method"
87
+ )
88
+
89
+ puts result.changed_files.first.updated_source
90
+ # => "user.new_method"
91
+ ```
92
+
93
+ ## Architecture
94
+
95
+ Reweave follows OpenRewrite's architecture adapted for Ruby:
96
+
97
+ ```
98
+ ┌─────────────────────────────────────────────────────┐
99
+ │ Recipe │
100
+ │ (declarative transformation definition) │
101
+ └─────────────────────┬───────────────────────────────┘
102
+ │
103
+ ▼
104
+ ┌─────────────────────────────────────────────────────┐
105
+ │ Visitor │
106
+ │ (traverses Prism AST, collects edits) │
107
+ └─────────────────────┬───────────────────────────────┘
108
+ │
109
+ ▼
110
+ ┌─────────────────────────────────────────────────────┐
111
+ │ EditSet │
112
+ │ (validates & applies byte-accurate edits) │
113
+ └─────────────────────┬───────────────────────────────┘
114
+ │
115
+ ▼
116
+ ┌─────────────────────────────────────────────────────┐
117
+ │ Engine │
118
+ │ (orchestrates execution, cycles, project mgmt) │
119
+ └─────────────────────────────────────────────────────┘
120
+ ```
121
+
122
+ ## Core Concepts
123
+
124
+ ### Recipes
125
+
126
+ Recipes define transformations. They can be:
127
+
128
+ - **Transformation recipes** — Modify source code
129
+ - **Scanning recipes** — Analyze multiple files, accumulate data
130
+ - **Composite recipes** — Compose multiple recipes
131
+
132
+ ### Visitors
133
+
134
+ Visitors traverse the Prism AST and collect edits using a mutation API:
135
+
136
+ ```ruby
137
+ replace(node, "new_code")
138
+ delete(node)
139
+ insert_before(node, "prefix")
140
+ insert_after(node, "suffix")
141
+ ```
142
+
143
+ ### Edits
144
+
145
+ Edits are immutable, byte-accurate operations validated before application:
146
+
147
+ - Offset bounds checking
148
+ - Overlap detection
149
+ - UTF-8 boundary validation
150
+ - Conflict resolution
151
+
152
+ ### Engine
153
+
154
+ The engine handles:
155
+ - File discovery
156
+ - Sequential recipe execution
157
+ - Multi-cycle convergence
158
+ - Dry-run mode
159
+ - Result aggregation
160
+
161
+ ## Testing
162
+
163
+ Reweave includes a first-class testing DSL:
164
+
165
+ ```ruby
166
+ RSpec.describe RenameDeprecatedMethod do
167
+ it "renames method calls" do
168
+ rewrite("user.old_method")
169
+ expect_output("user.new_method")
170
+ end
171
+
172
+ it "handles multiple calls" do
173
+ rewrite("a.old_method; b.old_method")
174
+ expect_output("a.new_method; b.new_method")
175
+ end
176
+ end
177
+ ```
178
+
179
+ ## Built-in Recipes
180
+
181
+ Coming soon:
182
+ - Ruby modernization (hash syntax, keyword args, etc.)
183
+ - Rails migrations (deprecated APIs, version upgrades)
184
+ - RSpec transformations
185
+ - Bundler/Gemfile updates
186
+
187
+ ## Requirements
188
+
189
+ - Ruby 3.2+
190
+ - Prism 1.0+
191
+
192
+ ## License
193
+
194
+ MIT License - see LICENSE file for details.
195
+
196
+ ## Contributing
197
+
198
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
199
+
200
+ ---
201
+
202
+ **Reweave** — Bringing OpenRewrite's power to the Ruby ecosystem.
data/bin/reweave ADDED
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/reweave"
5
+
6
+ def require_recipe(name)
7
+ # First try to get from registry (already loaded)
8
+ recipe_class = Reweave::REGISTRY.get(name)
9
+ return recipe_class if recipe_class
10
+
11
+ # Try to load from reweave/recipes (remove Reweave::Recipes:: prefix if present)
12
+ path = name.gsub(/^Reweave::Recipes::/, "").gsub("::", "/")
13
+ # Convert CamelCase to snake_case for file names
14
+ path = path.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
15
+ require "reweave/recipes/#{path}"
16
+ Reweave::REGISTRY.get(name)
17
+ rescue LoadError => e
18
+ # Try to load as a constant
19
+ begin
20
+ Object.const_get(name)
21
+ rescue NameError
22
+ abort("Recipe not found: #{name} (#{e.message})")
23
+ end
24
+ end
25
+
26
+ def parse_common_options(args)
27
+ options = {}
28
+ options[:dry_run] = args.delete("--dry-run") || args.delete("-n")
29
+ options[:path] = args.delete_at(args.index("--path") || args.index("-p") || 0)
30
+ options[:path] = "." if options[:path] == "--path" || options[:path] == "-p" || options[:path].nil?
31
+ options[:include] = args.delete_at(args.index("--include") + 1) if args.include?("--include")
32
+ options[:exclude] = args.delete_at(args.index("--exclude") + 1) if args.include?("--exclude")
33
+ options[:max_cycles] = args.delete_at(args.index("--max-cycles") + 1)&.to_i if args.include?("--max-cycles")
34
+ options[:json] = args.delete("--json")
35
+ options[:verbose] = args.delete("--verbose")
36
+ options
37
+ end
38
+
39
+ def print_result(result, json: false)
40
+ if json
41
+ require "json"
42
+ puts result.to_h.to_json
43
+ else
44
+ puts result.summary
45
+ if result.context.dry_run && result.changed?
46
+ puts "\n--- Diffs ---"
47
+ puts result.diffs
48
+ end
49
+ end
50
+ end
51
+
52
+ command = ARGV.shift
53
+
54
+ case command
55
+ when "run"
56
+ # Check for --config before parsing other options
57
+ config_idx = ARGV.index("--config") || ARGV.index("-c")
58
+ if config_idx
59
+ config_path = ARGV[config_idx + 1]
60
+ ARGV.delete_at(config_idx)
61
+ ARGV.delete_at(config_idx)
62
+ Reweave::REGISTRY.discover_recipes
63
+ begin
64
+ config = Reweave::Config.load(config_path)
65
+ recipe = Reweave::Config.build_recipe(config)
66
+ rescue Reweave::Config::ValidationError => e
67
+ abort("Validation error: #{e.message}")
68
+ end
69
+ else
70
+ recipe_name = ARGV.shift
71
+ abort("Usage: reweave run <recipe> [options]") unless recipe_name
72
+
73
+ Reweave::REGISTRY.discover_recipes
74
+ recipe_class = require_recipe(recipe_name)
75
+ abort("Recipe not found: #{recipe_name}") unless recipe_class
76
+
77
+ # Parse recipe options from remaining ARGV
78
+ options = {}
79
+ recipe_class.options.each do |name, opt|
80
+ long_name = name.to_s.gsub("_", "-")
81
+ idx = ARGV.index("--#{long_name}")
82
+ if idx
83
+ options[name] = ARGV[idx + 1]
84
+ ARGV.delete_at(idx)
85
+ ARGV.delete_at(idx)
86
+ end
87
+ end
88
+
89
+ recipe = recipe_class.new(**options)
90
+ end
91
+
92
+ common_opts = parse_common_options(ARGV)
93
+
94
+ result = Reweave.run(
95
+ recipe,
96
+ path: common_opts[:path],
97
+ dry_run: common_opts[:dry_run],
98
+ max_cycles: common_opts[:max_cycles] || 10,
99
+ patterns: common_opts[:include] ? [common_opts[:include]] : nil,
100
+ exclude: common_opts[:exclude] ? [common_opts[:exclude]] : nil
101
+ )
102
+
103
+ print_result(result, json: common_opts[:json])
104
+ exit(result.success? ? 0 : 1)
105
+
106
+ when "validate"
107
+ config_path = ARGV.shift
108
+ abort("Usage: reweave validate <config.yml>") unless config_path
109
+
110
+ Reweave::REGISTRY.discover_recipes
111
+ begin
112
+ config = Reweave::Config.load(config_path)
113
+ puts "✓ Config is valid"
114
+ recipe = Reweave::Config.build_recipe(config)
115
+ puts "Recipe: #{recipe.class.name}"
116
+ puts "Display: #{recipe.display_name}"
117
+ exit 0
118
+ rescue Reweave::Config::ValidationError => e
119
+ puts "✗ Validation error: #{e.message}"
120
+ exit 2
121
+ end
122
+
123
+ when "recipes"
124
+ Reweave::REGISTRY.discover_recipes
125
+ puts "Available recipes:"
126
+ Reweave::REGISTRY.names.each do |name|
127
+ recipe_class = Reweave::REGISTRY.get(name)
128
+ puts " #{name} - #{recipe_class.display_name}"
129
+ end
130
+
131
+ when "describe"
132
+ recipe_name = ARGV.shift
133
+ abort("Usage: reweave describe <recipe>") unless recipe_name
134
+
135
+ Reweave::REGISTRY.discover_recipes
136
+ recipe_class = require_recipe(recipe_name)
137
+ abort("Recipe not found: #{recipe_name}") unless recipe_class
138
+ recipe = recipe_class.allocate # Don't initialize with required options
139
+ puts "Name: #{recipe_name}"
140
+ puts "Display: #{recipe.display_name}"
141
+ puts "Description: #{recipe.description}"
142
+ puts "Options:"
143
+ recipe.class.options.each do |name, opt|
144
+ req = opt.required? ? " (required)" : ""
145
+ def_str = opt.default ? " [default: #{opt.default.inspect}]" : ""
146
+ puts " #{name}: #{opt.type}#{req}#{def_str}"
147
+ puts " #{opt.description}" if opt.description
148
+ end
149
+
150
+ when "results"
151
+ # Show last execution results (would need persistence)
152
+ puts "Results command not yet implemented - would require persistent storage"
153
+
154
+ when "roundtrip"
155
+ file = ARGV.shift
156
+ abort("Usage: reweave roundtrip <file.rb>") unless file
157
+
158
+ source = File.read(file)
159
+ result = Reweave.parse(source)
160
+ if result.success?
161
+ puts "✓ Parse successful"
162
+ puts "Diagnostics: #{result.diagnostics.size}"
163
+ else
164
+ puts "✗ Parse failed"
165
+ result.errors.each { |e| puts " #{e[:message]} at #{e[:start_line]}:#{e[:start_column]}" }
166
+ exit 1
167
+ end
168
+
169
+ else
170
+ puts <<~USAGE
171
+ Reweave - Automated Ruby source transformation
172
+
173
+ Commands:
174
+ run <recipe> [options] Execute a recipe
175
+ run --config <file.yml> [options] Execute from YAML config
176
+ validate <config.yml> Validate YAML config
177
+ recipes List available recipes
178
+ describe <recipe> Show recipe details
179
+ results Show last execution results
180
+ roundtrip <file.rb> Test parsing a file
181
+
182
+ Run options:
183
+ --dry-run, -n Dry run mode (no disk writes)
184
+ --path, -p <path> Project path (default: .)
185
+ --include <glob> Include pattern (e.g., "**/*.rb")
186
+ --exclude <glob> Exclude pattern (e.g., "vendor/**/*")
187
+ --max-cycles <n> Max execution cycles (default: 10)
188
+ --json JSON output for automation
189
+ --verbose Detailed logging
190
+
191
+ Examples:
192
+ reweave run RenameMethod --old-name foo --new-name bar --dry-run
193
+ reweave run --config reweave.yml --dry-run
194
+ reweave validate reweave.yml
195
+ reweave recipes
196
+ reweave describe RenameMethod
197
+
198
+ USAGE
199
+ exit 1
200
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Reweave
6
+ module Config
7
+ class ValidationError < StandardError; end
8
+
9
+ class << self
10
+ def load(file_path)
11
+ raise ValidationError, "Config file not found: #{file_path}" unless File.exist?(file_path)
12
+
13
+ config = YAML.safe_load_file(file_path, permitted_classes: [Symbol], aliases: true)
14
+ validate!(config)
15
+ config
16
+ rescue Psych::SyntaxError => e
17
+ raise ValidationError, "Invalid YAML: #{e.message}"
18
+ end
19
+
20
+ def validate!(config)
21
+ unless config.is_a?(Hash)
22
+ raise ValidationError, "Config must be a Hash"
23
+ end
24
+
25
+ validate_recipes(config["recipes"]) if config["recipes"]
26
+ validate_recipe_list(config["recipe_list"]) if config["recipe_list"]
27
+ validate_single_recipe(config) if config["name"]
28
+ end
29
+
30
+ def validate_single_recipe(config)
31
+ name = config["name"]
32
+ unless Reweave::REGISTRY.get(name)
33
+ raise ValidationError, "Unknown recipe: '#{name}' (not registered)"
34
+ end
35
+
36
+ if config["options"]
37
+ validate_options(name, config["options"])
38
+ end
39
+ end
40
+
41
+ def validate_recipes(recipes)
42
+ unless recipes.is_a?(Array)
43
+ raise ValidationError, "'recipes' must be an Array"
44
+ end
45
+
46
+ recipes.each_with_index do |recipe, index|
47
+ validate_recipe(recipe, index)
48
+ end
49
+ end
50
+
51
+ def validate_recipe(recipe, index)
52
+ unless recipe.is_a?(Hash)
53
+ raise ValidationError, "Recipe at index #{index} must be a Hash"
54
+ end
55
+
56
+ unless recipe["name"]
57
+ raise ValidationError, "Recipe at index #{index} must have a 'name'"
58
+ end
59
+
60
+ name = recipe["name"]
61
+ unless Reweave::REGISTRY.get(name)
62
+ raise ValidationError, "Unknown recipe: '#{name}' (not registered)"
63
+ end
64
+
65
+ if recipe["options"]
66
+ validate_options(recipe["name"], recipe["options"])
67
+ end
68
+ end
69
+
70
+ def validate_options(recipe_name, options)
71
+ unless options.is_a?(Hash)
72
+ raise ValidationError, "Options for '#{recipe_name}' must be a Hash"
73
+ end
74
+
75
+ recipe_class = Reweave::REGISTRY.get(recipe_name)
76
+ return unless recipe_class
77
+
78
+ known_options = recipe_class.options.keys
79
+ unknown = options.keys - known_options.map(&:to_s)
80
+ unless unknown.empty?
81
+ raise ValidationError, "Unknown options for '#{recipe_name}': #{unknown.join(", ")}"
82
+ end
83
+ end
84
+
85
+ def validate_recipe_list(recipe_list)
86
+ unless recipe_list.is_a?(Array)
87
+ raise ValidationError, "'recipe_list' must be an Array"
88
+ end
89
+
90
+ recipe_list.each_with_index do |recipe, index|
91
+ validate_recipe(recipe, index)
92
+ end
93
+ end
94
+
95
+ def build_recipe(config)
96
+ Reweave::REGISTRY.discover_recipes
97
+
98
+ if config["recipe_list"]
99
+ # Composite recipe from list
100
+ recipes = config["recipe_list"].map { |r| build_recipe(r) }
101
+ Reweave::CompositeRecipe.new(recipes)
102
+ elsif config["recipes"]
103
+ # Multiple recipes as composite
104
+ recipes = config["recipes"].map { |r| build_recipe(r) }
105
+ Reweave::CompositeRecipe.new(recipes)
106
+ elsif config["name"]
107
+ # Single recipe
108
+ recipe_class = Reweave::REGISTRY.get(config["name"])
109
+ raise ValidationError, "Unknown recipe: '#{config["name"]}'" unless recipe_class
110
+
111
+ options = config["options"]&.transform_keys(&:to_sym) || {}
112
+ recipe_class.new(**options)
113
+ else
114
+ raise ValidationError, "Config must have 'name', 'recipes', or 'recipe_list'"
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reweave
4
+ module Discovery
5
+ class FileDiscoverer
6
+ def self.discover(root, patterns: ["**/*.rb"], exclude: [])
7
+ root = File.expand_path(root)
8
+ all_files = []
9
+
10
+ patterns.each do |pattern|
11
+ Dir.glob(File.join(root, pattern), File::FNM_DOTMATCH).each do |path|
12
+ next unless File.file?(path)
13
+ next if exclude.any? { |ex| File.fnmatch(ex, path, File::FNM_PATHNAME) || File.fnmatch(ex, File.basename(path)) }
14
+ next if path.include?("/.git/")
15
+ all_files << path
16
+ end
17
+ end
18
+
19
+ all_files.uniq.sort
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reweave
4
+ module Editing
5
+ Edit = Data.define(
6
+ :source_id,
7
+ :start_offset,
8
+ :end_offset,
9
+ :replacement,
10
+ :recipe_name
11
+ ) do
12
+ def length
13
+ end_offset - start_offset
14
+ end
15
+
16
+ def insertion?
17
+ start_offset == end_offset
18
+ end
19
+
20
+ def deletion?
21
+ replacement.empty?
22
+ end
23
+
24
+ def replacement?
25
+ !insertion? && !deletion?
26
+ end
27
+
28
+ def overlaps?(other)
29
+ return false unless source_id == other.source_id
30
+ start_offset < other.end_offset && other.start_offset < end_offset
31
+ end
32
+
33
+ def adjacent?(other)
34
+ return false unless source_id == other.source_id
35
+ end_offset == other.start_offset || other.end_offset == start_offset
36
+ end
37
+
38
+ def contains_offset?(offset)
39
+ offset.between?(start_offset, end_offset)
40
+ end
41
+
42
+ def to_s
43
+ type = if insertion?
44
+ "insert"
45
+ else
46
+ deletion? ? "delete" : "replace"
47
+ end
48
+ "#{type} @#{start_offset}-#{end_offset}: #{replacement.inspect}"
49
+ end
50
+ end
51
+ end
52
+ end