aia 0.3.4 → 0.3.19
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 +12 -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 +29 -15
- data/lib/aia/prompt_processing.rb +208 -4
- data/lib/aia/tools/editor.rb +50 -0
- data/lib/aia/{external → tools}/mods.rb +69 -10
- data/lib/aia/{external → tools}/sgpt.rb +2 -2
- data/lib/aia/{external → tools}/subl.rb +23 -5
- data/lib/aia/tools/vim.rb +91 -0
- data/lib/aia/{external/tool.rb → tools.rb} +28 -24
- data/lib/aia/version.rb +5 -1
- data/lib/aia.rb +17 -3
- data/main.just +56 -0
- data/man/aia.1 +134 -0
- data/man/aia.1.md +107 -0
- metadata +72 -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.rb +0 -259
- data/lib/aia/external_two.rb +0 -43
data/lib/aia/external.rb
DELETED
@@ -1,259 +0,0 @@
|
|
1
|
-
# lib/aia/external.rb
|
2
|
-
|
3
|
-
# TODO: move stuff associated with the CLI options for
|
4
|
-
# external commands to this module.
|
5
|
-
# Is the EDITOR considered an external command? Yes.
|
6
|
-
|
7
|
-
=begin
|
8
|
-
|
9
|
-
There are at least 4 processes handled by external tools:
|
10
|
-
|
11
|
-
search .......... default PromptManager::Prompt or search_proc
|
12
|
-
review/select ... using fzf either exact or fuzzy
|
13
|
-
edit ............ ENV['EDITOR']
|
14
|
-
execute ......... mods or sgpt or ???
|
15
|
-
with different models / settings
|
16
|
-
|
17
|
-
sgpt is the executable for "shell-gpt" a python project
|
18
|
-
|
19
|
-
=end
|
20
|
-
|
21
|
-
module AIA::External
|
22
|
-
class Mods; end
|
23
|
-
class Fzf; end
|
24
|
-
class Rg; end
|
25
|
-
class Editor; end
|
26
|
-
end
|
27
|
-
|
28
|
-
module AIA::External
|
29
|
-
TOOLS = {
|
30
|
-
'fzf' => [ 'Command-line fuzzy finder written in Go',
|
31
|
-
'https://github.com/junegunn/fzf'],
|
32
|
-
|
33
|
-
'mods' => [ 'AI on the command-line',
|
34
|
-
'https://github.com/charmbracelet/mods'],
|
35
|
-
|
36
|
-
'rg' => [ 'Search tool like grep and The Silver Searcher',
|
37
|
-
'https://github.com/BurntSushi/ripgrep']
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
HELP = <<~EOS
|
42
|
-
External Tools Used
|
43
|
-
-------------------
|
44
|
-
|
45
|
-
To install the external CLI programs used by aia:
|
46
|
-
brew install #{TOOLS.keys.join(' ')}
|
47
|
-
|
48
|
-
#{TOOLS.to_a.map{|t| t.join("\n ") }.join("\n\n")}
|
49
|
-
|
50
|
-
A text editor whose executable is setup in the
|
51
|
-
system environment variable 'EDITOR' like this:
|
52
|
-
|
53
|
-
export EDITOR="#{ENV['EDITOR']}"
|
54
|
-
|
55
|
-
EOS
|
56
|
-
|
57
|
-
|
58
|
-
# Setup the AI CLI program with necessary variables
|
59
|
-
def setup_external_programs
|
60
|
-
verify_external_tools
|
61
|
-
|
62
|
-
ai_default_opts = "-m #{MODS_MODEL} --no-limit "
|
63
|
-
ai_default_opts += "-f " if markdown?
|
64
|
-
@ai_options = ai_default_opts.dup
|
65
|
-
|
66
|
-
|
67
|
-
@ai_options += @extra_options.join(' ')
|
68
|
-
|
69
|
-
@ai_command = "#{AI_CLI_PROGRAM} #{@ai_options} "
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
# Check if the external tools are present on the system
|
74
|
-
def verify_external_tools
|
75
|
-
missing_tools = []
|
76
|
-
|
77
|
-
TOOLS.each do |tool, url|
|
78
|
-
path = `which #{tool}`.chomp
|
79
|
-
if path.empty? || !File.executable?(path)
|
80
|
-
missing_tools << { name: tool, url: url }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
if missing_tools.any?
|
85
|
-
puts format_missing_tools_response(missing_tools)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
def format_missing_tools_response(missing_tools)
|
91
|
-
response = <<~EOS
|
92
|
-
|
93
|
-
WARNING: #{MY_NAME} makes use of a few external CLI tools.
|
94
|
-
#{MY_NAME} may not respond as designed without these.
|
95
|
-
|
96
|
-
The following tools are missing on your system:
|
97
|
-
|
98
|
-
EOS
|
99
|
-
|
100
|
-
missing_tools.each do |tool|
|
101
|
-
response << " #{tool[:name]}: install from #{tool[:url]}\n"
|
102
|
-
end
|
103
|
-
|
104
|
-
response
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
# Build the command to interact with the AI CLI program
|
109
|
-
def build_command
|
110
|
-
command = @ai_command + %Q["#{@prompt.to_s}"]
|
111
|
-
|
112
|
-
@arguments.each do |input_file|
|
113
|
-
file_path = Pathname.new(input_file)
|
114
|
-
abort("File does not exist: #{input_file}") unless file_path.exist?
|
115
|
-
command += " < #{input_file}"
|
116
|
-
end
|
117
|
-
|
118
|
-
command
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
# Execute the command and log the results
|
123
|
-
def send_prompt_to_external_command
|
124
|
-
command = build_command
|
125
|
-
|
126
|
-
puts command if verbose?
|
127
|
-
@result = `#{command}`
|
128
|
-
|
129
|
-
if output.nil?
|
130
|
-
puts @result
|
131
|
-
else
|
132
|
-
output.write @result
|
133
|
-
end
|
134
|
-
|
135
|
-
@result
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
__END__
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
MODS_MODEL = ENV['MODS_MODEL'] || 'gpt-4-1106-preview'
|
145
|
-
|
146
|
-
AI_CLI_PROGRAM = "mods"
|
147
|
-
ai_default_opts = "-m #{MODS_MODEL} --no-limit -f"
|
148
|
-
ai_options = ai_default_opts.dup
|
149
|
-
|
150
|
-
extra_inx = ARGV.index('--')
|
151
|
-
|
152
|
-
if extra_inx
|
153
|
-
ai_options += " " + ARGV[extra_inx+1..].join(' ')
|
154
|
-
ARGV.pop(ARGV.size - extra_inx)
|
155
|
-
end
|
156
|
-
|
157
|
-
AI_COMMAND = "#{AI_CLI_PROGRAM} #{ai_options} "
|
158
|
-
EDITOR = ENV['EDITOR']
|
159
|
-
PROMPT_DIR = HOME + ".prompts"
|
160
|
-
PROMPT_LOG = PROMPT_DIR + "_prompts.log"
|
161
|
-
PROMPT_EXTNAME = ".txt"
|
162
|
-
DEFAULTS_EXTNAME = ".json"
|
163
|
-
# SEARCH_COMMAND = "ag -l"
|
164
|
-
KEYWORD_REGEX = /(\[[A-Z _|]+\])/
|
165
|
-
|
166
|
-
AVAILABLE_PROMPTS = PROMPT_DIR
|
167
|
-
.children
|
168
|
-
.select{|c| PROMPT_EXTNAME == c.extname}
|
169
|
-
.map{|c| c.basename.to_s.split('.')[0]}
|
170
|
-
|
171
|
-
AVAILABLE_PROMPTS_HELP = AVAILABLE_PROMPTS
|
172
|
-
.map{|c| " * " + c}
|
173
|
-
.join("\n")
|
174
|
-
|
175
|
-
|
176
|
-
AI_CLI_PROGRAM_HELP = `#{AI_CLI_PROGRAM} --help`
|
177
|
-
|
178
|
-
HELP = <<EOHELP
|
179
|
-
AI CLI Program
|
180
|
-
==============
|
181
|
-
|
182
|
-
The AI cli program being used is: #{AI_CLI_PROGRAM}
|
183
|
-
|
184
|
-
The defaul options to #{AI_CLI_PROGRAM} are:
|
185
|
-
"#{ai_default_opts}"
|
186
|
-
|
187
|
-
You can pass additional CLI options to #{AI_CLI_PROGRAM} like this:
|
188
|
-
"#{my_name} my options -- options for #{AI_CLI_PROGRAM}"
|
189
|
-
|
190
|
-
#{AI_CLI_PROGRAM_HELP}
|
191
|
-
|
192
|
-
EOHELP
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
AG_COMMAND = "ag --file-search-regex '\.txt$' e" # searching for the letter "e"
|
197
|
-
CD_COMMAND = "cd #{PROMPT_DIR}"
|
198
|
-
FIND_COMMAND = "find . -name '*.txt'"
|
199
|
-
|
200
|
-
FZF_OPTIONS = [
|
201
|
-
"--tabstop=2", # 2 soaces for a tab
|
202
|
-
"--header='Prompt contents below'",
|
203
|
-
"--header-first",
|
204
|
-
"--prompt='Search term: '",
|
205
|
-
'--delimiter :',
|
206
|
-
"--preview 'ww {1}'", # ww comes from the word_wrap gem
|
207
|
-
"--preview-window=down:50%:wrap"
|
208
|
-
].join(' ')
|
209
|
-
|
210
|
-
FZF_OPTIONS += " --exact" unless fuzzy?
|
211
|
-
|
212
|
-
FZF_COMMAND = "#{CD_COMMAND} ; #{FIND_COMMAND} | fzf #{FZF_OPTIONS}"
|
213
|
-
AG_FZF_COMMAND = "#{CD_COMMAND} ; #{AG_COMMAND} | fzf #{FZF_OPTIONS}"
|
214
|
-
|
215
|
-
# use `ag` ti build a list of text lines from each prompt
|
216
|
-
# use `fzf` to search through that list to select a prompt file
|
217
|
-
|
218
|
-
def ag_fzf = `#{AG_FZF_COMMAND}`.split(':')&.first&.strip&.gsub('.txt','')
|
219
|
-
|
220
|
-
|
221
|
-
if configatron.prompt.empty?
|
222
|
-
unless first_argument_is_a_prompt?
|
223
|
-
configatron.prompt = ag_fzf
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
###############################################
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
#!/usr/bin/env bash
|
232
|
-
# ~/scripts/ripfzfsubl
|
233
|
-
#
|
234
|
-
# Uses Sublime Text (subl) as the text editor
|
235
|
-
#
|
236
|
-
# brew install bat ripgrep fzf
|
237
|
-
#
|
238
|
-
# bat Clone of cat(1) with syntax highlighting and Git integration
|
239
|
-
# |__ https://github.com/sharkdp/bat
|
240
|
-
#
|
241
|
-
# ripgrep Search tool like grep and The Silver Searcher
|
242
|
-
# |__ https://github.com/BurntSushi/ripgrep
|
243
|
-
#
|
244
|
-
# fzf Command-line fuzzy finder written in Go
|
245
|
-
# |__ https://github.com/junegunn/fzf
|
246
|
-
#
|
247
|
-
#
|
248
|
-
# 1. Search for text in files using Ripgrep
|
249
|
-
# 2. Interactively narrow down the list using fzf
|
250
|
-
# 3. Open the file in Sublime Text Editor
|
251
|
-
|
252
|
-
rg --color=always --line-number --no-heading --smart-case "${*:-}" |
|
253
|
-
fzf --ansi \
|
254
|
-
--color "hl:-1:underline,hl+:-1:underline:reverse" \
|
255
|
-
--delimiter : \
|
256
|
-
--preview 'bat --color=always {1} --highlight-line {2}' \
|
257
|
-
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
|
258
|
-
--bind 'enter:become(subl {1}:{2})'
|
259
|
-
|
data/lib/aia/external_two.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# lib/aia/external_two.rb
|
2
|
-
#
|
3
|
-
# Maybe something like this ...
|
4
|
-
#
|
5
|
-
# or a class structure based upon function where the external
|
6
|
-
# tool and its default options can be injected.
|
7
|
-
#
|
8
|
-
module AIA::External
|
9
|
-
EDITOR = ENV['EDITOR']
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
# Usage example:
|
15
|
-
|
16
|
-
# Verify and install tools if needed
|
17
|
-
mods = AIA::External::Mods.new
|
18
|
-
fzf = AIA::External::Fzf.new
|
19
|
-
rg = AIA::External::Rg.new
|
20
|
-
tools = [mods, fzf, rg]
|
21
|
-
AIA::External.verify_tools(tools)
|
22
|
-
|
23
|
-
# Build command for Mods tool with extra_options
|
24
|
-
extra_options = ['--some-extra-option']
|
25
|
-
mods_command = mods.command(extra_options)
|
26
|
-
puts "Mods command: #{mods_command}"
|
27
|
-
|
28
|
-
# Open a file with the system editor
|
29
|
-
AIA::External::Editor.open('path/to/file.txt')
|
30
|
-
|
31
|
-
# Search and select a file using Fzf tool
|
32
|
-
fzf_options = {
|
33
|
-
prompt_dir: 'path/to/prompts',
|
34
|
-
fuzzy: true
|
35
|
-
}
|
36
|
-
fzf_command = fzf.command(fzf_options)
|
37
|
-
puts "Fzf command: #{fzf_command}"
|
38
|
-
|
39
|
-
# Use Rg tool to search within files
|
40
|
-
search_term = 'search_query'
|
41
|
-
rg_command = rg.command(search_term, fzf_options: fzf.options)
|
42
|
-
puts "Rg command: #{rg_command}"
|
43
|
-
|