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
29 changes: 29 additions & 0 deletions lib/roast/cogs/agent/providers/claude/tool_use.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,35 @@ def format_skill
args ? "SKILL #{skill} (#{truncate(args)})" : "SKILL #{skill}"
end

# Formats a Task tool-use line.
#
# Input fields:
# :description (String) – short label for the task [required]
# :run_in_background (bool) – run the agent asynchronously [optional]
# :subagent_type (String) – which agent type to spawn [optional]
# :model (String) – model override for the agent [optional]
#
# Output: "TASK <description>", with " (<details>)" appended when any
# optional field is set: "background" (when :run_in_background is set),
# then :subagent_type, then :model — joined with " · " in that order and
# shown as raw values (no key= labels). :description is truncated to
# TRUNCATE_LIMIT chars; the other fields are not.
#
# Examples:
# TASK Find all callers (background · Explore · opus)
# TASK Summarize the diff
#
#: () -> String
def format_task
description = truncate(input[:description])
details = [
("background" if input[:run_in_background]),
input[:subagent_type],
input[:model],
].compact.join(" · ")
details.empty? ? "TASK #{description}" : "TASK #{description} (#{details})"
end

#: () -> String
def format_unknown
"UNKNOWN [#{name}] #{input.inspect}"
Expand Down
38 changes: 38 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 @@ -300,6 +300,44 @@ class ToolUseTest < ActiveSupport::TestCase
assert_equal "SKILL #{long} (#{truncated})", output
end

# format_task

test "format_task renders the description alone with no optional fields" do
tool_use = ToolUse.new(name: :task, input: { description: "Find all callers" })

output = tool_use.format

assert_equal "TASK Find all callers", output
end

test "format_task joins background, subagent type, and model in order" do
input = { description: "Audit", run_in_background: true, subagent_type: "Explore", model: "opus" }
tool_use = ToolUse.new(name: :task, input: input)

output = tool_use.format

assert_equal "TASK Audit (background · Explore · opus)", output
end

test "format_task omits background when run_in_background is false" do
tool_use = ToolUse.new(name: :task, input: { description: "Audit", run_in_background: false })

output = tool_use.format

assert_equal "TASK Audit", output
end

test "format_task truncates the description but not the subagent type or model" do
long = "a" * (ToolUse::TRUNCATE_LIMIT + 10)
truncated = "#{"a" * (ToolUse::TRUNCATE_LIMIT - 3)}..."
input = { description: long, subagent_type: long, model: long }
tool_use = ToolUse.new(name: :task, input: input)

output = tool_use.format

assert_equal "TASK #{truncated} (#{long} · #{long})", output
end

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

Expand Down
Loading