aia 0.0.5 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,37 +0,0 @@
1
- # bin/aia_completion.sh
2
- # Setup a prompt completion for use with
3
- # aia (a Ruby program) AI Assistant
4
- #
5
-
6
- if [ -z "$PROMPTS_DIR" ]; then
7
- echo "Error: PROMPTS_DIR environment variable is not set"
8
- exit 1
9
- fi
10
-
11
- # SMELL: Is this BASH-only or will it work with other shells?
12
-
13
- # Function to generate prompt completions for aia
14
-
15
- _aia_completion() {
16
- # The current word being completed
17
- local cur_word="${COMP_WORDS[COMP_CWORD]}"
18
-
19
- # Store the previous directory to return to it later
20
- local initial_pwd=$(pwd)
21
-
22
- # Change directory to the prompts directory
23
- cd $PROMPTS_DIR
24
-
25
- # Generate a list of relative paths from the ~/.prompts directory (without .txt extension)
26
- local files=($(find . -name "*.txt" -type f | sed 's|^\./||' | sed 's/\.txt$//'))
27
-
28
- # Change back to the initial directory
29
- cd "$initial_pwd"
30
-
31
- # Generate possible matches and store them in the COMPREPLY array
32
- COMPREPLY=($(compgen -W "${files[*]}" -- "$cur_word"))
33
- }
34
-
35
-
36
- # Register the completion function for the aip command
37
- complete -F _aia_completion aia
@@ -1,116 +0,0 @@
1
- # lib/aia/external_commands.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
- module AIA::ExternalCommands
8
- TOOLS = {
9
- 'fzf' => [ 'Command-line fuzzy finder written in Go',
10
- 'https://github.com/junegunn/fzf'],
11
-
12
- 'mods' => [ 'AI on the command-line',
13
- 'https://github.com/charmbracelet/mods'],
14
-
15
- 'rg' => [ 'Search tool like grep and The Silver Searcher',
16
- 'https://github.com/BurntSushi/ripgrep']
17
- }
18
-
19
-
20
- HELP = <<~EOS
21
- External Tools Used
22
- -------------------
23
-
24
- To install the external CLI programs used by aia:
25
- brew install #{TOOLS.keys.join(' ')}
26
-
27
- #{TOOLS.to_a.map{|t| t.join("\n ") }.join("\n\n")}
28
-
29
- A text editor whose executable is setup in the
30
- system environment variable 'EDITOR' like this:
31
-
32
- export EDITOR="#{ENV['EDITOR']}"
33
-
34
- EOS
35
-
36
-
37
- # Setup the AI CLI program with necessary variables
38
- def setup_external_programs
39
- verify_external_tools
40
-
41
- ai_default_opts = "-m #{MODS_MODEL} --no-limit "
42
- ai_default_opts += "-f " if markdown?
43
- @ai_options = ai_default_opts.dup
44
-
45
-
46
- @ai_options += @extra_options.join(' ')
47
-
48
- @ai_command = "#{AI_CLI_PROGRAM} #{@ai_options} "
49
- end
50
-
51
-
52
- # Check if the external tools are present on the system
53
- def verify_external_tools
54
- missing_tools = []
55
-
56
- TOOLS.each do |tool, url|
57
- path = `which #{tool}`.chomp
58
- if path.empty? || !File.executable?(path)
59
- missing_tools << { name: tool, url: url }
60
- end
61
- end
62
-
63
- if missing_tools.any?
64
- puts format_missing_tools_response(missing_tools)
65
- end
66
- end
67
-
68
-
69
- def format_missing_tools_response(missing_tools)
70
- response = <<~EOS
71
-
72
- WARNING: #{MY_NAME} makes use of a few external CLI tools.
73
- #{MY_NAME} may not respond as designed without these.
74
-
75
- The following tools are missing on your system:
76
-
77
- EOS
78
-
79
- missing_tools.each do |tool|
80
- response << " #{tool[:name]}: install from #{tool[:url]}\n"
81
- end
82
-
83
- response
84
- end
85
-
86
-
87
- # Build the command to interact with the AI CLI program
88
- def build_command
89
- command = @ai_command + %Q["#{@prompt.to_s}"]
90
-
91
- @arguments.each do |input_file|
92
- file_path = Pathname.new(input_file)
93
- abort("File does not exist: #{input_file}") unless file_path.exist?
94
- command += " < #{input_file}"
95
- end
96
-
97
- command
98
- end
99
-
100
-
101
- # Execute the command and log the results
102
- def send_prompt_to_external_command
103
- command = build_command
104
-
105
- puts command if verbose?
106
- @result = `#{command}`
107
-
108
- if output.nil?
109
- puts @result
110
- else
111
- output.write @result
112
- end
113
-
114
- @result
115
- end
116
- end