Class: Miniswen::CLI::Reporter
- Inherits:
-
Object
- Object
- Miniswen::CLI::Reporter
- Defined in:
- lib/miniswen/cli.rb
Overview
Prints messages and tool calls in real-time. The renderer deliberately keeps the captured (non-TTY) version plain, which makes it useful in CI and when piping a run to a log file too.
Constant Summary collapse
- MAX_TOOL_OUTPUT_CHARS =
Tool output can be extremely noisy (for example, a recursive grep or a test runner dumping a log). Keep the normal report useful while allowing -vv to retain the complete output for debugging.
1_000
Instance Method Summary collapse
-
#initialize(io = $stdout, verbose: false) ⇒ Reporter
constructor
A new instance of Reporter.
- #on_message(message) ⇒ Object
-
#on_tool_call(call) ⇒ Object
Tool calls are reported separately so the command is visible before its output arrives.
- #print_failure(result) ⇒ Object
- #print_summary(result) ⇒ Object
Constructor Details
#initialize(io = $stdout, verbose: false) ⇒ Reporter
Returns a new instance of Reporter.
20 21 22 23 |
# File 'lib/miniswen/cli.rb', line 20 def initialize(io = $stdout, verbose: false) @io = io @verbose = verbose end |
Instance Method Details
#on_message(message) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/miniswen/cli.rb', line 25 def () case [:role].to_s when "assistant" write_block("●", [:content], :assistant) when "tool" write_block("↳", [:content], :tool) when "user" write_block("!", [:content], :warning) else write_block("·", [:content], :muted) end end |
#on_tool_call(call) ⇒ Object
Tool calls are reported separately so the command is visible before its output arrives. It is not added to the trajectory sent to the LLM.
40 41 42 43 44 45 46 |
# File 'lib/miniswen/cli.rb', line 40 def on_tool_call(call) command = call.dig(:arguments, "command") || call.dig(:arguments, :command) return if command.to_s.empty? line = style("$ #{command}", :command) io.puts(" #{line}") end |
#print_failure(result) ⇒ Object
53 54 55 |
# File 'lib/miniswen/cli.rb', line 53 def print_failure(result) write_block("!", "Miniswen failed: #{result.status}", :warning) end |
#print_summary(result) ⇒ Object
48 49 50 51 |
# File 'lib/miniswen/cli.rb', line 48 def print_summary(result) write_block("●", result..last[:content], :assistant) write_block("↳", "steps=#{result.steps} · cost=$#{result.cost_usd}", :muted) end |