Skip to content
Draft
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
18 changes: 18 additions & 0 deletions lib/roast/cogs/agent/providers/pi/messages/tool_call_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ def format_bash
command.empty? ? "BASH" : "BASH #{command}"
end

# Formats a read tool call.
#
# Input fields:
# :path (String) – file to read [required]
#
# Output: "READ <path>", with :path truncated to TRUNCATE_LIMIT chars.
# A missing path renders the bare "READ".
#
# Examples:
# READ lib/roast.rb
# READ
#
#: () -> String
def format_read
path = truncate(arguments[:path])
path.empty? ? "READ" : "READ #{path}"
end

# Formats a tool call for which Roast has no dedicated formatter.
#
# Output: "<NAME> <key>: <value>, ..." – the upcased tool name, then each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ def format_bash
ok_line("#{count} #{"line".pluralize(count)}", preview)
end

# Formats a read tool result.
#
# Content: the file's text.
#
# Output: "READ OK <n> <line|lines>" – <n> is the line count (pluralized).
#
# Examples:
# READ OK 42 lines
# READ OK 1 line
# READ OK 0 lines
#
#: () -> String
def format_read
count = content.to_s.lines.length
ok_line("#{count} #{"line".pluralize(count)}")
end

# Formats a result for which Roast has no dedicated formatter.
#
# Content: the tool's output text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ class ToolCallMessageTest < ActiveSupport::TestCase
assert_equal "BASH #{"x" * (ToolCallMessage::TRUNCATE_LIMIT - 3)}...", msg.format
end

test "format renders READ with the path" do
msg = ToolCallMessage.new(id: "1", name: "read", arguments: { path: "lib/roast.rb" })
assert_equal "READ lib/roast.rb", msg.format
end

test "format renders a bare READ when the path is missing" do
msg = ToolCallMessage.new(id: "1", name: "read", arguments: {})
assert_equal "READ", msg.format
end

test "format truncates a long read path" do
msg = ToolCallMessage.new(id: "1", name: "read", arguments: { path: "x" * 100 })
assert_equal "READ #{"x" * (ToolCallMessage::TRUNCATE_LIMIT - 3)}...", msg.format
end

test "format renders an unhandled tool as NAME key: value, ..." do
msg = ToolCallMessage.new(
id: "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ def setup
assert_equal "BASH OK 0 lines", msg.format(@context)
end

test "format summarizes read output with a line count" do
msg = ToolResultMessage.new(
tool_call_id: "1",
tool_name: "read",
content: "line one\nline two\nline three",
is_error: false,
)

assert_equal "READ OK 3 lines", msg.format(@context)
end

test "format pluralizes a single line of read output" do
msg = ToolResultMessage.new(
tool_call_id: "1",
tool_name: "read",
content: "just one line",
is_error: false,
)

assert_equal "READ OK 1 line", msg.format(@context)
end

test "format reports zero lines when the file is empty" do
msg = ToolResultMessage.new(
tool_call_id: "1",
tool_name: "read",
content: nil,
is_error: false,
)

assert_equal "READ OK 0 lines", msg.format(@context)
end

test "format renders NAME ERROR with the message for an error result" do
msg = ToolResultMessage.new(
tool_call_id: "1",
Expand Down
Loading