Class: Clacky::PlainUIController
- Inherits:
-
Object
- Object
- Clacky::PlainUIController
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
-
#append_output(content) ⇒ Object
-
#clear_input ⇒ Object
-
#clear_progress ⇒ Object
-
#initialize(output: $stdout) ⇒ PlainUIController
constructor
A new instance of PlainUIController.
-
#log(message, level: :info) ⇒ Object
-
#puts_line(text) ⇒ Object
-
#request_confirmation(message, default: true) ⇒ Object
Blocking interaction (auto-approve in non-interactive mode) ===.
-
#set_idle_status ⇒ Object
-
#set_input_tips(message, type: :info) ⇒ Object
-
#set_working_status ⇒ Object
-
#show_assistant_message(content, files:) ⇒ Object
Output display ===.
-
#show_complete(iterations:, cost:, duration: nil, cache_stats: nil, awaiting_user_feedback: false) ⇒ Object
-
#show_error(message) ⇒ Object
-
#show_file_edit_preview(path) ⇒ Object
-
#show_file_error(error_message) ⇒ Object
-
#show_file_write_preview(path, is_new_file:) ⇒ Object
-
#show_idle_status(phase:, message:) ⇒ Object
-
#show_info(message, prefix_newline: true) ⇒ Object
Status messages ===.
-
#show_progress(message = nil, prefix_newline: true, output_buffer: nil) ⇒ Object
Progress (no-ops β no spinner in plain mode) ===.
-
#show_shell_preview(command) ⇒ Object
-
#show_success(message) ⇒ Object
-
#show_tool_call(name, args) ⇒ Object
-
#show_tool_error(error) ⇒ Object
-
#show_tool_result(result) ⇒ Object
-
#show_warning(message) ⇒ Object
-
#stop ⇒ Object
-
#update_sessionbar(tasks: nil, cost: nil, status: nil) ⇒ Object
State updates (no-ops) ===.
-
#update_todos(todos) ⇒ Object
#show_diff, #show_token_usage, #show_tool_args, #show_tool_stdout
Constructor Details
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
|
134
|
# File 'lib/clacky/plain_ui_controller.rb', line 134
def clear_input; end
|
#clear_progress ⇒ Object
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)
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)
true
end
|
#set_idle_status ⇒ Object
122
|
# File 'lib/clacky/plain_ui_controller.rb', line 122
def set_idle_status; end
|
135
|
# File 'lib/clacky/plain_ui_controller.rb', line 135
def set_input_tips(message, type: :info); end
|
#set_working_status ⇒ Object
121
|
# File 'lib/clacky/plain_ui_controller.rb', line 121
def set_working_status; end
|
#show_assistant_message(content, files:) ⇒ Object
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:)
puts_line("[info] #{message}") if phase.to_s == "end"
end
|
#show_info(message, prefix_newline: true) ⇒ Object
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
|
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
|
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
|
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?
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
|
#stop ⇒ Object
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
|