Commit b56133a

mo khan <mo@mokhan.ca>
2026-01-17 06:25:41
fix: print invalid tool call in error
1 parent ccbf688
Changed files (2)
lib/elelem/agent.rb
@@ -57,7 +57,7 @@ module Elelem
         tool_calls.each do |tool_call|
           name, args = tool_call[:name], tool_call[:arguments]
           terminal.say "\n#{format_tool_display(name, args)}"
-          result = truncate(toolbox.run(name, args))
+          result = toolbox.run(tool_call)
           terminal.say format_tool_result(name, result)
           ctx << { role: "tool", tool_call_id: tool_call[:id], content: result.to_json }
           errors += 1 if result[:error]
@@ -91,7 +91,7 @@ module Elelem
     end
 
     def format_tool_result(name, result)
-      return nil if result[:exit_status]
+      return if result[:exit_status]
 
       text = result[:content] || result[:error] || ""
       return nil if text.strip.empty?
@@ -99,13 +99,6 @@ module Elelem
       result[:error] ? "  ! #{text.lines.first&.strip}" : text
     end
 
-    def truncate(result)
-      return result unless result[:content].is_a?(String) && result[:content].lines.size > MAX_LINES
-
-      result[:content] = result[:content].lines.first(MAX_LINES).join + "… (truncated)"
-      result
-    end
-
     def system_prompt
       <<~PROMPT.strip
         Terminal agent. Be concise. Act directly, verify your work.
lib/elelem/toolbox.rb
@@ -48,10 +48,11 @@ module Elelem
       end
     end
 
-    def run(name, args)
+    def run(tool_call)
+      name, args = tool_call[:name], tool_call[:arguments]
       name = ALIASES.fetch(name, name)
       tool = tools[name]
-      return { error: "unknown tool: #{name}" } unless tool
+      return { error: "unknown tool: #{tool_call}" } unless tool
 
       tool[:fn].call(args)
     rescue => e