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

# Formats a TodoWrite tool-use line.
#
# Input fields:
# :todos (Array) – the full todo list [required]
#
# Output: "TODOWRITE <n> todos" (singular "todo" when n is 1). When the
# list is non-empty, " (<breakdown>)" is appended — each distinct :status
# with its count ("<count> <status>"), joined with " · " in the order the
# statuses first appear.
#
# Examples:
# TODOWRITE 3 todos (2 completed · 1 in_progress)
# TODOWRITE 1 todo (1 in_progress)
# TODOWRITE 0 todos
#
#: () -> String
def format_todowrite
todos = input[:todos] || []
counts = todos.group_by { |todo| todo[:status] }.transform_values(&:length)
summary = counts.map { |status, count| "#{count} #{status}" }.join(" · ")
label = todos.length == 1 ? "todo" : "todos"
base = "TODOWRITE #{todos.length} #{label}"
summary.empty? ? base : "#{base} (#{summary})"
end

#: () -> String
def format_unknown
"UNKNOWN [#{name}] #{input.inspect}"
Expand Down
36 changes: 36 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 @@ -236,6 +236,42 @@ class ToolUseTest < ActiveSupport::TestCase
assert_equal "EDIT /a.rb (-0 +0 lines)", output
end

# format_todowrite

test "format_todowrite shows a zero count and no breakdown for an empty list" do
tool_use = ToolUse.new(name: :todowrite, input: {})

output = tool_use.format

assert_equal "TODOWRITE 0 todos", output
end

test "format_todowrite uses the singular label for a single todo" do
tool_use = ToolUse.new(name: :todowrite, input: { todos: [{ status: "pending" }] })

output = tool_use.format

assert_equal "TODOWRITE 1 todo (1 pending)", output
end

test "format_todowrite tallies each status with its count" do
todos = [{ status: "completed" }, { status: "pending" }, { status: "completed" }]
tool_use = ToolUse.new(name: :todowrite, input: { todos: todos })

output = tool_use.format

assert_equal "TODOWRITE 3 todos (2 completed · 1 pending)", output
end

test "format_todowrite orders the breakdown by where each status first appears" do
todos = [{ status: "pending" }, { status: "completed" }, { status: "completed" }]
tool_use = ToolUse.new(name: :todowrite, input: { todos: todos })

output = tool_use.format

assert_equal "TODOWRITE 3 todos (1 pending · 2 completed)", output
end

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

Expand Down
Loading