Class: Clacky::PlainUIController

Inherits:
Object
  • Object
show all
Includes:
UIInterface
Defined in:
lib/clacky/plain_ui_controller.rb

Overview

PlainUIController implements UIInterface for non-interactive (–message) mode. Writes human-readable plain text directly to stdout so the caller can capture or pipe the output. No spinners, no TUI β€” just clean lines.

Instance Method Summary collapse

Methods included from UIInterface

#show_diff, #show_token_usage, #show_tool_args, #show_tool_stdout

Constructor Details

#initialize(output: $stdout) ⇒ PlainUIController

Returns a new instance of PlainUIController.



12
13
14
15
# File 'lib/clacky/plain_ui_controller.rb', line 12

def initialize(output: $stdout)
  @output = output
  @mutex = Mutex.new
end

Instance Method Details

#append_output(content) ⇒ Object



80
81
82
# File 'lib/clacky/plain_ui_controller.rb', line 80

def append_output(content)
  puts_line(content)
end

#clear_inputObject

Input control / Lifecycle (no-ops) ===



134
# File 'lib/clacky/plain_ui_controller.rb', line 134

def clear_input; end

#clear_progressObject



115
# File 'lib/clacky/plain_ui_controller.rb', line 115

def clear_progress; end

#log(message, level: :info) ⇒ Object



107
108
109
110
# File 'lib/clacky/plain_ui_controller.rb', line 107

def log(message, level: :info)
  # Only surface errors/warnings; suppress debug noise in plain mode
  puts_line("[#{level}] #{message}") if %i[error warn].include?(level.to_sym)
end

#puts_line(text) ⇒ Object



139
140
141
142
143
144
# File 'lib/clacky/plain_ui_controller.rb', line 139

def puts_line(text)
  @mutex.synchronize do
    @output.puts(text)
    @output.flush
  end
end

#request_confirmation(message, default: true) ⇒ Object

Blocking interaction (auto-approve in non-interactive mode) ===



126
127
128
129
130
# File 'lib/clacky/plain_ui_controller.rb', line 126

def request_confirmation(message, default: true)
  # Should not be reached because permission_mode is forced to auto_approve,
  # but return true as a safety net.
  true
end

#set_idle_statusObject



122
# File 'lib/clacky/plain_ui_controller.rb', line 122

def set_idle_status; end

#set_input_tips(message, type: :info) ⇒ Object



135
# File 'lib/clacky/plain_ui_controller.rb', line 135

def set_input_tips(message, type: :info); end

#set_working_statusObject



121
# File 'lib/clacky/plain_ui_controller.rb', line 121

def set_working_status; end

#show_assistant_message(content, files:) ⇒ Object

Output display ===



19
20
21
22
# File 'lib/clacky/plain_ui_controller.rb', line 19

def show_assistant_message(content, files:)
  puts_line(content) unless content.nil? || content.strip.empty?
  files.each { |f| puts_line("πŸ“„ File: #{f[:path]}") }
end

#show_complete(iterations:, cost:, duration: nil, cache_stats: nil, awaiting_user_feedback: false) ⇒ Object



74
75
76
77
78
# File 'lib/clacky/plain_ui_controller.rb', line 74

def show_complete(iterations:, cost:, duration: nil, cache_stats: nil, awaiting_user_feedback: false)
  parts = ["[done] iterations=#{iterations}", "cost=$#{cost.round(4)}"]
  parts << "duration=#{duration.round(1)}s" if duration
  puts_line(parts.join(" "))
end

#show_error(message) ⇒ Object



99
100
101
# File 'lib/clacky/plain_ui_controller.rb', line 99

def show_error(message)
  puts_line("[error] #{message}")
end

#show_file_edit_preview(path) ⇒ Object



62
63
64
# File 'lib/clacky/plain_ui_controller.rb', line 62

def show_file_edit_preview(path)
  puts_line("[file] edit: #{path}")
end

#show_file_error(error_message) ⇒ Object



66
67
68
# File 'lib/clacky/plain_ui_controller.rb', line 66

def show_file_error(error_message)
  puts_line("[file error] #{error_message}")
end

#show_file_write_preview(path, is_new_file:) ⇒ Object



57
58
59
60
# File 'lib/clacky/plain_ui_controller.rb', line 57

def show_file_write_preview(path, is_new_file:)
  action = is_new_file ? "create" : "overwrite"
  puts_line("[file] #{action}: #{path}")
end

#show_idle_status(phase:, message:) ⇒ Object



90
91
92
93
# File 'lib/clacky/plain_ui_controller.rb', line 90

def show_idle_status(phase:, message:)
  # In plain mode, just print the final state
  puts_line("[info] #{message}") if phase.to_s == "end"
end

#show_info(message, prefix_newline: true) ⇒ Object

Status messages ===



86
87
88
# File 'lib/clacky/plain_ui_controller.rb', line 86

def show_info(message, prefix_newline: true)
  puts_line("[info] #{message}")
end

#show_progress(message = nil, prefix_newline: true, output_buffer: nil) ⇒ Object

Progress (no-ops β€” no spinner in plain mode) ===



114
# File 'lib/clacky/plain_ui_controller.rb', line 114

def show_progress(message = nil, prefix_newline: true, output_buffer: nil); end

#show_shell_preview(command) ⇒ Object



70
71
72
# File 'lib/clacky/plain_ui_controller.rb', line 70

def show_shell_preview(command)
  puts_line("[shell] #{command}")
end

#show_success(message) ⇒ Object



103
104
105
# File 'lib/clacky/plain_ui_controller.rb', line 103

def show_success(message)
  puts_line("[ok] #{message}")
end

#show_tool_call(name, args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/clacky/plain_ui_controller.rb', line 24

def show_tool_call(name, args)
  args_data = args.is_a?(String) ? (JSON.parse(args) rescue args) : args
  display = case name
            when "shell", "safe_shell"
              cmd = args_data.is_a?(Hash) ? (args_data[:command] || args_data["command"]) : args_data
              "$ #{cmd}"
            when "write"
              path = args_data.is_a?(Hash) ? (args_data[:path] || args_data["path"]) : args_data
              "Write β†’ #{path}"
            when "edit"
              path = args_data.is_a?(Hash) ? (args_data[:path] || args_data["path"]) : args_data
              "Edit β†’ #{path}"
            else
              label = args_data.is_a?(Hash) ? args_data.map { |k, v| "#{k}=#{v.to_s[0..40]}" }.join(", ") : args_data.to_s[0..80]
              "#{name}(#{label})"
            end
  puts_line("[tool] #{display}")
end

#show_tool_error(error) ⇒ Object



52
53
54
55
# File 'lib/clacky/plain_ui_controller.rb', line 52

def show_tool_error(error)
  msg = error.is_a?(Exception) ? error.message : error.to_s
  puts_line("[error] #{msg}")
end

#show_tool_result(result) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/clacky/plain_ui_controller.rb', line 43

def show_tool_result(result)
  text = result.to_s.strip
  return if text.empty?

  # Indent multi-line results for readability
  indented = text.lines.map { |l| "  #{l}" }.join
  puts_line(indented)
end

#show_warning(message) ⇒ Object



95
96
97
# File 'lib/clacky/plain_ui_controller.rb', line 95

def show_warning(message)
  puts_line("[warn] #{message}")
end

#stopObject



136
# File 'lib/clacky/plain_ui_controller.rb', line 136

def stop; end

#update_sessionbar(tasks: nil, cost: nil, status: nil) ⇒ Object

State updates (no-ops) ===



119
# File 'lib/clacky/plain_ui_controller.rb', line 119

def update_sessionbar(tasks: nil, cost: nil, status: nil); end

#update_todos(todos) ⇒ Object



120
# File 'lib/clacky/plain_ui_controller.rb', line 120

def update_todos(todos); end