diff --git a/lib/roast/cogs/agent.rb b/lib/roast/cogs/agent.rb index 05e57614..ff69c631 100644 --- a/lib/roast/cogs/agent.rb +++ b/lib/roast/cogs/agent.rb @@ -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 diff --git a/lib/roast/cogs/agent/providers/claude/claude_invocation.rb b/lib/roast/cogs/agent/providers/claude/claude_invocation.rb index d7080289..f2555877 100644 --- a/lib/roast/cogs/agent/providers/claude/claude_invocation.rb +++ b/lib/roast/cogs/agent/providers/claude/claude_invocation.rb @@ -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 @@ -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, @@ -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 diff --git a/test/examples/functional/roast_examples_test.rb b/test/examples/functional/roast_examples_test.rb index 8f081a3f..5e808c1c 100644 --- a/test/examples/functional/roast_examples_test.rb +++ b/test/examples/functional/roast_examples_test.rb @@ -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 @@ -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, diff --git a/test/roast/cogs/agent/providers/claude/claude_invocation_test.rb b/test/roast/cogs/agent/providers/claude/claude_invocation_test.rb index a5e4e3ef..2314ede2 100644 --- a/test/roast/cogs/agent/providers/claude/claude_invocation_test.rb +++ b/test/roast/cogs/agent/providers/claude/claude_invocation_test.rb @@ -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 @@ -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 diff --git a/test/roast/cogs/agent/providers/claude_test.rb b/test/roast/cogs/agent/providers/claude_test.rb index d1edbb13..9237bece 100644 --- a/test/roast/cogs/agent/providers/claude_test.rb +++ b/test/roast/cogs/agent/providers/claude_test.rb @@ -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