Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/roast/cogs/agent/providers/claude/tool_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ def ok_line(*parts)
summary.present? ? "#{prefix} #{summary}" : prefix
end

# Renders "<TOOL> ERROR <message>" with any <tool_use_error> wrapper stripped.
# Renders "<TOOL> ERROR <message>" – the text inside the
# <tool_use_error> wrapper, or the whole content when it is unwrapped.
#
# Reads the instance's `content` and `tool_name` to produce a single-line
# error summary. Error messages are intentionally NOT truncated so the full
Expand All @@ -339,7 +340,7 @@ def ok_line(*parts)
#
#: () -> String
def error_line
message = content.to_s.gsub(%r{</?tool_use_error>}, "").strip
message = tag_text("tool_use_error") || content.to_s.strip
"#{tool_name.to_s.upcase} ERROR #{message}".strip
end

Expand Down
16 changes: 16 additions & 0 deletions test/roast/cogs/agent/providers/claude/tool_result_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ class Claude::ToolResultTest < ActiveSupport::TestCase
assert_equal "BASH ERROR File has not been read yet.", output
end

test "error_line preserves special characters in the tool_use_error body" do
tool_use_message = Claude::Messages::ToolUseMessage.new(
type: :tool_use,
hash: { name: "bash", input: {} },
)
tool_result = Claude::ToolResult.new(
tool_use: tool_use_message,
content: "<tool_use_error>parse error: a < b && c > d, see <ref>x</ref> & exit 1</tool_use_error>",
is_error: true,
)

output = tool_result.send(:error_line)

assert_equal "BASH ERROR parse error: a < b && c > d, see <ref>x</ref> & exit 1", output
end

test "error_line handles nil content gracefully" do
tool_use_message = Claude::Messages::ToolUseMessage.new(
type: :tool_use,
Expand Down
Loading