girb 0.4.1 → 0.4.2

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: f244733846ba5bf59fd211ed2d84baf52b62cc3865e67b42601889d50f0754da
4
- data.tar.gz: b25bb0834fa555712f5fd3ad5ad05ec3459e9fc0ba198f385aa6bebad1fa815c
3
+ metadata.gz: 2c8e1b470a14e892f8309060aeba93369a49d9447f5407f8f16ba114838c35ac
4
+ data.tar.gz: ef985221519c5ac871b158f51304aff1eef55c9ff75a34a45118842102acef84
5
5
  SHA512:
6
- metadata.gz: e52e3443a0cc91f8b5a53ae7ac5c36c33fbe04a9e6eeb1450148a7aa54e321d46cba35b3ab2845ddcfff5cafa29c9bd2e1250adc19a028f2cb43d312b31ca8b5
7
- data.tar.gz: 50fcdded0067980c0098c5e9cebc0b5d76c6a3a1f799f0d749cb4b2faf1433ba0f4a590908fd1c7f10e54b7d41252c0b9e08066fe9c3d35ea2a1da6d799fc9a6
6
+ metadata.gz: 640764d0fad7f882743e3bf5fc973da26363e9730e65a17471c575d5e912c57b08545aaefca707dd1d87efac7fb5335d82e028718be9414c8623f29653484d44
7
+ data.tar.gz: 14ec81191995278196e8d8f6de2f0653456488b1139b9d1418341f56b251e2288bba8d3a8a2640e58d358ae047460e0f35169dcac9bd8c574fa20e99e10b51d4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.2] - 2026-02-13
4
+
5
+ ### Added
6
+
7
+ - Show tool execution details (name, arguments, results) in human-readable format during AI operation
8
+ - Add detailed debug logging for provider responses and messages (`c.debug = true`)
9
+
10
+ ### Changed
11
+
12
+ - Reinforce Ruby environment context in system prompts to reduce provider-specific function call errors
13
+ - Provider-agnostic error handling: display `response.error` summary to user without retrying
14
+
15
+ ### Fixed
16
+
17
+ - Fix AI sometimes responding in Japanese regardless of user's language
18
+ - Replace Japanese auto-continue messages in IRB-to-debug transition with English
19
+ - Replace Japanese placeholder text in session history with English
20
+ - Remove Japanese example from debug prompt greeting detection
21
+
3
22
  ## [0.4.1] - 2026-02-12
4
23
 
5
24
  ### Fixed
@@ -140,6 +140,23 @@ module Girb
140
140
  end
141
141
 
142
142
  messages = ConversationHistory.to_normalized
143
+ if Girb.configuration.debug
144
+ puts "[girb] --- Sending to provider (iteration #{iterations}) ---"
145
+ puts "[girb] messages count: #{messages.length}"
146
+ messages.each_with_index do |msg, i|
147
+ case msg[:role]
148
+ when :tool_call
149
+ args_preview = msg[:args].inspect.slice(0, 150)
150
+ puts "[girb] [#{i}] role=tool_call name=#{msg[:name]} args=#{args_preview}"
151
+ when :tool_result
152
+ result_preview = msg[:result].inspect.slice(0, 150)
153
+ puts "[girb] [#{i}] role=tool_result name=#{msg[:name]} result=#{result_preview}"
154
+ else
155
+ content_preview = msg[:content].to_s.gsub("\n", "\\n").slice(0, 150)
156
+ puts "[girb] [#{i}] role=#{msg[:role]} content=#{content_preview.inspect}"
157
+ end
158
+ end
159
+ end
143
160
  begin
144
161
  response = @provider.chat(
145
162
  messages: messages,
@@ -165,9 +182,11 @@ module Girb
165
182
  end
166
183
 
167
184
  if Girb.configuration.debug
168
- puts "[girb] function_calls: #{response.function_calls.inspect}"
169
- puts "[girb] text: #{response.text&.slice(0, 100).inspect}"
170
- puts "[girb] error: #{response.error.inspect}" if response.error
185
+ puts "[girb] --- Response (iteration #{iterations}) ---"
186
+ puts "[girb] text: #{response.text.nil? ? 'nil' : response.text.empty? ? '""' : response.text.slice(0, 200).inspect}"
187
+ puts "[girb] function_call?: #{response.function_call?}"
188
+ puts "[girb] function_calls: #{response.function_calls.inspect}" if response.function_call?
189
+ puts "[girb] error: #{response.error.inspect}" if response.error
171
190
  end
172
191
 
173
192
  unless response
@@ -176,7 +195,10 @@ module Girb
176
195
  end
177
196
 
178
197
  if response.error && !response.function_call?
179
- puts "[girb] API Error: #{response.error}"
198
+ puts "[girb] API Error: #{response.error}" if Girb.configuration.debug
199
+ ConversationHistory.add_assistant_message("")
200
+ error_summary = response.error.to_s.split(":").first || "Unknown error"
201
+ puts "[girb] Error: #{error_summary}"
180
202
  break
181
203
  end
182
204
 
@@ -193,9 +215,7 @@ module Girb
193
215
  tool_args = function_call[:args] || {}
194
216
  tool_id = function_call[:id]
195
217
 
196
- if Girb.configuration.debug
197
- puts "[girb] Tool: #{tool_name}(#{tool_args.map { |k, v| "#{k}: #{v.inspect}" }.join(', ')})"
198
- end
218
+ print_tool_call(tool_name, tool_args)
199
219
 
200
220
  result = execute_tool(tool_name, tool_args)
201
221
 
@@ -207,9 +227,7 @@ module Girb
207
227
 
208
228
  ConversationHistory.add_tool_call(tool_name, tool_args, result, id: tool_id, metadata: function_call[:metadata])
209
229
 
210
- if Girb.configuration.debug && result.is_a?(Hash) && result[:error]
211
- puts "[girb] Tool error: #{result[:error]}"
212
- end
230
+ print_tool_result(tool_name, result)
213
231
 
214
232
  # If run_debug_command was called, we need to exit the tool loop
215
233
  # so the debugger/IRB can execute the pending commands
@@ -237,11 +255,14 @@ module Girb
237
255
  end
238
256
 
239
257
  full_text = accumulated_text.any? ? accumulated_text.join("\n") : ""
240
- # 空でも必ずアシスタントメッセージを記録(user/assistantの交互を維持)
258
+ # Always record assistant message even when empty (maintain user/assistant alternation)
241
259
  ConversationHistory.add_assistant_message(full_text)
242
260
  if full_text.empty?
243
- puts "[girb] Warning: Empty or unexpected response" if Girb.configuration.debug
261
+ if Girb.configuration.debug
262
+ puts "[girb] Warning: Empty response"
263
+ end
244
264
  else
265
+ ConversationHistory.add_assistant_message(full_text)
245
266
  puts full_text
246
267
  record_ai_response(full_text)
247
268
  end
@@ -269,6 +290,32 @@ module Girb
269
290
  { error: "Tool execution failed: #{e.class} - #{e.message}" }
270
291
  end
271
292
 
293
+ def print_tool_call(name, args)
294
+ puts ""
295
+ puts "[girb] #{name}"
296
+ args.each do |key, value|
297
+ str = value.to_s
298
+ if str.include?("\n")
299
+ puts " #{key}:"
300
+ str.each_line { |line| puts " #{line}" }
301
+ else
302
+ puts " #{key}: #{str}"
303
+ end
304
+ end
305
+ end
306
+
307
+ def print_tool_result(_name, result)
308
+ return unless result.is_a?(Hash)
309
+
310
+ if result[:error]
311
+ puts "[girb] => Error: #{result[:error]}"
312
+ elsif result[:stdout] && !result[:stdout].empty?
313
+ puts "[girb] => #{result[:stdout]}"
314
+ elsif result[:result]
315
+ puts "[girb] => #{result[:result]}"
316
+ end
317
+ end
318
+
272
319
  def record_ai_response(response)
273
320
  if @debug_mode
274
321
  require_relative "debug_session_history"
@@ -3,8 +3,8 @@
3
3
  module Girb
4
4
  class DebugPromptBuilder
5
5
  SYSTEM_PROMPT = <<~PROMPT
6
- You are girb, an AI debugging assistant embedded in a Ruby debugger session.
7
- You are integrated with Ruby's debug gem and can help developers debug their code.
6
+ You are girb, an AI debugging assistant embedded in a Ruby debugger (debug gem) session.
7
+ The runtime environment is Ruby. All code execution, evaluation, and examples must be in Ruby.
8
8
 
9
9
  ## CRITICAL: Context Information
10
10
  The user is stopped at a breakpoint or debugger statement.
@@ -31,7 +31,7 @@ module Girb
31
31
  - NEVER ask the user for code, file names, or variable definitions that you can look up
32
32
  yourself with `read_file`, `evaluate_code`, `inspect_object`, or `find_file`
33
33
 
34
- However, for simple greetings or conversational messages (e.g., "hello", "hi", "こんにちは", "thanks"),
34
+ However, for simple greetings or conversational messages (e.g., "hello", "hi", "thanks"),
35
35
  just respond naturally without using tools. Not every message requires investigation.
36
36
 
37
37
  ## CRITICAL: Variable Persistence Across Frames
@@ -27,13 +27,13 @@ module Girb
27
27
  original_question = Girb::IrbIntegration.pending_user_question
28
28
  Girb::IrbIntegration.pending_user_question = nil
29
29
  if original_question
30
- continuation = "(auto-continue: デバッグモードに移行しました。最初のデバッグコマンドは既に実行されました。" \
31
- "同じコマンドを再度発行しないでください。\n" \
32
- "元の指示: 「#{original_question}」\n" \
33
- "次のステップに進んでください。例: continueで実行を継続、または結果を確認。)"
30
+ continuation = "(auto-continue: Transitioned to debug mode. The first debug command has already been executed. " \
31
+ "Do NOT re-issue the same command.\n" \
32
+ "Original instruction: \"#{original_question}\"\n" \
33
+ "Proceed to the next step. e.g., continue execution or inspect results.)"
34
34
  else
35
- continuation = "(auto-continue: デバッグモードに移行しました。最初のデバッグコマンドは既に実行されました。" \
36
- "次のステップに進んでください。)"
35
+ continuation = "(auto-continue: Transitioned to debug mode. The first debug command has already been executed. " \
36
+ "Proceed to the next step.)"
37
37
  end
38
38
  Girb::DebugIntegration.add_pending_debug_command("qq #{continuation}")
39
39
  end
@@ -4,7 +4,8 @@ module Girb
4
4
  class PromptBuilder
5
5
  # Common prompt shared across all IRB modes
6
6
  COMMON_PROMPT = <<~PROMPT
7
- You are girb, an AI assistant embedded in a Ruby developer's session.
7
+ You are girb, an AI assistant embedded in a Ruby developer's IRB (Interactive Ruby) session.
8
+ The runtime environment is Ruby. All code execution, evaluation, and examples must be in Ruby.
8
9
 
9
10
  ## CRITICAL: Prompt Information Takes Highest Priority
10
11
  Information in this system prompt and "User-Defined Instructions" section
@@ -129,7 +129,7 @@ module Girb
129
129
  response_preview = if e.ai_response
130
130
  truncate(e.ai_response, 100)
131
131
  else
132
- "(回答待ち)"
132
+ "(awaiting response)"
133
133
  end
134
134
  "#{e.line_no}: [USER] #{e.code} => [AI] #{response_preview}"
135
135
  else
data/lib/girb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Girb
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - rira100000000