console_agent 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28a64e6be4f7d39d73e55b67d6e95404324355420293651acf44fd439394eb56
4
- data.tar.gz: 8350d0a49d94733c54530debc4d8e184bd0c2774b04f82c68be24b71d32a7457
3
+ metadata.gz: 35e4cf8ecceb5241ce1b18f2cac6d8a235b3185f7839b2143eca6233390375d5
4
+ data.tar.gz: 7ebfc01003d9995ce65645a1f15955747cd59197c891e294d2152f3101fd583c
5
5
  SHA512:
6
- metadata.gz: 874af072ffd5222c5ef7c782e1b5db18a148ecaf013a6ba8f2e33d863123895235c1d93106551ad5197eb35c17ad2bf65b076a79e74ef091ac76690c59fe4ba8
7
- data.tar.gz: c2ba1ece779bf4e12b30c9bc0ed533dc9acabdaa22d6749e8f3f75d0d18fea1cb3895c669c313ec005f1e79a3a72ab7e2d16a2fefdcbc7df8509eac35afaee92
6
+ metadata.gz: 1bfdf0d1b5a6278101d7cda640ac710a1aef589e5a1adc4194876404d897a53bcfa27cd423029abc76a117eb6ab2ba13a14e605c4447c1452ab78d0f7b98b960
7
+ data.tar.gz: 7589590b8dcbfd4268070ce59da381741ca1643152b2689829d741a6cc325e7d9130576629a3155ba0267fb0ea86623a584f9a6e6c2956143e043da43e551501
data/README.md CHANGED
@@ -117,7 +117,7 @@ Next time, it already knows — no re-reading files, fewer tokens.
117
117
  ```
118
118
  irb> ai!
119
119
  ConsoleAgent interactive mode. Type 'exit' to leave.
120
- Auto-execute: OFF (Shift-Tab or /auto to toggle)
120
+ Auto-execute: OFF (Shift-Tab or /auto to toggle) | > code to run directly | /usage | /name <label>
121
121
 
122
122
  ai> show me all tables
123
123
  ...
@@ -132,6 +132,21 @@ ai> exit
132
132
 
133
133
  Toggle `/auto` to skip confirmation prompts. `/debug` shows raw API traffic. `/usage` shows token stats.
134
134
 
135
+ ### Direct Code Execution
136
+
137
+ Prefix any input with `>` to run Ruby code directly — no LLM round-trip. The result is added to the conversation context, so the AI knows what happened:
138
+
139
+ ```
140
+ ai> >User.count
141
+ => 8
142
+ ai> how many users do I have?
143
+ Thinking...
144
+
145
+ You have **8 users** in your database, as confirmed by the `User.count` you just ran.
146
+ ```
147
+
148
+ Useful for quick checks, setting up variables, or giving the AI concrete data to work with.
149
+
135
150
  ### Sessions
136
151
 
137
152
  Sessions are saved automatically when session logging is enabled. You can name, list, and resume them.
@@ -146,7 +146,7 @@ module ConsoleAgent
146
146
  name_display = @interactive_session_name ? " (#{@interactive_session_name})" : ""
147
147
  # Write banner to real stdout (bypass TeeIO) so it doesn't accumulate on resume
148
148
  @interactive_old_stdout.puts "\e[36mConsoleAgent interactive mode#{name_display}. Type 'exit' or 'quit' to leave.\e[0m"
149
- @interactive_old_stdout.puts "\e[2m Auto-execute: #{auto ? 'ON' : 'OFF'} (Shift-Tab or /auto to toggle) | /usage | /name <label>\e[0m"
149
+ @interactive_old_stdout.puts "\e[2m Auto-execute: #{auto ? 'ON' : 'OFF'} (Shift-Tab or /auto to toggle) | > code to run directly | /usage | /name <label>\e[0m"
150
150
 
151
151
  # Bind Shift-Tab to insert /auto command and submit
152
152
  if Readline.respond_to?(:parse_and_bind)
@@ -199,6 +199,35 @@ module ConsoleAgent
199
199
  next
200
200
  end
201
201
 
202
+ # Direct code execution with ">" prefix — skip LLM entirely
203
+ if input.start_with?('>') && !input.start_with?('>=')
204
+ raw_code = input.sub(/\A>\s?/, '')
205
+ Readline::HISTORY.push(input) unless input == Readline::HISTORY.to_a.last
206
+ @interactive_console_capture.write("ai> #{input}\n")
207
+
208
+ exec_result = @executor.execute(raw_code)
209
+
210
+ output_parts = []
211
+ output_parts << "Output:\n#{@executor.last_output.strip}" if @executor.last_output && !@executor.last_output.strip.empty?
212
+ output_parts << "Return value: #{exec_result.inspect}" if exec_result
213
+
214
+ result_str = output_parts.join("\n\n")
215
+ result_str = result_str[0..1000] + '...' if result_str.length > 1000
216
+
217
+ context_msg = "User directly executed code: `#{raw_code}`"
218
+ context_msg += "\n#{result_str}" unless output_parts.empty?
219
+ @history << { role: :user, content: context_msg }
220
+
221
+ @interactive_query ||= input
222
+ @last_interactive_code = raw_code
223
+ @last_interactive_output = @executor.last_output
224
+ @last_interactive_result = exec_result ? exec_result.inspect : nil
225
+ @last_interactive_executed = true
226
+
227
+ log_interactive_turn
228
+ next
229
+ end
230
+
202
231
  # Add to Readline history (avoid consecutive duplicates)
203
232
  Readline::HISTORY.push(input) unless input == Readline::HISTORY.to_a.last
204
233
 
@@ -285,7 +285,7 @@ module ConsoleAgent
285
285
  when 'a', 'auto'
286
286
  skip_confirmations = true
287
287
  when 'y', 'yes'
288
- # proceed with per-step confirmation
288
+ skip_confirmations = true if steps.length == 1
289
289
  else
290
290
  $stdout.puts "\e[33m Plan declined.\e[0m"
291
291
  feedback = ask_feedback("What would you like changed?")
@@ -1,3 +1,3 @@
1
1
  module ConsoleAgent
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cortfr