aia 0.3.4 → 0.3.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.semver +6 -0
- data/CHANGELOG.md +16 -0
- data/README.md +165 -55
- data/Rakefile +2 -0
- data/justfile +167 -0
- data/lib/aia/cli.rb +228 -115
- data/lib/aia/config.rb +7 -0
- data/lib/aia/logging.rb +49 -12
- data/lib/aia/main.rb +46 -15
- data/lib/aia/prompt_processing.rb +208 -4
- data/lib/aia/tools/editor.rb +52 -0
- data/lib/aia/{external → tools}/mods.rb +108 -12
- data/lib/aia/{external → tools}/sgpt.rb +12 -7
- data/lib/aia/{external → tools}/subl.rb +32 -11
- data/lib/aia/tools/temp.md +97 -0
- data/lib/aia/tools/vim.rb +93 -0
- data/lib/aia/tools.rb +50 -0
- data/lib/aia/version.rb +5 -1
- data/lib/aia.rb +18 -3
- data/main.just +56 -0
- data/man/aia.1 +134 -0
- data/man/aia.1.md +107 -0
- metadata +87 -18
- data/lib/aia/configuration.rb +0 -39
- data/lib/aia/external/,keep +0 -0
- data/lib/aia/external/.irbrc +0 -11
- data/lib/aia/external/ag.rb +0 -103
- data/lib/aia/external/bat.rb +0 -189
- data/lib/aia/external/fzf.rb +0 -147
- data/lib/aia/external/glow.rb +0 -37
- data/lib/aia/external/rg.rb +0 -1163
- data/lib/aia/external/tool.rb +0 -73
- data/lib/aia/external.rb +0 -259
- data/lib/aia/external_two.rb +0 -43
data/lib/aia/cli.rb
CHANGED
@@ -1,150 +1,207 @@
|
|
1
1
|
# lib/aia/cli.rb
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
@arguments = args
|
6
|
-
# TODO: consider a fixed config file: ~/,aia
|
7
|
-
@options = {
|
8
|
-
# Value
|
9
|
-
edit?: [false, "-e --edit", "Edit the Prompt File"],
|
10
|
-
debug?: [false, "-d --debug", "Turn On Debugging"],
|
11
|
-
verbose?: [false, "-v --verbose", "Be Verbose"],
|
12
|
-
version?: [false, "--version", "Print Version"],
|
13
|
-
help?: [false, "-h --help", "Show Usage"],
|
14
|
-
fuzzy?: [false, "--fuzzy", "Use Fuzzy Matching"],
|
15
|
-
completion: [nil, "--completion", "Show completion script for bash|zsh|fish"],
|
16
|
-
# TODO: Consider dropping output in favor of always
|
17
|
-
# going to STDOUT so user can redirect or pipe somewhere else
|
18
|
-
output: [OUTPUT,"-o --output --no-output", "Out FILENAME"],
|
19
|
-
log: [PROMPT_LOG,"-l --log --no-log", "Log FILEPATH"],
|
20
|
-
markdown?: [true, "-m --markdown --no-markdown --md --no-md", "Format with Markdown"],
|
21
|
-
backend: [:mods, "-b --be --backend --no-backend", "Specify the backend prompt resolver"],
|
22
|
-
}
|
23
|
-
|
24
|
-
# Array(String)
|
25
|
-
@extra_options = [] # intended for the backend AI processor
|
3
|
+
HOME = Pathname.new(ENV['HOME'])
|
4
|
+
MY_NAME = 'aia'
|
26
5
|
|
27
|
-
build_reader_methods # for the @options keys
|
28
|
-
process_arguments
|
29
|
-
end
|
30
6
|
|
7
|
+
require 'hashie'
|
8
|
+
require 'pathname'
|
9
|
+
require 'yaml'
|
10
|
+
require 'toml-rb'
|
31
11
|
|
32
|
-
def usage
|
33
|
-
usage = "\n#{MY_NAME} v#{AIA::VERSION}\n\n"
|
34
|
-
usage += "Usage: #{MY_NAME} [options] prompt_id [context_file]* [-- external_options+]\n\n"
|
35
|
-
usage += usage_options
|
36
|
-
usage += usage_options_details
|
37
|
-
usage += "\n"
|
38
|
-
usage += usage_notes if verbose?
|
39
|
-
|
40
|
-
usage
|
41
|
-
end
|
42
|
-
|
43
12
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
13
|
+
class AIA::Cli
|
14
|
+
CF_FORMATS = %w[yml yaml toml]
|
15
|
+
ENV_PREFIX = self.name.split('::').first.upcase + "_"
|
16
|
+
MAN_PAGE_PATH = Pathname.new(__dir__) + '../../man/aia.1'
|
17
|
+
|
18
|
+
|
19
|
+
def initialize(args)
|
20
|
+
args = args.split(' ') if args.is_a? String
|
21
|
+
|
22
|
+
setup_options_with_defaults(args) # 1. defaults
|
23
|
+
load_env_options # 2. over-ride with envars
|
24
|
+
process_command_line_arguments # 3. over-ride with command line options
|
25
|
+
|
26
|
+
# 4. over-ride everything with config file
|
27
|
+
load_config_file unless AIA.config.config_file.nil?
|
50
28
|
|
51
|
-
|
29
|
+
convert_to_pathname_objects
|
52
30
|
|
53
|
-
|
54
|
-
|
55
|
-
|
31
|
+
setup_prompt_manager
|
32
|
+
|
33
|
+
execute_immediate_commands
|
34
|
+
end
|
56
35
|
|
57
|
-
default = o[0]
|
58
|
-
default = "./" + default.basename.to_s if o[1].include?('output')
|
59
|
-
default = default.is_a?(Pathname) ? "$HOME/" + default.relative_path_from(HOME).to_s : default
|
60
36
|
|
61
|
-
|
37
|
+
def convert_pathname_objects!(converting_to_pathname: true)
|
38
|
+
path_keys = AIA.config.keys.grep(/_(dir|file)\z/)
|
39
|
+
path_keys.each do |key|
|
40
|
+
case AIA.config[key]
|
41
|
+
when String
|
42
|
+
AIA.config[key] = string_to_pathname(AIA.config[key])
|
43
|
+
when Pathname
|
44
|
+
AIA.config[key] = pathname_to_string(AIA.config[key]) unless converting_to_pathname
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def string_to_pathname(string)
|
51
|
+
['~/', '$HOME/'].each do |prefix|
|
52
|
+
if string.start_with? prefix
|
53
|
+
string = string.gsub(prefix, HOME.to_s+'/')
|
54
|
+
break
|
55
|
+
end
|
62
56
|
end
|
63
57
|
|
64
|
-
|
58
|
+
pathname = Pathname.new(string)
|
59
|
+
pathname.relative? ? Pathname.pwd + pathname : pathname
|
65
60
|
end
|
66
61
|
|
67
62
|
|
68
|
-
def
|
69
|
-
|
63
|
+
def pathname_to_string(pathname)
|
64
|
+
pathname.to_s
|
65
|
+
end
|
70
66
|
|
71
|
-
Details
|
72
|
-
-------
|
73
67
|
|
74
|
-
|
68
|
+
def convert_to_pathname_objects
|
69
|
+
convert_pathname_objects!(converting_to_pathname: true)
|
70
|
+
end
|
75
71
|
|
76
|
-
Use --completion bash|zsh|fish to show a script
|
77
|
-
that will add prompt ID completion to your desired shell.
|
78
|
-
You must copy the output from this option into a
|
79
|
-
place where the function will be executed for
|
80
|
-
your shell.
|
81
72
|
|
82
|
-
|
73
|
+
def convert_from_pathname_objects
|
74
|
+
convert_pathname_objects!(converting_to_pathname: false)
|
83
75
|
end
|
84
76
|
|
85
77
|
|
86
|
-
def
|
87
|
-
|
78
|
+
def load_env_options
|
79
|
+
known_keys = @options.keys
|
88
80
|
|
89
|
-
|
90
|
-
|
81
|
+
keys = ENV.keys
|
82
|
+
.select{|k| k.start_with?(ENV_PREFIX)}
|
83
|
+
.map{|k| k.gsub(ENV_PREFIX,'').downcase.to_sym}
|
91
84
|
|
92
|
-
|
85
|
+
keys.each do |key|
|
86
|
+
envar_key = ENV_PREFIX + key.to_s.upcase
|
87
|
+
if known_keys.include?(key)
|
88
|
+
AIA.config[key] = ENV[envar_key]
|
89
|
+
elsif known_keys.include?("#{key}?".to_sym)
|
90
|
+
key = "#{key}?".to_sym
|
91
|
+
AIA.config[key] = %w[true t yes yea y 1].include?(ENV[envar_key].strip.downcase) ? true : false
|
92
|
+
else
|
93
|
+
# This is a new config key
|
94
|
+
AIA.config[key] = ENV[envar_key]
|
95
|
+
end
|
96
|
+
end
|
93
97
|
end
|
94
98
|
|
95
99
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
+
def load_config_file
|
101
|
+
AIA.config.config_file = Pathname.new(AIA.config.config_file)
|
102
|
+
if AIA.config.config_file.exist?
|
103
|
+
AIA.config.merge! parse_config_file
|
104
|
+
else
|
105
|
+
abort "Config file does not exist: #{AIA.config.config_file}"
|
106
|
+
end
|
107
|
+
end
|
100
108
|
|
101
|
-
The OUTPUT and PROMPT_LOG envars can be overridden
|
102
|
-
by cooresponding options on the command line.
|
103
109
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
def setup_options_with_defaults(args)
|
111
|
+
# TODO: This structure if flat; consider making it
|
112
|
+
# at least two levels totake advantage of
|
113
|
+
# YAML and TOML capabilities to isolate
|
114
|
+
# common options within a section.
|
115
|
+
#
|
116
|
+
@options = {
|
117
|
+
# Default
|
118
|
+
# Key Value, switches
|
119
|
+
arguments: [args], # NOTE: after process, prompt_id and context_files will be left
|
120
|
+
extra: [''], # SMELL: should be nil?
|
121
|
+
#
|
122
|
+
model: ["gpt-4-1106-preview", "--llm --model"],
|
123
|
+
#
|
124
|
+
dump: [nil, "--dump"],
|
125
|
+
completion: [nil, "--completion"],
|
126
|
+
#
|
127
|
+
edit?: [false, "-e --edit"],
|
128
|
+
debug?: [false, "-d --debug"],
|
129
|
+
verbose?: [false, "-v --verbose"],
|
130
|
+
version?: [false, "--version"],
|
131
|
+
help?: [false, "-h --help"],
|
132
|
+
fuzzy?: [false, "-f --fuzzy"],
|
133
|
+
search: [nil, "-s --search"],
|
134
|
+
markdown?: [true, "-m --markdown --no-markdown --md --no-md"],
|
135
|
+
#
|
136
|
+
# TODO: May have to process the
|
137
|
+
# "~" character and replace it with HOME
|
138
|
+
#
|
139
|
+
# TODO: Consider using standard suffix of _dif and _file
|
140
|
+
# to signal Pathname objects fo validation
|
141
|
+
#
|
142
|
+
config_file:[nil, "-c --config"],
|
143
|
+
prompts_dir:["~/.prompts", "-p --prompts"],
|
144
|
+
output_file:["temp.md", "-o --output --no-output"],
|
145
|
+
log_file: ["~/.prompts/_prompts.log", "-l --log --no-log"],
|
146
|
+
#
|
147
|
+
backend: ['mods', "-b --be --backend --no-backend"],
|
148
|
+
}
|
149
|
+
|
150
|
+
AIA.config = AIA::Config.new(@options.transform_values { |values| values.first })
|
151
|
+
end
|
112
152
|
|
113
|
-
These two are required for access the OpenAI
|
114
|
-
services. The have the same value but different
|
115
|
-
programs use different envar names.
|
116
153
|
|
117
|
-
|
118
|
-
|
119
|
-
|
154
|
+
def arguments
|
155
|
+
AIA.config.arguments
|
156
|
+
end
|
120
157
|
|
121
|
-
OPENAI_ACCESS_TOKEN
|
122
|
-
OPENAI_API_KEY
|
123
158
|
|
124
|
-
|
159
|
+
def execute_immediate_commands
|
160
|
+
show_usage if AIA.config.help?
|
161
|
+
show_version if AIA.config.version?
|
162
|
+
dump_config_file if AIA.config.dump
|
163
|
+
show_completion if AIA.config.completion
|
125
164
|
end
|
126
165
|
|
127
166
|
|
128
|
-
def
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
167
|
+
def dump_config_file
|
168
|
+
a_hash = prepare_config_as_hash
|
169
|
+
|
170
|
+
case AIA.config.dump.downcase
|
171
|
+
when 'yml', 'yaml'
|
172
|
+
puts YAML.dump(a_hash)
|
173
|
+
when 'toml'
|
174
|
+
puts TomlRB.dump(a_hash)
|
175
|
+
else
|
176
|
+
abort "Invalid config file format request. Only #{CF_FORMATS.join(', ')} are supported."
|
133
177
|
end
|
178
|
+
|
179
|
+
exit
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
def prepare_config_as_hash
|
184
|
+
convert_from_pathname_objects
|
185
|
+
|
186
|
+
a_hash = AIA.config.to_h
|
187
|
+
a_hash['dump'] = nil
|
188
|
+
|
189
|
+
a_hash.delete('arguments')
|
190
|
+
a_hash.delete('config_file')
|
191
|
+
|
192
|
+
a_hash
|
134
193
|
end
|
135
194
|
|
136
195
|
|
137
|
-
def
|
196
|
+
def process_command_line_arguments
|
138
197
|
@options.keys.each do |option|
|
139
198
|
check_for option
|
140
199
|
end
|
141
200
|
|
142
|
-
show_completion unless @options[:completion].first.nil?
|
143
|
-
|
144
201
|
# get the options meant for the backend AI command
|
145
202
|
extract_extra_options
|
146
203
|
|
147
|
-
bad_options =
|
204
|
+
bad_options = arguments.select{|a| a.start_with?('-')}
|
148
205
|
|
149
206
|
unless bad_options.empty?
|
150
207
|
puts <<~EOS
|
@@ -161,23 +218,26 @@ module AIA::Cli
|
|
161
218
|
|
162
219
|
|
163
220
|
def check_for(option_sym)
|
164
|
-
|
165
|
-
|
221
|
+
# sometimes @options has stuff that is not a command line option
|
222
|
+
return if @options[option_sym].nil? || @options[option_sym].size <= 1
|
223
|
+
|
224
|
+
boolean = option_sym.to_s.end_with?('?')
|
225
|
+
switches = @options[option_sym][1].split
|
166
226
|
|
167
227
|
switches.each do |switch|
|
168
|
-
if
|
169
|
-
index =
|
228
|
+
if arguments.include?(switch)
|
229
|
+
index = arguments.index(switch)
|
170
230
|
|
171
231
|
if boolean
|
172
|
-
|
173
|
-
|
232
|
+
AIA.config[option_sym] = switch.include?('-no-') ? false : true
|
233
|
+
arguments.slice!(index,1)
|
174
234
|
else
|
175
235
|
if switch.include?('-no-')
|
176
|
-
|
177
|
-
|
236
|
+
AIA.config[option_sym] = switch.include?('output') ? STDOUT : nil
|
237
|
+
arguments.slice!(index,1)
|
178
238
|
else
|
179
|
-
|
180
|
-
|
239
|
+
AIA.config[option_sym] = arguments[index + 1]
|
240
|
+
arguments.slice!(index,2)
|
181
241
|
end
|
182
242
|
end
|
183
243
|
|
@@ -186,17 +246,33 @@ module AIA::Cli
|
|
186
246
|
end
|
187
247
|
end
|
188
248
|
|
189
|
-
|
249
|
+
# aia usage is maintained in a man page
|
190
250
|
def show_usage
|
191
251
|
@options[:help?][0] = false
|
192
|
-
puts
|
252
|
+
puts `man #{MAN_PAGE_PATH}`
|
253
|
+
show_verbose_usage if AIA.config.verbose?
|
193
254
|
exit
|
194
255
|
end
|
195
256
|
alias_method :show_help, :show_usage
|
196
257
|
|
197
258
|
|
259
|
+
def show_verbose_usage
|
260
|
+
puts <<~EOS
|
261
|
+
|
262
|
+
======================================
|
263
|
+
== Currently selected Backend: #{AIA.config.backend} ==
|
264
|
+
======================================
|
265
|
+
|
266
|
+
EOS
|
267
|
+
puts `mods --help` if "mods" == AIA.config.backend
|
268
|
+
puts `sgpt --help` if "sgpt" == AIA.config.backend
|
269
|
+
puts
|
270
|
+
end
|
271
|
+
# alias_method :show_verbose_help, :show_verbose_usage
|
272
|
+
|
273
|
+
|
198
274
|
def show_completion
|
199
|
-
shell =
|
275
|
+
shell = AIA.config.completion
|
200
276
|
script = Pathname.new(__dir__) + "aia_completion.#{shell}"
|
201
277
|
|
202
278
|
if script.exist?
|
@@ -206,12 +282,11 @@ module AIA::Cli
|
|
206
282
|
else
|
207
283
|
STDERR.puts <<~EOS
|
208
284
|
|
209
|
-
|
285
|
+
ERROR: The shell '#{shell}' is not supported.
|
210
286
|
|
211
287
|
EOS
|
212
288
|
end
|
213
289
|
|
214
|
-
|
215
290
|
exit
|
216
291
|
end
|
217
292
|
|
@@ -220,4 +295,42 @@ module AIA::Cli
|
|
220
295
|
puts AIA::VERSION
|
221
296
|
exit
|
222
297
|
end
|
298
|
+
|
299
|
+
|
300
|
+
def setup_prompt_manager
|
301
|
+
@prompt = nil
|
302
|
+
|
303
|
+
PromptManager::Prompt.storage_adapter =
|
304
|
+
PromptManager::Storage::FileSystemAdapter.config do |config|
|
305
|
+
config.prompts_dir = AIA.config.prompts_dir
|
306
|
+
config.prompt_extension = '.txt'
|
307
|
+
config.params_extension = '.json'
|
308
|
+
config.search_proc = nil
|
309
|
+
# TODO: add the rgfzf script for search_proc
|
310
|
+
end.new
|
311
|
+
end
|
312
|
+
|
313
|
+
|
314
|
+
# Get the additional CLI arguments intended for the
|
315
|
+
# backend gen-AI processor.
|
316
|
+
def extract_extra_options
|
317
|
+
extra_index = arguments.index('--')
|
318
|
+
|
319
|
+
if extra_index
|
320
|
+
AIA.config.extra = arguments.slice!(extra_index..-1)[1..].join(' ')
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
def parse_config_file
|
326
|
+
case AIA.config.config_file.extname.downcase
|
327
|
+
when '.yaml', '.yml'
|
328
|
+
YAML.safe_load(AIA.config.config_file.read)
|
329
|
+
when '.toml'
|
330
|
+
TomlRB.parse(AIA.config.config_file.read)
|
331
|
+
else
|
332
|
+
abort "Unsupported config file type: #{AIA.config.config_file.extname}"
|
333
|
+
end
|
334
|
+
end
|
223
335
|
end
|
336
|
+
|
data/lib/aia/config.rb
ADDED
data/lib/aia/logging.rb
CHANGED
@@ -1,22 +1,59 @@
|
|
1
1
|
# lib/aia/logging.rb
|
2
2
|
|
3
|
-
|
4
|
-
def log_result
|
5
|
-
return if log.nil?
|
6
|
-
|
7
|
-
f = File.open(log, "ab")
|
3
|
+
require 'logger'
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
== #{Time.now}
|
12
|
-
== #{@prompt.path}
|
5
|
+
class AIA::Logging
|
6
|
+
attr_accessor :logger
|
13
7
|
|
14
|
-
|
15
|
-
|
8
|
+
def initialize(log_file_path)
|
9
|
+
@logger = if log_file_path
|
10
|
+
Logger.new(
|
11
|
+
log_file_path, # path/to/file
|
12
|
+
'weekly', # rotation interval
|
13
|
+
'a' # append to existing file
|
14
|
+
)
|
15
|
+
else
|
16
|
+
Logger.new(STDOUT) # Fall back to standard output if path is nil or invalid
|
17
|
+
end
|
18
|
+
|
19
|
+
configure_logger
|
20
|
+
end
|
21
|
+
|
22
|
+
def prompt_result(prompt, result)
|
23
|
+
logger.info( <<~EOS
|
24
|
+
PROMPT ID #{prompt.id}
|
25
|
+
PATH: #{prompt.path}
|
26
|
+
KEYWORDS: #{prompt.keywords.join(', ')}
|
27
|
+
|
28
|
+
#{prompt.to_s}
|
16
29
|
|
17
30
|
RESULT:
|
18
|
-
#{
|
31
|
+
#{result}
|
32
|
+
|
19
33
|
|
20
34
|
EOS
|
35
|
+
)
|
36
|
+
rescue StandardError => e
|
37
|
+
logger.error("Failed to log the result. Error: #{e.message}")
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def debug(msg) = logger.debug(msg)
|
42
|
+
def info(msg) = logger.info(msg)
|
43
|
+
def warn(msg) = logger.warn(msg)
|
44
|
+
def error(msg) = logger.error(msg)
|
45
|
+
def fatal(msg) = logger.fatal(msg)
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def configure_logger
|
50
|
+
@logger.formatter = proc do |severity, datetime, _progname, msg|
|
51
|
+
formatted_datetime = datetime.strftime("%Y-%m-%d %H:%M:%S")
|
52
|
+
"[#{formatted_datetime}] #{severity}: #{msg}\n"
|
53
|
+
end
|
54
|
+
@logger.level = Logger::DEBUG
|
21
55
|
end
|
22
56
|
end
|
57
|
+
|
58
|
+
|
59
|
+
|
data/lib/aia/main.rb
CHANGED
@@ -2,38 +2,69 @@
|
|
2
2
|
|
3
3
|
module AIA ; end
|
4
4
|
|
5
|
-
require_relative '
|
6
|
-
|
5
|
+
require_relative 'config'
|
7
6
|
require_relative 'cli'
|
8
7
|
require_relative 'prompt_processing'
|
9
|
-
require_relative 'external'
|
10
8
|
require_relative 'logging'
|
9
|
+
require_relative 'tools'
|
11
10
|
|
12
11
|
# Everything is being handled within the context
|
13
12
|
# of a single class.
|
14
13
|
|
15
14
|
class AIA::Main
|
16
|
-
include AIA::Configuration
|
17
|
-
include AIA::Cli
|
18
15
|
include AIA::PromptProcessing
|
19
|
-
include AIA::External
|
20
|
-
include AIA::Logging
|
21
16
|
|
17
|
+
attr_accessor :logger, :tools
|
22
18
|
|
23
19
|
def initialize(args= ARGV)
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
AIA::Cli.new(args)
|
21
|
+
|
22
|
+
@logger = AIA::Logging.new(AIA.config.log_file)
|
23
|
+
AIA::Tools.load_tools
|
24
|
+
|
25
|
+
# TODO: still should verify that the tools are ion the $PATH
|
26
|
+
# tools.class.verify_tools
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
30
|
def call
|
31
|
-
show_usage if help?
|
32
|
-
show_version if version?
|
33
|
-
|
34
31
|
get_prompt
|
35
32
|
process_prompt
|
36
|
-
|
37
|
-
|
33
|
+
|
34
|
+
# send_prompt_to_external_command
|
35
|
+
|
36
|
+
# TODO: the context_files left in the @arguments array
|
37
|
+
# should be verified BEFORE asking the user for a
|
38
|
+
# prompt keyword or process the prompt. Do not
|
39
|
+
# want invalid files to make it this far.
|
40
|
+
|
41
|
+
found = AIA::Tools
|
42
|
+
.search_for(
|
43
|
+
name: AIA.config.backend,
|
44
|
+
role: :backend
|
45
|
+
)
|
46
|
+
|
47
|
+
if found.empty?
|
48
|
+
abort "There are no :backend tools named #{AIA.config.backend}"
|
49
|
+
end
|
50
|
+
|
51
|
+
if found.size > 1
|
52
|
+
abort "There are #{found.size} :backend tools with the name #{AIAA.config.backend}"
|
53
|
+
end
|
54
|
+
|
55
|
+
backend_klass = found.first.klass
|
56
|
+
|
57
|
+
abort "backend not found: #{AIA.config.backend}" if backend_klass.nil?
|
58
|
+
|
59
|
+
backend = backend_klass.new(
|
60
|
+
text: @prompt.to_s,
|
61
|
+
files: AIA.config.arguments # FIXME: want validated context files
|
62
|
+
)
|
63
|
+
|
64
|
+
result = backend.run
|
65
|
+
|
66
|
+
AIA.config.output_file.write result
|
67
|
+
|
68
|
+
logger.prompt_result(@prompt, result)
|
38
69
|
end
|
39
70
|
end
|