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



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

def append_output(content)
  puts_line(content)
end

#clear_inputObject

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



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

def clear_input; end

#clear_progressObject



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

def clear_progress; end

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



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

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



153
154
155
156
157
158
# File 'lib/clacky/plain_ui_controller.rb', line 153

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



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

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



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

def set_idle_status; end

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



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

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

#set_working_statusObject



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

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



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

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



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

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

#show_file_edit_preview(path) ⇒ Object



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

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

#show_file_error(error_message) ⇒ Object



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

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

#show_file_write_preview(path, is_new_file:) ⇒ Object



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

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



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

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



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

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

#show_shell_preview(command) ⇒ Object



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

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

#show_success(message) ⇒ Object



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

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
# 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 "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



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

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



62
63
64
65
66
67
68
69
# File 'lib/clacky/plain_ui_controller.rb', line 62

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



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

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

#stopObject



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

def stop; end

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

State updates (no-ops) ===



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

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

#update_todos(todos) ⇒ Object



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

def update_todos(todos); end