aia 0.5.1 → 0.5.3

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: be8cb1e68dc5f180c5a75b87ff6519ccda00a7e82a5da524577648d83f2de56a
4
- data.tar.gz: b16fc5cf5e15ee1942da68b832f82308a2cd037d3374d8a55bdbe2289be1b030
3
+ metadata.gz: 872817d33ce07dce0b81526206b55de4800df41adc7b31a295c0d690f677ff58
4
+ data.tar.gz: f95bdf3845fec419a8b0e56a0c2075e2b1cbab79342538eeb32acb4dc255f8c1
5
5
  SHA512:
6
- metadata.gz: fa3136515303b071abe2866a48af9702047d117d004b6666150445133ebfa0ebb4c0aa1e86ebc3ea7e023ab6eed255a6a98938c7bf9bbb8c01a9f524130a87f4
7
- data.tar.gz: 33d4e8aa6df5e3b3a3b7e5e5811af67e01be18498ce3818dbdd4a863b495132f07fec1333d6273953132931b82852c6a435654fdac6d4aef57e14cd7f2f3ff81
6
+ metadata.gz: 04fc7614ec13ba847e66def37dda93cdfbe8bd0f19425083339276c7bfa5f1ecc214684d0cb9fcb479fddb7fda2cd818ac74fd5498083af3452f8df4f8442a29
7
+ data.tar.gz: 03d5adfdc25ac89cd29b752dd8a2af1c3d6876cad6206471ff9ae1c13e251ea8ee2b2c1038bb64f28febd3f977a375bbe03868b5b3b686a4c35b621e3216a2e1
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 5
4
- :patch: 1
4
+ :patch: 3
5
5
  :special: ''
6
6
  :metadata: ''
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.3] 2024-01-14
4
+ - adding ability to render markdown to the terminal using the "glow" CLI utility
5
+
6
+ ## [0.5.2] 2024-01-13
7
+ - wrap response when its going to the terminal
8
+
3
9
  ## [0.5.1] 2024-01-12
4
10
  - removed a wicked puts "loaded" statement
5
11
  - fixed missed code when the options were changed to --out_file and --log_file
data/README.md CHANGED
@@ -5,6 +5,10 @@
5
5
  It leverages the `prompt_manager` gem to manage prompts for the `mods` and `sgpt` CLI utilities. It utilizes "ripgrep" for searching for prompt files. It uses `fzf` for prompt selection based on a search term and fuzzy matching.
6
6
 
7
7
  **Most Recent Change**: Refer to the [Changelog](CHANGELOG.md)
8
+ v0.5.3
9
+ - `--render` will render markdown formatted content to the terminal using the `glow` CLI utility.
10
+ - fixes to some terminal UI stuff like AI response is not being wrapped to the terminal width to make for easier reading.
11
+ - fixed the completion functions to use the correct $AIA_PROMPTS_DIR envar
8
12
 
9
13
  v0.5.0 - Breaking changes:
10
14
  - `--config` is now `--config_file`
@@ -125,6 +129,9 @@ OPTIONS
125
129
  --model NAME
126
130
  Name of the LLM model to use - default is gpt-4-1106-preview
127
131
 
132
+ --render
133
+ Render markdown to the terminal using the external tool “glow” - default: false
134
+
128
135
  --speak
129
136
  Simple implementation. Uses the “say” command to speak the response. Fun with
130
137
  --chat
@@ -251,6 +258,22 @@ SEE ALSO
251
258
  text, and more, using simple commands. Streamline your workflow and enhance
252
259
  productivity with this powerful and user-friendly CLI tool.
253
260
 
261
+ • fzf <https://github.com/junegunn/fzf>
262
+ fzf is a general-purpose command-line fuzzy finder. It’s an interactive
263
+ Unix filter for command-line that can be used with any list; files, command
264
+ history, processes, hostnames, bookmarks, git commits, etc.
265
+
266
+ • ripgrep <https://github.com/BurntSushi/ripgrep>
267
+ Search tool like grep and The Silver Searcher. It is a line-oriented search
268
+ tool that recursively searches a directory tree for a regex pattern. By
269
+ default, ripgrep will respect gitignore rules and automatically skip hidden
270
+ files/directories and binary files. (To disable all automatic filtering by
271
+ default, use rg -uuu.) ripgrep has first class support on Windows, macOS and
272
+ Linux, with binary downloads available for every release.
273
+
274
+ • glow <https://github.com/charmbracelet/glow>
275
+ Render markdown on the CLI
276
+
254
277
  AUTHOR
255
278
  Dewayne VanHoozer <dvanhoozer@gmail.com>
256
279
 
@@ -402,31 +425,32 @@ When this prompt is processed, `aia` will ask you for a value for the keyword "R
402
425
 
403
426
  ## External CLI Tools Used
404
427
 
405
- ```text
406
- External Tools Used
407
- -------------------
408
-
409
428
  To install the external CLI programs used by aia:
410
- brew install fzf mods rg
429
+
430
+ brew install fzf mods rg glow
411
431
 
412
432
  fzf
413
433
  Command-line fuzzy finder written in Go
414
- https://github.com/junegunn/fzf
434
+ [https://github.com/junegunn/fzf](https://github.com/junegunn/fzf)
415
435
 
416
436
  mods
417
437
  AI on the command-line
418
- https://github.com/charmbracelet/mods
438
+ [https://github.com/charmbracelet/mods](https://github.com/charmbracelet/mods)
419
439
 
420
440
  rg
421
441
  Search tool like grep and The Silver Searcher
422
- https://github.com/BurntSushi/ripgrep
442
+ [https://github.com/BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep)
443
+
444
+ glow
445
+ Render markdown on the CLI
446
+ [https://github.com/charmbracelet/glow](https://github.com/charmbracelet/glow)
423
447
 
424
448
  A text editor whose executable is setup in the
425
449
  system environment variable 'EDITOR' like this:
426
450
 
427
- export EDITOR="subl -w"
451
+ export EDITOR="subl -w"
452
+
428
453
 
429
- ```
430
454
 
431
455
  ## Shell Completion
432
456
 
data/justfile CHANGED
@@ -112,6 +112,7 @@ mods_delete_all:
112
112
  module_repo := "/Users/dewayne/sandbox/git_repos/repo.just"
113
113
  module_gem := "/Users/dewayne/sandbox/git_repos/gem.just"
114
114
  module_version := "/Users/dewayne/just_modules/version.just"
115
+ module_git := "/Users/dewayne/just_modules/git.just"
115
116
 
116
117
 
117
118
  # Install Locally
@@ -185,3 +186,9 @@ alias inc := bump
185
186
  @version what='' args='':
186
187
  just -d . -f {{module_version}} {{what}} {{args}}
187
188
 
189
+
190
+
191
+ # Module git
192
+ @git what='' args='':
193
+ just -d . -f {{module_git}} {{what}} {{args}}
194
+
data/lib/aia/cli.rb CHANGED
@@ -125,18 +125,19 @@ class AIA::Cli
125
125
  dump: [nil, "--dump"],
126
126
  completion: [nil, "--completion"],
127
127
  #
128
+ chat?: [false, "--chat"],
129
+ debug?: [false, "-d --debug"],
128
130
  edit?: [false, "-e --edit"],
129
- shell?: [false, "--shell"],
130
131
  erb?: [false, "--erb"],
131
- debug?: [false, "-d --debug"],
132
- verbose?: [false, "-v --verbose"],
133
- version?: [false, "--version"],
134
- help?: [false, "-h --help"],
135
132
  fuzzy?: [false, "-f --fuzzy"],
133
+ help?: [false, "-h --help"],
136
134
  markdown?: [true, "-m --markdown --no-markdown --md --no-md"],
137
- chat?: [false, "--chat"],
138
- terse?: [false, "--terse"],
135
+ render?: [false, "--render"],
136
+ shell?: [false, "--shell"],
139
137
  speak?: [false, "--speak"],
138
+ terse?: [false, "--terse"],
139
+ verbose?: [false, "-v --verbose"],
140
+ version?: [false, "--version"],
140
141
  #
141
142
  role: ['', "-r --role"],
142
143
  #
data/lib/aia/main.rb CHANGED
@@ -56,6 +56,12 @@ class AIA::Main
56
56
 
57
57
  # Function to prompt the user with a question using reline
58
58
  def ask_question_with_reline(prompt)
59
+ if prompt.start_with?("\n")
60
+ puts
61
+ puts
62
+ prompt = prompt[1..]
63
+ end
64
+
59
65
  answer = Reline.readline(prompt)
60
66
  Reline::HISTORY.push(answer) unless answer.nil? || Reline::HISTORY.to_a.include?(answer)
61
67
  answer
@@ -106,14 +112,10 @@ class AIA::Main
106
112
  files: AIA.config.arguments # FIXME: want validated context files
107
113
  )
108
114
 
109
-
110
- result = backend.run
111
-
112
- AIA.config.out_file.write result
115
+ result = get_and_display_result(the_prompt)
113
116
 
114
117
  logger.prompt_result(@prompt, result)
115
118
 
116
-
117
119
  if AIA.config.chat?
118
120
  setup_reline_history
119
121
  speak result
@@ -122,34 +124,75 @@ class AIA::Main
122
124
  end
123
125
 
124
126
 
125
- def lets_chat
127
+ def get_and_display_result(the_prompt_text)
128
+ backend.text = the_prompt_text
129
+ result = backend.run
130
+
131
+ AIA.config.out_file.write "\nResponse:\n"
132
+
133
+ if STDOUT == AIA.config.out_file
134
+ if AIA.config.render?
135
+ AIA::Glow.new(content: result).run
136
+ else
137
+ result = result.wrap(indent: 2)
138
+ AIA.config.out_file.write result
139
+ end
140
+ else
141
+ AIA.config.out_file.write result
142
+ if AIA.config.render?
143
+ AIA::Glow.new(file_path: AIA.config.out_file).run
144
+ end
145
+ end
146
+
147
+ result
148
+ end
149
+
150
+
151
+ def log_the_follow_up(the_prompt_text, result)
152
+ logger.info "Follow Up:\n#{the_prompt_text}"
153
+ logger.info "Response:\n#{result}"
154
+ end
155
+
156
+
157
+ def add_continue_option
126
158
  if 'mods' == AIA.config.backend
127
- AIA.config.extra += " -C"
159
+ continue_option = " -C"
160
+ AIA.config.extra += continue_option unless AIA.config.extra.include?(continue_option)
128
161
  end
162
+ end
163
+
164
+
165
+ def insert_terse_phrase(a_string)
166
+ if AIA.config.terse?
167
+ a_string.prepend "Be terse in your response. "
168
+ end
169
+
170
+ a_string
171
+ end
172
+
173
+
174
+ def lets_chat
175
+ add_continue_option
176
+
177
+ the_prompt_text = ask_question_with_reline("\nFollow Up: ")
129
178
 
130
- backend.text = ask_question_with_reline("\nFollow Up: ")
131
-
132
- until backend.text.empty?
133
- if AIA.config.terse?
134
- backend.text.prepend "Be terse in your response. "
135
- end
136
-
137
- logger.info "Follow Up: #{backend.text}"
138
- response = backend.run
179
+ until the_prompt_text.empty?
180
+ the_prompt_text = insert_terse_phrase(the_prompt_text)
139
181
 
140
- speak response
182
+ result = get_and_display_result(the_prompt_text)
183
+
184
+ log_the_follow_up(the_prompt_text, result)
185
+
186
+ speak result
187
+
141
188
 
142
- puts "\nResponse: #{response}"
143
- logger.info "Response: #{backend.run}"
144
-
145
189
  # TODO: Allow user to enter a directive; loop
146
190
  # until answer is not a directive
147
191
  #
148
192
  # while !directive do
149
- backend.text = ask_question_with_reline("\nFollow Up: ")
150
193
 
151
- speak backend.text
152
-
194
+ the_prompt_text = ask_question_with_reline("\nFollow Up: ")
195
+
153
196
  # execute the directive
154
197
  # end
155
198
  end
data/lib/aia/prompt.rb CHANGED
@@ -150,6 +150,12 @@ class AIA::Prompt
150
150
 
151
151
  # Function to prompt the user with a question using reline
152
152
  def ask_question_with_reline(prompt)
153
+ if prompt.start_with?("\n")
154
+ puts
155
+ puts
156
+ prompt = prompt[1..]
157
+ end
158
+
153
159
  answer = Reline.readline(prompt)
154
160
  Reline::HISTORY.push(answer) unless answer.nil? || Reline::HISTORY.to_a.include?(answer)
155
161
  answer
@@ -178,7 +184,7 @@ class AIA::Prompt
178
184
  if default&.empty?
179
185
  user_prompt = "\n-=> "
180
186
  else
181
- user_prompt = "\n(#{default}) -=>"
187
+ user_prompt = "\n(#{default}) -=> "
182
188
  end
183
189
 
184
190
  a_string = ask_question_with_reline(user_prompt)
@@ -0,0 +1,90 @@
1
+ # aia/lib/aia/tools/glow.rb
2
+
3
+ require 'tempfile'
4
+ require 'tty-screen'
5
+ require 'shellwords'
6
+
7
+
8
+ =begin
9
+
10
+ This class supports two use cases:
11
+ 1) rendering markdown from an existing file
12
+ 2) rendering markdown from a String object via a temporary file
13
+
14
+ In both cases a String object is created and returned that contains the
15
+ rendered version of the content so that it can be written to STDOUT
16
+ by the caller.
17
+
18
+ =end
19
+
20
+ class AIA::Glow < AIA::Tools
21
+
22
+ meta(
23
+ name: 'glow',
24
+ role: :markdown_renderer,
25
+ desc: "A markdown renderer utility",
26
+ url: "https://github.com/charmbracelet/glow",
27
+ install: "brew install glow",
28
+ )
29
+
30
+ DEFAULT_PARAMETERS = "--width #{TTY::Screen.width-2}" # Magic: -2 just because I want it
31
+
32
+ attr_accessor :content, :file_path
33
+
34
+
35
+ def initialize(content: nil, file_path: nil)
36
+ @content = content
37
+ @file_path = file_path
38
+ end
39
+
40
+
41
+ def build_command(file_path)
42
+ "#{self.class.meta[:name]} #{DEFAULT_PARAMETERS} #{Shellwords.escape(file_path)}"
43
+ end
44
+
45
+
46
+ def run
47
+ return unless content || file_path
48
+
49
+ if @file_path && File.exist?(@file_path)
50
+ command = build_command(@file_path)
51
+ system(command)
52
+ else
53
+ Tempfile.create(['glow', '.md']) do |file|
54
+ file.write(@content)
55
+ file.close
56
+ command = build_command(file.path)
57
+ system(command)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ __END__
64
+
65
+ $ glow --help
66
+
67
+ Render markdown on the CLI, with pizzazz!
68
+
69
+ Usage:
70
+ glow [SOURCE|DIR] [flags]
71
+ glow [command]
72
+
73
+ Available Commands:
74
+ completion Generate the autocompletion script for the specified shell
75
+ config Edit the glow config file
76
+ help Help about any command
77
+ stash Stash a markdown
78
+
79
+ Flags:
80
+ -a, --all show system files and directories (TUI-mode only)
81
+ --config string config file (default /Users/dewayne/Library/Preferences/glow/glow.yml)
82
+ -h, --help help for glow
83
+ -l, --local show local files only; no network (TUI-mode only)
84
+ -p, --pager display with pager
85
+ -s, --style string style name or JSON path (default "auto")
86
+ -v, --version version for glow
87
+ -w, --width uint word-wrap at width
88
+
89
+ Use "glow [command] --help" for more information about a command.
90
+
data/main.just CHANGED
@@ -14,6 +14,7 @@ with ~/.justfile
14
14
  module repo /Users/dewayne/sandbox/git_repos/repo.just
15
15
  module gem /Users/dewayne/sandbox/git_repos/gem.just
16
16
  module version /Users/dewayne/just_modules/version.just
17
+ module git /Users/dewayne/just_modules/git.just
17
18
 
18
19
 
19
20
  # Install Locally
data/man/aia.1 CHANGED
@@ -41,6 +41,9 @@ If dynamic prompt content using \[Do](\.\.\.) wasn\[cq]t enough here is ERB\. E
41
41
  \fB\-\-model\fR \fINAME\fP
42
42
  Name of the LLM model to use \- default is gpt\-4\-1106\-preview
43
43
  .TP
44
+ \fB\-\-render\fR
45
+ Render markdown to the terminal using the external tool \[lq]glow\[rq] \- default: false
46
+ .TP
44
47
  \fB\-\-speak\fR
45
48
  Simple implementation\. Uses the \[lq]say\[rq] command to speak the response\. Fun with \-\-chat
46
49
  .TP
@@ -147,6 +150,21 @@ sgpt
147
150
  .UR https:\[sl]\[sl]github\.com\[sl]tbckr\[sl]sgpt
148
151
  .UE
149
152
  (aka shell\-gpt) is a powerful command\-line interface (CLI) tool designed for seamless interaction with OpenAI models directly from your terminal\. Effortlessly run queries, generate shell commands or code, create images from text, and more, using simple commands\. Streamline your workflow and enhance productivity with this powerful and user\-friendly CLI tool\.
153
+ .IP \(bu 2
154
+ fzf
155
+ .UR https:\[sl]\[sl]github\.com\[sl]junegunn\[sl]fzf
156
+ .UE
157
+ fzf is a general\-purpose command\-line fuzzy finder\. It\[cq]s an interactive Unix filter for command\-line that can be used with any list; files, command history, processes, hostnames, bookmarks, git commits, etc\.
158
+ .IP \(bu 2
159
+ ripgrep
160
+ .UR https:\[sl]\[sl]github\.com\[sl]BurntSushi\[sl]ripgrep
161
+ .UE
162
+ Search tool like grep and The Silver Searcher\. It is a line\-oriented search tool that recursively searches a directory tree for a regex pattern\. By default, ripgrep will respect gitignore rules and automatically skip hidden files\[sl]directories and binary files\. (To disable all automatic filtering by default, use rg \-uuu\.) ripgrep has first class support on Windows, macOS and Linux, with binary downloads available for every release\.
163
+ .IP \(bu 2
164
+ glow
165
+ .UR https:\[sl]\[sl]github\.com\[sl]charmbracelet\[sl]glow
166
+ .UE
167
+ Render markdown on the CLI
150
168
  .RE
151
169
  .SH AUTHOR
152
170
  .PP
data/man/aia.1.md CHANGED
@@ -46,6 +46,9 @@ The aia command-line tool is an interface for interacting with an AI model backe
46
46
  `--model` *NAME*
47
47
  : Name of the LLM model to use - default is gpt-4-1106-preview
48
48
 
49
+ `--render`
50
+ : Render markdown to the terminal using the external tool "glow" - default: false
51
+
49
52
  `--speak`
50
53
  : Simple implementation. Uses the "say" command to speak the response. Fun with --chat
51
54
 
@@ -135,6 +138,13 @@ Detail discussion on individual prompt directives is TBD. Most likely it will b
135
138
 
136
139
  - [sgpt](https://github.com/tbckr/sgpt) (aka shell-gpt) is a powerful command-line interface (CLI) tool designed for seamless interaction with OpenAI models directly from your terminal. Effortlessly run queries, generate shell commands or code, create images from text, and more, using simple commands. Streamline your workflow and enhance productivity with this powerful and user-friendly CLI tool.
137
140
 
141
+ - [fzf](https://github.com/junegunn/fzf) fzf is a general-purpose command-line fuzzy finder. It's an interactive Unix filter for command-line that can be used with any list; files, command history, processes, hostnames, bookmarks, git commits, etc.
142
+
143
+ - [ripgrep](https://github.com/BurntSushi/ripgrep) Search tool like grep and The Silver Searcher. It is a line-oriented search tool that recursively searches a directory tree for a regex pattern. By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files. (To disable all automatic filtering by default, use rg -uuu.) ripgrep has first class support on Windows, macOS and Linux, with binary downloads available for every release.
144
+
145
+ - [glow](https://github.com/charmbracelet/glow) Render markdown on the CLI
146
+
147
+
138
148
  ## AUTHOR
139
149
 
140
150
  Dewayne VanHoozer <dvanhoozer@gmail.com>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-13 00:00:00.000000000 Z
11
+ date: 2024-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tty-screen
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tty-spinner
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: minitest
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -164,12 +192,18 @@ dependencies:
164
192
  - - ">="
165
193
  - !ruby/object:Gem::Version
166
194
  version: '0'
167
- description: "A command-line AI Assistante (aia) that provides\nparameterized prompt
168
- management (via the prompt_manager gem) to\nvarious backend gen-AI processes. aia
169
- currently supports the \"mods\"\nCLI tool. aia uses \"ripgrep\" and \"fzf\" CLI
170
- utilities \nto search for and select prompt files to send to the backend gen-AI\ntool
171
- along with supported context files. Example usage: \"aia refactor my_class.rb\"
172
- \nwhere \"refactor\" is the prompt ID for the file \"refactor.txt\" from your\nRPROMPTS_DIR\n"
195
+ description: |
196
+ `aia` - the AI Assistant - is a command-line (CLI) tool for
197
+ interfacing with generative AI (gen-AI/GPT) backends. Its designed
198
+ to provide developers with the ability to issue prompts, receive
199
+ AI-generated responses, and incorporate additional context from files
200
+ such as Ruby source code. It supports configuration and customization
201
+ for different environments, includes options for output formats like
202
+ markdown rendering or spoken responses, and allows dynamic content
203
+ generation within prompts such as shell integration and embedded
204
+ Ruby. With `aia`, users benefit from a simplified setup process and
205
+ an extendable interaction model with AI, suitable for a range of
206
+ command-line tasks.
173
207
  email:
174
208
  - dvanhoozer@gmail.com
175
209
  executables:
@@ -201,6 +235,7 @@ files:
201
235
  - lib/aia/tools.rb
202
236
  - lib/aia/tools/backend_common.rb
203
237
  - lib/aia/tools/editor.rb
238
+ - lib/aia/tools/glow.rb
204
239
  - lib/aia/tools/mods.rb
205
240
  - lib/aia/tools/sgpt.rb
206
241
  - lib/aia/tools/subl.rb