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
4 changes: 0 additions & 4 deletions lib/roast/cogs/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ class MissingPromptError < AgentCogError; end
#
#: (Input) -> Output
def execute(input)
puts "[USER PROMPT] #{input.prompts.first}" if config.show_prompt?
output = provider.invoke(input)
# NOTE: If progress is displayed, the agent's response will always be the last progress message,
# so showing it again is duplicative.
puts "[AGENT RESPONSE] #{output.response}" if config.show_response? && !config.show_progress?
puts "[AGENT STATS] #{output.stats}" if config.show_stats?
puts "Session ID: #{output.session}" if config.show_stats?
output
Expand Down
4 changes: 4 additions & 0 deletions lib/roast/cogs/agent/providers/claude/claude_invocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def initialize(config, prompt, session)
@context = Context.new #: Context
@result = Result.new #: Result
@raw_dump_file = config.valid_dump_raw_agent_messages_to_path #: Pathname?
@show_prompt = config.show_prompt? #: bool
@show_progress = config.show_progress? #: bool
@show_response = config.show_response? #: bool
@prompt = prompt
@session = session
end
Expand All @@ -74,6 +76,7 @@ def run!
raise ClaudeAlreadyStartedError if started?

@started = true
puts "[USER PROMPT] #{@prompt}" if @show_prompt
_stdout, stderr, status = CommandRunner.execute(
command_line,
working_directory: @working_directory,
Expand All @@ -83,6 +86,7 @@ def run!

if status.success?
@completed = true
puts "[AGENT RESPONSE] #{@result.response}" if @show_response
else
@failed = true
@result.success = false
Expand Down
4 changes: 3 additions & 1 deletion test/examples/functional/roast_examples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ class RoastExamplesTest < FunctionalTest
Caspian spreads wide—
Ancient waters vast and deep,
World's largest lake gleams.
[AGENT RESPONSE] Caspian spreads wide—
Ancient waters vast and deep,
World's largest lake gleams.
[AGENT STATS] Turns: 1
Duration: 4 seconds
Cost (USD): $0.050913
Expand Down Expand Up @@ -555,7 +558,6 @@ class RoastExamplesTest < FunctionalTest
# When show_progress is enabled (the default), text blocks are accumulated and printed
# as a single unit, and [AGENT RESPONSE] is suppressed to avoid duplication
expected_stdout = <<~STDOUT
[USER PROMPT] What is the world's largest lake?
[USER PROMPT] What is the world's largest lake?
Caspian spreads wide—
Ancient waters vast and deep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Claude < Provider
class ClaudeInvocationTest < ActiveSupport::TestCase
def setup
@config = Agent::Config.new
@config.no_show_progress!
@config.no_display!
@invocation = ClaudeInvocation.new(@config, "Test prompt", nil)
end

Expand Down Expand Up @@ -367,6 +367,73 @@ def failure_status
Event.expects(:<<).never
@invocation.send(:handle_message, second)
end

test "run! prints prompt when show_prompt is enabled" do
@config.show_prompt!
invocation = ClaudeInvocation.new(@config, "Hello agent", nil)

output = capture_io do
CommandRunner.stub(:execute, ["", "", success_status]) do
invocation.run!
end
end

assert_match "[USER PROMPT] Hello agent", output.first
end

test "run! does not print prompt when show_prompt is disabled" do
invocation = ClaudeInvocation.new(@config, "Hello agent", nil)

output = capture_io do
CommandRunner.stub(:execute, ["", "", success_status]) do
invocation.run!
end
end

refute_match(/\[USER PROMPT\]/, output.first)
end

test "run! prints response when show_response is enabled" do
@config.show_response!
invocation = ClaudeInvocation.new(@config, "Hello agent", nil)

result_json = { type: "result", subtype: "success", result: "Here is my answer" }.to_json
output = capture_io do
CommandRunner.stub(:execute, ->(*_args, **kwargs) {
kwargs[:stdout_handler]&.call(result_json)
["", "", success_status]
}) do
invocation.run!
end
end

assert_match "[AGENT RESPONSE] Here is my answer", output.first
end

test "run! does not print response when show_response is disabled" do
@config.no_show_response!
invocation = ClaudeInvocation.new(@config, "Hello agent", nil)

output = capture_io do
CommandRunner.stub(:execute, ["", "", success_status]) do
invocation.run!
end
end

refute_match(/\[AGENT RESPONSE\]/, output.first)
end

test "run! does not print response on failure" do
invocation = ClaudeInvocation.new(@config, "Hello agent", nil)

output = capture_io do
CommandRunner.stub(:execute, ["", "Error", failure_status]) do
invocation.run!
end
end

refute_match(/\[AGENT RESPONSE\]/, output.first)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/roast/cogs/agent/providers/claude_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Providers
class ClaudeTest < ActiveSupport::TestCase
def setup
@config = Agent::Config.new
@config.no_show_progress!
@config.no_display!
@provider = Claude.new(@config)
end

Expand Down
Loading