ai_refactor 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa9421b9791dda3c02b930e63d0fa7bd3dc587d121a0b3748a0f9d8c649f98a3
4
- data.tar.gz: a5cb385968939847ebb1ceb1d663b1926e410fce0571fa2ab7463440347c0f50
3
+ metadata.gz: aae248c6a2c5342ea8990e2a672b455c48ec79645e8d88eb20f9afc1af9e7cce
4
+ data.tar.gz: f86584d15b6467600be12797e4f34bf4ce4545ad6be3bbaef8f9ce62817dd66f
5
5
  SHA512:
6
- metadata.gz: 6ff997f0533fe95da7f0361789d88b4a73ecd8fbd82a1f54179fbce3b6a3b466c40330ae615a00f850e549212fe2463ba60ca4467cc0d9f65bbd6679f326dff1
7
- data.tar.gz: 5898b17ebaa96c24a89cae1ff741a53d3afbb7a6c4844f52a271ddfecc1ebc1923026324601cb98e56b5aed0d673bba5d583d388a7a936e4cc86b272e1858bd8
6
+ metadata.gz: a4d1aa38dc497acd25038229da1fe3e46bcbb4dd26cf33770f2bfe1a8a44a48c656023a2b9342a0b81c9fb620ecc4bc28dba215ef2225da8e5e22b13a8d73d92
7
+ data.tar.gz: e1a7e38d44b83b81da06dcb684e8ce61532fe37818c1e4c41f14451923cd9ad9c3f78092fba5b0fe65e316c1fe75681bf34b81501d2f99694a6ceb85826cede3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ai_refactor (0.3.0)
4
+ ai_refactor (0.3.1)
5
5
  colorize (< 2.0)
6
6
  open3 (< 2.0)
7
7
  ruby-openai (>= 3.4.0, < 5.0)
data/README.md CHANGED
@@ -11,8 +11,9 @@ This is based on the assumption that the LLM AIs are pretty good at identifying
11
11
 
12
12
  Currently available:
13
13
 
14
- - `generic`
15
- - `rspec_to_minitest_rails`
14
+ - `rspec_to_minitest_rails`: convert RSpec specs to minitest tests in Rails apps
15
+ - `generic`: provide your own prompt for the AI and run against the input files
16
+
16
17
 
17
18
  ### `rspec_to_minitest_rails`
18
19
 
@@ -47,7 +48,20 @@ Done processing all files!
47
48
 
48
49
  Applies the refactor specified by prompting the AI with the user supplied prompt. You must supply a prompt file with the `-p` option.
49
50
 
50
- The output is written to `stdout`.
51
+ The output is written to `stdout`, or to a file with the `--output` option. If `--output` is used without a value it overwrites the input.
52
+
53
+ You can also output to a file using a template, `--output-template` to determine the output file name given a template string:
54
+
55
+ The template is used to create the output name, where the it can have substitutions, '[FILE]', '[NAME]', '[DIR]', '[REFACTOR]' & '[EXT]'.
56
+
57
+ Eg `--output-template "[DIR]/[NAME]_[REFACTOR][EXT]"`
58
+
59
+ eg for the input `my_dir/my_class.rb`
60
+ - `[FILE]`: `my_class.rb`
61
+ - `[NAME]`: `my_class`
62
+ - `[DIR]`: `my_dir`
63
+ - `[REFACTOR]`: `generic`
64
+ - `[EXT]`: `.rb`
51
65
 
52
66
  ## Installation
53
67
 
@@ -66,7 +80,7 @@ See `ai_refactor --help` for more information.
66
80
  ```
67
81
  Usage: ai_refactor REFACTOR_TYPE INPUT_FILE_OR_DIR [options]
68
82
 
69
- Where REFACTOR_TYPE is one of: ["generic", "rspec_to_minitest_rails", "minitest_to_rspec"]
83
+ Where REFACTOR_TYPE is one of: ["rspec_to_minitest_rails", "generic"]
70
84
 
71
85
  -p, --prompt PROMPT_FILE Specify path to a text file that contains the ChatGPT 'system' prompt.
72
86
  -c, --continue [MAX_MESSAGES] If ChatGPT stops generating due to the maximum token count being reached, continue to generate more messages, until a stop condition or MAX_MESSAGES. MAX_MESSAGES defaults to 3
@@ -77,6 +91,10 @@ Where REFACTOR_TYPE is one of: ["generic", "rspec_to_minitest_rails", "minitest_
77
91
  -v, --verbose Show extra output and progress info
78
92
  -d, --debug Show debugging output to help diagnose issues
79
93
  -h, --help Prints this help
94
+
95
+ For refactor type 'generic':
96
+ --output [FILE] Write output to file instead of stdout. If no path provided will overwrite input file (will prompt to overwrite existing files)
97
+ --output-template TEMPLATE Write outputs to files instead of stdout. The template is used to create the output name, where the it can have substitutions, '[FILE]', '[NAME]', '[DIR]', '[REFACTOR]' & '[EXT]'. Eg `[DIR]/[NAME]_[REFACTOR][EXT]` (will prompt to overwrite existing files)
80
98
  ```
81
99
 
82
100
 
@@ -33,7 +33,14 @@ module AIRefactor
33
33
  end
34
34
 
35
35
  def prompt_file_path
36
- self.class.prompt_file_path
36
+ file = if options && options[:prompt_file_path]&.length&.positive?
37
+ options[:prompt_file_path]
38
+ else
39
+ File.join(File.dirname(File.expand_path(__FILE__)), "refactors", "prompts", "#{refactor_name}.md")
40
+ end
41
+ file.tap do |prompt|
42
+ raise "No prompt file '#{prompt}' found for #{refactor_name}" unless File.exist?(prompt)
43
+ end
37
44
  end
38
45
 
39
46
  def ai_client
@@ -54,17 +61,6 @@ module AIRefactor
54
61
  .tr("-", "_")
55
62
  .downcase
56
63
  end
57
-
58
- def prompt_file_path
59
- file = if options[:prompt_file_path]&.length&.positive?
60
- options[:prompt_file_path]
61
- else
62
- File.join(File.dirname(File.expand_path(__FILE__)), "prompts", "#{refactor_name}.md")
63
- end
64
- file.tap do |prompt|
65
- raise "No prompt file '#{prompt}' found for #{refactor_name}" unless File.exist?(prompt)
66
- end
67
- end
68
64
  end
69
65
  end
70
66
  end
@@ -91,10 +91,6 @@ module AIRefactor
91
91
  end
92
92
 
93
93
  class << self
94
- def prompt_file_path
95
- raise "Generic refactor requires prompt file to be user specified."
96
- end
97
-
98
94
  def command_line_options
99
95
  [
100
96
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AIRefactor
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai_refactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou