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



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

def append_output(content)
  puts_line(content)
end

#clear_inputObject

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



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

def clear_input; end

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



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

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



159
160
161
162
163
164
# File 'lib/clacky/plain_ui_controller.rb', line 159

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) ===



146
147
148
149
150
# File 'lib/clacky/plain_ui_controller.rb', line 146

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



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

def set_idle_status; end

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



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

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

#set_working_statusObject



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

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



100
101
102
103
104
# File 'lib/clacky/plain_ui_controller.rb', line 100

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



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

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

#show_file_edit_preview(path) ⇒ Object



88
89
90
# File 'lib/clacky/plain_ui_controller.rb', line 88

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

#show_file_error(error_message) ⇒ Object



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

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

#show_file_write_preview(path, is_new_file:) ⇒ Object



83
84
85
86
# File 'lib/clacky/plain_ui_controller.rb', line 83

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

#show_info(message, prefix_newline: true) ⇒ Object

Status messages ===



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

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

#show_progress(message = nil, prefix_newline: true, progress_type: "thinking", phase: "active", metadata: {}) ⇒ Object

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



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

def show_progress(message = nil, prefix_newline: true, progress_type: "thinking", phase: "active", metadata: {}); end

#show_shell_preview(command) ⇒ Object



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

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

#show_success(message) ⇒ Object



124
125
126
# File 'lib/clacky/plain_ui_controller.rb', line 124

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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

  # Special handling for request_user_feedback β€” display as a readable prompt
  if name.to_s == "request_user_feedback"
    question = args_data.is_a?(Hash) ? (args_data[:question] || args_data["question"]).to_s : ""
    context  = args_data.is_a?(Hash) ? (args_data[:context]  || args_data["context"]).to_s  : ""
    options  = args_data.is_a?(Hash) ? (args_data[:options]  || args_data["options"])        : nil
    options  = Array(options) if options && !options.is_a?(Array)

    parts = []
    parts << "**Context:** #{context.strip}" if context && !context.strip.empty?
    parts << "**Question:** #{question.strip}"
    if options && !options.empty?
      parts << "**Options:**"
      options.each_with_index { |opt, i| parts << "  #{i + 1}. #{opt}" }
    end
    puts_line(parts.join("\n"))
    return
  end

  display = case name
            when "terminal"
              cmd = args_data.is_a?(Hash) ? (args_data[:command] || args_data["command"]) : args_data
              sid = args_data.is_a?(Hash) ? (args_data[:session_id] || args_data["session_id"]) : nil
              if cmd
                "$ #{cmd}"
              elsif sid
                "$ (session ##{sid})"
              else
                "$ terminal"
              end
            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



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

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



69
70
71
72
73
74
75
76
# File 'lib/clacky/plain_ui_controller.rb', line 69

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



116
117
118
# File 'lib/clacky/plain_ui_controller.rb', line 116

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

#stopObject



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

def stop; end

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

State updates (no-ops) ===



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

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

#update_todos(todos) ⇒ Object



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

def update_todos(todos); end