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
19 changes: 19 additions & 0 deletions lib/roast/cogs/agent/providers/claude/tool_use.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ def format_read
details ? "READ #{file_path} (#{details})" : "READ #{file_path}"
end

# Formats a Glob tool-use line.
#
# Input fields:
# :pattern (String) – glob pattern to match [required]
# :path (String) – directory to search in [optional]
#
# Output: "GLOB <pattern>", with " (in <path>)" appended when :path
# is present.
#
# Examples:
# GLOB **/*.rb (in lib/roast)
# GLOB **/*.rb
#
#: () -> String
def format_glob
pattern, path = input.values_at(:pattern, :path)
path ? "GLOB #{pattern} (in #{path})" : "GLOB #{pattern}"
end

#: () -> String
def format_unknown
"UNKNOWN [#{name}] #{input.inspect}"
Expand Down
18 changes: 18 additions & 0 deletions test/roast/cogs/agent/providers/claude/tool_use_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ class ToolUseTest < ActiveSupport::TestCase
assert_equal "READ /a.rb", output
end

# format_glob

test "format_glob renders the pattern only when no path given" do
tool_use = ToolUse.new(name: :glob, input: { pattern: "**/*.rb" })

output = tool_use.format

assert_equal "GLOB **/*.rb", output
end

test "format_glob appends the search path in parentheses" do
tool_use = ToolUse.new(name: :glob, input: { pattern: "**/*.rb", path: "lib/roast" })

output = tool_use.format

assert_equal "GLOB **/*.rb (in lib/roast)", output
end

test "format calls format_unknown for unknown tool" do
tool_use = ToolUse.new(name: :unknown_tool, input: { arg: "value" })

Expand Down
Loading