aia 0.0.4 → 0.3.0

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: 5737dc3f15dc0372865893efba9c8e7bb6c4c41fc335476b638cb55a5dc4ad17
4
- data.tar.gz: 91545c6a73d8d6f61cbf878f35df375f3e700961d1d70b25bd3cb0aa0cc25251
3
+ metadata.gz: c4d68353a3458a4a3e485acbf09ec6444e63d33ddaedca66a1f48aaf38b31a96
4
+ data.tar.gz: b2d07bde2cb329db6f23ccda5c845b67251f00f5bdfab680406d671a32ee0b32
5
5
  SHA512:
6
- metadata.gz: 7a276b2fdad405245fd29f8aba586504ad2a99cc4c8f3f570af1de58849c1ee2abda2f30c5a72fbd699db37f01b94e79711eb4833495cebeae33c9562d03033f
7
- data.tar.gz: 2c570b4339d3f24b6621378481393994272a0f0317ab4edb2ae9ca79007a81b288cc09eeae0f9326f72892ce742d41e9bbfe180de3a8bb6f652a1fc808d1e62f
6
+ metadata.gz: d27e5190de909b14a71a52f2eea78b8d948de6cbe5c621f3b10e819404d0a9a78087c5da748598b6dfbf8af88ece61382c407d62382eadb062ad0582d5f4b8f9
7
+ data.tar.gz: 6cc9b0ad1d570f0cb994e06af614d4faea07b356303042fa1e1bfe03ed12a62f273824e0240b8bb2cb46a64b6f195dd715b15161a228255f3d2639fc1648e61e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] = 2023-11-23
4
+
5
+ - Matching version to [prompt_manager](https://github.com/prompt_manager) This version allows for the user of history in the entery of values to prompt keywords. KW_HISTORY_MAX is set at 5. Changed CLI enteraction to use historical selection and editing of prior keyword values.
6
+
3
7
  ## [0.1.0] - 2023-11-23
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -1,11 +1,27 @@
1
1
  # AI Assistant (AIA)
2
2
 
3
- **Under Development**
4
-
5
3
  `aia` is a command-line utility that integrates prameterized prompt management with generative AI (gen-AI) execution.
6
4
 
7
5
  Uses the gem "prompt_manager" to manage the prompts sent to the `mods` command-line utility. Uses the command line tools "ripgrep" to search for prompts to send and "fzf" to select the prompts that match the search term.
8
6
 
7
+ **Most Recent Change**
8
+
9
+ v0.3.0 - Matching version to [prompt_manager](https://github.com/prompt_manager) This version allows for the user of history in the entery of values to prompt keywords. KW_HISTORY_MAX is set at 5. Changed CLI enteraction to use historical selection and editing of prior keyword values.
10
+
11
+
12
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
13
+
14
+ ## Table of Contents
15
+
16
+ - [Installation](#installation)
17
+ - [Usage](#usage)
18
+ - [System Environment Variables (envars)](#system-environment-variables-envars)
19
+ - [External CLI Tools Used](#external-cli-tools-used)
20
+ - [Development](#development)
21
+ - [Contributing](#contributing)
22
+ - [License](#license)
23
+
24
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
9
25
 
10
26
 
11
27
  ## Installation
@@ -31,48 +47,120 @@ TODO: don't forget to mention have access token (API keys) setup as envars for t
31
47
 
32
48
  ## Usage
33
49
 
34
- `aia prompt_id [context_file]*`
50
+ ```text
51
+ $ aia --help
52
+
53
+ aia v0.0.5
54
+
55
+ Usage: aia [options] prompt_id [context_file]* [-- external_options+]
56
+
57
+ Options
58
+ -------
59
+
60
+ Edit the Prompt File -e --edit
61
+ default: false
62
+
63
+ Turn On Debugging -d --debug
64
+ default: false
65
+
66
+ Be Verbose -v --verbose
67
+ default: false
68
+
69
+ Print Version --version
70
+ default: false
71
+
72
+ Show Usage -h --help
73
+ default: false
74
+
75
+ Use Fuzzy Matching --fuzzy
76
+ default: false
77
+
78
+ Out FILENAME -o --output --no-output
79
+ default: ./temp.md
35
80
 
36
- `prompt_id` is the basename of the `prompt_id.txt` file that is located in the `$PROMPTS_DIR` directory. There is also a `prompt_id.json` file saved in the same place to hold the last-used values (parameters) for the keywords (if any) found in your prompt file.
81
+ Log FILEPATH -l --log --no-log
82
+ default: $HOME/.prompts/_prompts.log
37
83
 
38
- TODO: consider a config file.
39
- TODO: consider a --no-log option to turn off logging
84
+ Format with Markdown -m --markdown --no-markdown --md --no-md
85
+ default: true
86
+ ```
40
87
 
41
- The `_prompts.log` file is also located in the `$PROMPTS_DIR`
88
+ Turn on `verbose` with `help` to see more usage information that includes system environment variables and external CLI tools that are used.
42
89
 
43
- The default output file is `temp.md` which is written to the current directory from which `aia` was executed.
90
+ ```text
91
+ $ aia --help --verbose
92
+ ```
44
93
 
94
+ ## System Environment Variables (envars)
95
+
96
+ From the verbose help text ...
45
97
 
46
98
  ```text
47
- $ aia -h
48
- Use generative AI with saved parameterized prompts
49
99
 
50
- Usage: aia [options] ...
100
+ System Environment Variables Used
101
+ ---------------------------------
102
+
103
+ The OUTPUT and PROMPT_LOG envars can be overridden
104
+ by cooresponding options on the command line.
105
+
106
+ Name Default Value
107
+ -------------- -------------------------
108
+ PROMPTS_DIR $HOME/.prompts_dir
109
+ AI_CLI_PROGRAM mods
110
+ EDITOR edit
111
+ MODS_MODEL gpt-4-1106-preview
112
+ OUTPUT ./temp.md
113
+ PROMPT_LOG $PROMPTS_DIR/_prompts.log
114
+
115
+ These two are required for access the OpenAI
116
+ services. The have the same value but different
117
+ programs use different envar names.
118
+
119
+ To get an OpenAI access key/token (same thing)
120
+ you must first create an account at OpenAI.
121
+ Here is the link: https://platform.openai.com/docs/overview
122
+
123
+ OPENAI_ACCESS_TOKEN
124
+ OPENAI_API_KEY
125
+ ```
126
+
127
+ ## External CLI Tools Used
128
+
129
+ From the verbose help text ...
130
+
131
+ ```text
132
+ External Tools Used
133
+ -------------------
51
134
 
52
- Where:
135
+ To install the external CLI programs used by aia:
136
+ brew install fzf mods rg
53
137
 
54
- Common Options Are:
55
- -h, --help show this message
56
- -v, --verbose enable verbose mode
57
- -d, --debug enable debug mode
58
- --version print the version: 1.2.0
138
+ fzf
139
+ Command-line fuzzy finder written in Go
140
+ https://github.com/junegunn/fzf
59
141
 
60
- Program Options Are:
61
- -f, --fuzzy Allow fuzzy matching
62
- -o, --output The output file
142
+ mods
143
+ AI on the command-line
144
+ https://github.com/charmbracelet/mods
63
145
 
64
- AI Assistant (aia)
65
- ==================
146
+ rg
147
+ Search tool like grep and The Silver Searcher
148
+ https://github.com/BurntSushi/ripgrep
66
149
 
67
- The AI cli program being used is: mods
150
+ A text editor whose executable is setup in the
151
+ system environment variable 'EDITOR' like this:
68
152
 
69
- The defaul options to mods are:
70
- "-m gpt-4-1106-preview --no-limit -f"
153
+ export EDITOR="subl -w"
71
154
 
72
- You can pass additional CLI options to mods like this:
73
- "aia my options -- options for mods"
74
155
  ```
75
156
 
157
+ ## Shell Completion
158
+
159
+ One of the executables with this gem is `aia_completion.sh` which contains a completion script for hte `aia` such that you specify the first few characters of a prompt ID on the command line and the shell will complete the rest of the ID for you. It works with the `bash` shell but do not know whether it works with the other shells.
160
+
161
+ To set the completion you can execute aia_completion.sh` in your `.bashrc` however, the PROMPTS_DIR environment variable must be set in order for prompt ID to work correctly.
162
+
163
+
76
164
  ## Development
77
165
 
78
166
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/bin/aia CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # aia
2
+ # bin/aia
3
3
 
4
4
  require 'aia'
5
-
6
- # Create an instance of the Main class and run the program
7
- AIA::Main.new.call
5
+ AIA.run
data/lib/aia/cli.rb ADDED
@@ -0,0 +1,179 @@
1
+ # lib/aia/cli.rb
2
+
3
+ module AIA::Cli
4
+ def setup_cli_options(args)
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
+ # TODO: Consider dropping output in favor of always
16
+ # going to STDOUT so user can redirect or pipe somewhere else
17
+ output: [OUTPUT,"-o --output --no-output", "Out FILENAME"],
18
+ log: [PROMPT_LOG,"-l --log --no-log", "Log FILEPATH"],
19
+ markdown?: [true, "-m --markdown --no-markdown --md --no-md", "Format with Markdown"],
20
+ backend: [:mods, "-b --be --backend --no-backend", "Specify the backend prompt resolver"],
21
+ }
22
+
23
+ # Array(String)
24
+ @extra_options = [] # intended for the backend AI processor
25
+
26
+ build_reader_methods # for the @options keys
27
+ process_arguments
28
+ end
29
+
30
+
31
+ def usage
32
+ usage = "\n#{MY_NAME} v#{AIA::VERSION}\n\n"
33
+ usage += "Usage: #{MY_NAME} [options] prompt_id [context_file]* [-- external_options+]\n\n"
34
+ usage += usage_options
35
+ usage += "\n"
36
+ usage += usage_notes if verbose?
37
+
38
+ usage
39
+ end
40
+
41
+
42
+ def usage_options
43
+ options = [
44
+ "Options",
45
+ "-------",
46
+ ""
47
+ ]
48
+
49
+ max_size = @options.values.map{|o| o[2].size}.max + 2
50
+
51
+ @options.values.each do |o|
52
+ pad_size = max_size - o[2].size
53
+ options << o[2] + (" "*pad_size) + o[1]
54
+
55
+ default = o[0]
56
+ default = "./" + default.basename.to_s if o[1].include?('output')
57
+ default = default.is_a?(Pathname) ? "$HOME/" + default.relative_path_from(HOME).to_s : default
58
+
59
+ options << " default: #{default}\n"
60
+ end
61
+
62
+ options.join("\n")
63
+ end
64
+
65
+
66
+ def usage_notes
67
+ <<~EOS
68
+ #{usage_envars}
69
+ #{AIA::ExternalCommands::HELP}
70
+ EOS
71
+ end
72
+
73
+
74
+ def usage_envars
75
+ <<~EOS
76
+ System Environment Variables Used
77
+ ---------------------------------
78
+
79
+ The OUTPUT and PROMPT_LOG envars can be overridden
80
+ by cooresponding options on the command line.
81
+
82
+ Name Default Value
83
+ -------------- -------------------------
84
+ PROMPTS_DIR $HOME/.prompts_dir
85
+ AI_CLI_PROGRAM mods
86
+ EDITOR edit
87
+ MODS_MODEL gpt-4-1106-preview
88
+ OUTPUT ./temp.md
89
+ PROMPT_LOG $PROMPTS_DIR/_prompts.log
90
+
91
+ These two are required for access the OpenAI
92
+ services. The have the same value but different
93
+ programs use different envar names.
94
+
95
+ To get an OpenAI access key/token (same thing)
96
+ you must first create an account at OpenAI.
97
+ Here is the link: https://platform.openai.com/docs/overview
98
+
99
+ OPENAI_ACCESS_TOKEN
100
+ OPENAI_API_KEY
101
+
102
+ EOS
103
+ end
104
+
105
+
106
+ def build_reader_methods
107
+ @options.keys.each do |key|
108
+ define_singleton_method(key) do
109
+ @options[key][0]
110
+ end
111
+ end
112
+ end
113
+
114
+
115
+ def process_arguments
116
+ @options.keys.each do |option|
117
+ check_for option
118
+ end
119
+
120
+ # get the options meant for the backend AI command
121
+ extract_extra_options
122
+
123
+ bad_options = @arguments.select{|a| a.start_with?('-')}
124
+
125
+ unless bad_options.empty?
126
+ puts <<~EOS
127
+
128
+ ERROR: Unknown options: #{bad_options.join(' ')}
129
+
130
+ EOS
131
+
132
+ show_usage
133
+
134
+ exit
135
+ end
136
+ end
137
+
138
+
139
+ def check_for(option_sym)
140
+ boolean = option_sym.to_s.end_with?('?')
141
+ switches = @options[option_sym][1].split
142
+
143
+ switches.each do |switch|
144
+ if @arguments.include?(switch)
145
+ index = @arguments.index(switch)
146
+
147
+ if boolean
148
+ @options[option_sym][0] = switch.include?('-no-') ? false : true
149
+ @arguments.slice!(index,1)
150
+ else
151
+ if switch.include?('-no-')
152
+ @options[option_sym][0] = nil
153
+ @arguments.slice!(index,1)
154
+ else
155
+ @options[option_sym][0] = @arguments[index + 1]
156
+ @arguments.slice!(index,2)
157
+ end
158
+ end
159
+
160
+ break
161
+ end
162
+ end
163
+ end
164
+
165
+
166
+
167
+ def show_usage
168
+ @options[:help?][0] = false
169
+ puts usage
170
+ exit
171
+ end
172
+ alias_method :show_help, :show_usage
173
+
174
+
175
+ def show_version
176
+ puts AIA::VERSION
177
+ exit
178
+ end
179
+ end
@@ -0,0 +1,44 @@
1
+ # lib/aia/configuration.rb
2
+
3
+ HOME = Pathname.new(ENV['HOME'])
4
+ PROMPTS_DIR = Pathname.new(ENV['PROMPTS_DIR'] || (HOME + ".prompts_dir"))
5
+
6
+ AI_CLI_PROGRAM = "mods"
7
+ EDITOR = ENV['EDITOR'] || 'edit'
8
+ MY_NAME = "aia"
9
+ MODS_MODEL = ENV['MODS_MODEL'] || 'gpt-4-1106-preview'
10
+ OUTPUT = Pathname.pwd + "temp.md"
11
+ PROMPT_LOG = PROMPTS_DIR + "_prompts.log"
12
+
13
+
14
+ module AIA::Configuration
15
+ def setup_configuration
16
+ @prompt = nil
17
+
18
+ PromptManager::Prompt.storage_adapter =
19
+ PromptManager::Storage::FileSystemAdapter.config do |config|
20
+ config.prompts_dir = PROMPTS_DIR
21
+ config.prompt_extension = '.txt'
22
+ config.params_extension = '.json'
23
+ config.search_proc = nil
24
+ # TODO: add the rgfzz script for search_proc
25
+ end.new
26
+ end
27
+
28
+
29
+ # Get the additional CLI arguments intended for the
30
+ # backend gen-AI processor.
31
+ def extract_extra_options
32
+ extra_index = @arguments.index('--')
33
+ if extra_index.nil?
34
+ @extra_options = []
35
+ else
36
+ @extra_options = @arguments.slice!(extra_index..-1)[1..]
37
+ end
38
+ end
39
+
40
+
41
+
42
+
43
+
44
+ end
File without changes
@@ -0,0 +1,11 @@
1
+
2
+
3
+
4
+ module AIA
5
+ module External
6
+ end
7
+ end
8
+
9
+ require_relative 'tool'
10
+ include AIA
11
+ include External
@@ -0,0 +1,103 @@
1
+ # lib/aia/external/ag.rb
2
+
3
+ class AIA::External::Ag < AIA::External::Tool
4
+ def initialize
5
+ super
6
+ @role = :search
7
+ @desc = "the_silver_searcher Code-search similar to ack"
8
+ @url = "https://github.com/ggreer/the_silver_searcher"
9
+ end
10
+ end
11
+
12
+ __END__
13
+
14
+ Usage: ag [FILE-TYPE] [OPTIONS] PATTERN [PATH]
15
+
16
+ Recursively search for PATTERN in PATH.
17
+ Like grep or ack, but faster.
18
+
19
+ Example:
20
+ ag -i foo /bar/
21
+
22
+ Output Options:
23
+ --ackmate Print results in AckMate-parseable format
24
+ -A --after [LINES] Print lines after match (Default: 2)
25
+ -B --before [LINES] Print lines before match (Default: 2)
26
+ --[no]break Print newlines between matches in different files
27
+ (Enabled by default)
28
+ -c --count Only print the number of matches in each file.
29
+ (This often differs from the number of matching lines)
30
+ --[no]color Print color codes in results (Enabled by default)
31
+ --color-line-number Color codes for line numbers (Default: 1;33)
32
+ --color-match Color codes for result match numbers (Default: 30;43)
33
+ --color-path Color codes for path names (Default: 1;32)
34
+ --column Print column numbers in results
35
+ --[no]filename Print file names (Enabled unless searching a single file)
36
+ -H --[no]heading Print file names before each file's matches
37
+ (Enabled by default)
38
+ -C --context [LINES] Print lines before and after matches (Default: 2)
39
+ --[no]group Same as --[no]break --[no]heading
40
+ -g --filename-pattern PATTERN
41
+ Print filenames matching PATTERN
42
+ -l --files-with-matches Only print filenames that contain matches
43
+ (don't print the matching lines)
44
+ -L --files-without-matches
45
+ Only print filenames that don't contain matches
46
+ --print-all-files Print headings for all files searched, even those that
47
+ don't contain matches
48
+ --[no]numbers Print line numbers. Default is to omit line numbers
49
+ when searching streams
50
+ -o --only-matching Prints only the matching part of the lines
51
+ --print-long-lines Print matches on very long lines (Default: >2k characters)
52
+ --passthrough When searching a stream, print all lines even if they
53
+ don't match
54
+ --silent Suppress all log messages, including errors
55
+ --stats Print stats (files scanned, time taken, etc.)
56
+ --stats-only Print stats and nothing else.
57
+ (Same as --count when searching a single file)
58
+ --vimgrep Print results like vim's :vimgrep /pattern/g would
59
+ (it reports every match on the line)
60
+ -0 --null --print0 Separate filenames with null (for 'xargs -0')
61
+
62
+ Search Options:
63
+ -a --all-types Search all files (doesn't include hidden files
64
+ or patterns from ignore files)
65
+ -D --debug Ridiculous debugging (probably not useful)
66
+ --depth NUM Search up to NUM directories deep (Default: 25)
67
+ -f --follow Follow symlinks
68
+ -F --fixed-strings Alias for --literal for compatibility with grep
69
+ -G --file-search-regex PATTERN Limit search to filenames matching PATTERN
70
+ --hidden Search hidden files (obeys .*ignore files)
71
+ -i --ignore-case Match case insensitively
72
+ --ignore PATTERN Ignore files/directories matching PATTERN
73
+ (literal file/directory names also allowed)
74
+ --ignore-dir NAME Alias for --ignore for compatibility with ack.
75
+ -m --max-count NUM Skip the rest of a file after NUM matches (Default: 10,000)
76
+ --one-device Don't follow links to other devices.
77
+ -p --path-to-ignore STRING
78
+ Use .ignore file at STRING
79
+ -Q --literal Don't parse PATTERN as a regular expression
80
+ -s --case-sensitive Match case sensitively
81
+ -S --smart-case Match case insensitively unless PATTERN contains
82
+ uppercase characters (Enabled by default)
83
+ --search-binary Search binary files for matches
84
+ -t --all-text Search all text files (doesn't include hidden files)
85
+ -u --unrestricted Search all files (ignore .ignore, .gitignore, etc.;
86
+ searches binary and hidden files as well)
87
+ -U --skip-vcs-ignores Ignore VCS ignore files
88
+ (.gitignore, .hgignore; still obey .ignore)
89
+ -v --invert-match
90
+ -w --word-regexp Only match whole words
91
+ -W --width NUM Truncate match lines after NUM characters
92
+ -z --search-zip Search contents of compressed (e.g., gzip) files
93
+
94
+ File Types:
95
+ The search can be restricted to certain types of files. Example:
96
+ ag --html needle
97
+ - Searches for 'needle' in files with suffix .htm, .html, .shtml or .xhtml.
98
+
99
+ For a list of supported file types run:
100
+ ag --list-file-types
101
+
102
+ ag was originally created by Geoff Greer. More information (and the latest release)
103
+ can be found at http://geoff.greer.fm/ag