aia 0.5.2 → 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: 35bff72b31591194079e96f6e1dfab9dc76db90fda1f635e962377aeb77b5662
4
- data.tar.gz: 60704012ba00cca73bdb6bb344a4207df189b97b5dc2d686a53215836c5d27d5
3
+ metadata.gz: 872817d33ce07dce0b81526206b55de4800df41adc7b31a295c0d690f677ff58
4
+ data.tar.gz: f95bdf3845fec419a8b0e56a0c2075e2b1cbab79342538eeb32acb4dc255f8c1
5
5
  SHA512:
6
- metadata.gz: a7b3f5bb0bee380f3863bfe80599e8898e16143587d374db27f99d27a718433d9e6869da1a8f44207016185c0b28935b5c5edbaf45d939992ad58ecd65a68fa9
7
- data.tar.gz: 3f4fd8f0707e55cfc2147090d55ff4c865eba8c14bb22bb07831b3e46653530c9800a8d69f148e978bcb763a91d47ac3b58c1f2ab19e387019d6537b9446059e
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: 2
4
+ :patch: 3
5
5
  :special: ''
6
6
  :metadata: ''
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
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
+
3
6
  ## [0.5.2] 2024-01-13
4
7
  - wrap response when its going to the terminal
5
8
 
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/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
@@ -57,6 +57,7 @@ class AIA::Main
57
57
  # Function to prompt the user with a question using reline
58
58
  def ask_question_with_reline(prompt)
59
59
  if prompt.start_with?("\n")
60
+ puts
60
61
  puts
61
62
  prompt = prompt[1..]
62
63
  end
@@ -111,20 +112,10 @@ class AIA::Main
111
112
  files: AIA.config.arguments # FIXME: want validated context files
112
113
  )
113
114
 
114
-
115
- result = backend.run
116
-
117
- if STDOUT == AIA.config.out_file
118
- result = result.wrap(indent: 2)
119
- end
120
-
121
- # TODO: consider using glow to render markdown to
122
- # terminal `brew install glow`
123
- AIA.config.out_file.write result
115
+ result = get_and_display_result(the_prompt)
124
116
 
125
117
  logger.prompt_result(@prompt, result)
126
118
 
127
-
128
119
  if AIA.config.chat?
129
120
  setup_reline_history
130
121
  speak result
@@ -133,34 +124,75 @@ class AIA::Main
133
124
  end
134
125
 
135
126
 
136
- 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
137
158
  if 'mods' == AIA.config.backend
138
- AIA.config.extra += " -C"
159
+ continue_option = " -C"
160
+ AIA.config.extra += continue_option unless AIA.config.extra.include?(continue_option)
139
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: ")
140
178
 
141
- backend.text = ask_question_with_reline("\nFollow Up: ")
142
-
143
- until backend.text.empty?
144
- if AIA.config.terse?
145
- backend.text.prepend "Be terse in your response. "
146
- end
179
+ until the_prompt_text.empty?
180
+ the_prompt_text = insert_terse_phrase(the_prompt_text)
147
181
 
148
- logger.info "Follow Up: #{backend.text}"
149
- response = backend.run
150
-
151
- 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
+
152
188
 
153
- puts "\nResponse:\n#{response.wrap(indent: 2)}"
154
- logger.info "Response: #{backend.run}"
155
-
156
189
  # TODO: Allow user to enter a directive; loop
157
190
  # until answer is not a directive
158
191
  #
159
192
  # while !directive do
160
- backend.text = ask_question_with_reline("\nFollow Up: ")
161
193
 
162
- speak backend.text
163
-
194
+ the_prompt_text = ask_question_with_reline("\nFollow Up: ")
195
+
164
196
  # execute the directive
165
197
  # end
166
198
  end
data/lib/aia/prompt.rb CHANGED
@@ -151,6 +151,7 @@ class AIA::Prompt
151
151
  # Function to prompt the user with a question using reline
152
152
  def ask_question_with_reline(prompt)
153
153
  if prompt.start_with?("\n")
154
+ puts
154
155
  puts
155
156
  prompt = prompt[1..]
156
157
  end
@@ -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/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.2
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