Class: Aidp::Harness::UI::EnhancedTUI
- Inherits:
-
Object
- Object
- Aidp::Harness::UI::EnhancedTUI
- Defined in:
- lib/aidp/harness/ui/enhanced_tui.rb
Overview
Enhanced TUI system using TTY libraries, inspired by Claude Code and modern LLM agents
Defined Under Namespace
Classes: DisplayError, InputError, TUIError
Instance Attribute Summary collapse
-
#current_mode ⇒ Object
Expose state for testability.
-
#current_step ⇒ Object
Expose state for testability.
-
#headless ⇒ Object
Expose state for testability.
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#workflow_active ⇒ Object
Expose state for testability.
Instance Method Summary collapse
-
#add_job(job_id, job_data) ⇒ Object
Job management methods - interface for EnhancedRunner.
-
#announce_mode(mode) ⇒ Object
Called by CLI after mode selection in interactive flow (added helper).
- #get_confirmation(message, default: true) ⇒ Object
-
#get_user_input(prompt = "💬 You: ") ⇒ Object
Input methods using TTY::Prompt only - no background threads.
-
#initialize(prompt: TTY::Prompt.new, tty: $stdin) ⇒ EnhancedTUI
constructor
A new instance of EnhancedTUI.
-
#multiselect(title, items, selected: []) ⇒ Object
Multiselect interface using TTY::Prompt.
- #remove_job(job_id) ⇒ Object
- #restore_screen ⇒ Object
- #show_input_area(message) ⇒ Object
-
#show_message(message, type = :info) ⇒ Object
Display methods using TTY::Prompt.
-
#show_step_execution(step_name, status, details = {}) ⇒ Object
Enhanced step execution display.
-
#show_workflow_status(workflow_data) ⇒ Object
Enhanced workflow display.
-
#simulate_step_execution(step_name) ⇒ Object
Simulate selecting a workflow step in test mode.
-
#single_select(title, items, default: 0) ⇒ Object
Single-select interface using TTY::Prompt.
- #update_job(job_id, updates) ⇒ Object
Constructor Details
#initialize(prompt: TTY::Prompt.new, tty: $stdin) ⇒ EnhancedTUI
Returns a new instance of EnhancedTUI.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 27 def initialize(prompt: TTY::Prompt.new, tty: $stdin) @cursor = TTY::Cursor @screen = TTY::Screen @prompt = prompt # Headless (non-interactive) detection for test/CI environments: # - STDIN not a TTY (captured by PTY/tmux harness or test environment) @headless = !!(tty.nil? || !tty.tty?) # Initialize Pastel with disabled colors in headless mode to avoid # "closed stream" errors when checking TTY capabilities @pastel = Pastel.new(enabled: !@headless) @current_mode = nil @workflow_active = false @current_step = nil @jobs = {} @jobs_visible = false setup_signal_handlers end |
Instance Attribute Details
#current_mode ⇒ Object
Expose state for testability
24 25 26 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 24 def current_mode @current_mode end |
#current_step ⇒ Object
Expose state for testability
24 25 26 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 24 def current_step @current_step end |
#headless ⇒ Object
Expose state for testability
24 25 26 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 24 def headless @headless end |
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
25 26 27 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 25 def jobs @jobs end |
#workflow_active ⇒ Object
Expose state for testability
24 25 26 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 24 def workflow_active @workflow_active end |
Instance Method Details
#add_job(job_id, job_data) ⇒ Object
Job management methods - interface for EnhancedRunner
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 228 def add_job(job_id, job_data) @jobs[job_id] = { id: job_id, name: job_data[:name] || job_id, status: job_data[:status] || :pending, progress: job_data[:progress] || 0, provider: job_data[:provider], message: job_data[:message], created_at: Time.now } end |
#announce_mode(mode) ⇒ Object
Called by CLI after mode selection in interactive flow (added helper)
86 87 88 89 90 91 92 93 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 86 def announce_mode(mode) @current_mode = mode if @headless header = (mode == :analyze) ? "Analyze Mode" : "Execute Mode" @prompt.say(header) @prompt.say("Select workflow") end end |
#get_confirmation(message, default: true) ⇒ Object
55 56 57 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 55 def get_confirmation(, default: true) @prompt.yes?() end |
#get_user_input(prompt = "💬 You: ") ⇒ Object
Input methods using TTY::Prompt only - no background threads
51 52 53 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 51 def get_user_input(prompt = "💬 You: ") @prompt.ask(prompt) end |
#multiselect(title, items, selected: []) ⇒ Object
Multiselect interface using TTY::Prompt
65 66 67 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 65 def multiselect(title, items, selected: []) @prompt.multi_select(title, items, default: selected) end |
#remove_job(job_id) ⇒ Object
247 248 249 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 247 def remove_job(job_id) @jobs.delete(job_id) end |
#restore_screen ⇒ Object
255 256 257 258 259 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 255 def restore_screen @cursor.show @cursor.clear_screen @cursor.move_to(1, 1) end |
#show_input_area(message) ⇒ Object
251 252 253 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 251 def show_input_area() @prompt.say("📝 #{}", color: :cyan) end |
#show_message(message, type = :info) ⇒ Object
Display methods using TTY::Prompt
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 70 def (, type = :info) case type when :info @prompt.say("ℹ #{}", color: :blue) when :success @prompt.say("✓ #{}", color: :green) when :warning @prompt.say("⚠ #{}", color: :yellow) when :error @prompt.say("✗ #{}", color: :red) else @prompt.say() end end |
#show_step_execution(step_name, status, details = {}) ⇒ Object
Enhanced step execution display
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 134 def show_step_execution(step_name, status, details = {}) case status when :starting content = [] content << @pastel.blue("Starting execution...") if details[:provider] content << @pastel.dim("Provider: #{details[:provider]}") end box = TTY::Box.frame( content.join("\n"), title: {top_left: "🚀 Executing Step: #{step_name}"}, border: :thick, padding: [1, 2], style: {border: {fg: :blue}} ) @prompt.say(box) when :running content = [] content << @pastel.yellow("Step is running...") if details[:message] content << @pastel.dim(details[:message]) end box = TTY::Box.frame( content.join("\n"), title: {top_left: "⏳ Running Step: #{step_name}"}, border: :thick, padding: [1, 2], style: {border: {fg: :yellow}} ) @prompt.say(box) when :completed content = [] content << @pastel.green("Step completed successfully") if details[:duration] content << @pastel.dim("Duration: #{details[:duration].round(2)}s") end box = TTY::Box.frame( content.join("\n"), title: {top_left: "✅ Completed Step: #{step_name}"}, border: :thick, padding: [1, 2], style: {border: {fg: :green}} ) @prompt.say(box) when :failed content = [] content << @pastel.red("Step failed") if details[:error] # Extract the most relevant error information error_msg = details[:error] # Look for key error patterns and extract them if error_msg.include?("ConnectError:") # Extract ConnectError and what comes after it connect_error_match = error_msg.match(/ConnectError: ([^\\n]+)/) if connect_error_match error_msg = "ConnectError: #{connect_error_match[1]}" end elsif error_msg.include?("exit status:") # Extract exit status and stderr using string operations to avoid ReDoS exit_status_match = error_msg.match(/exit status: (\d+)/) stderr_match = error_msg.match(/stderr: ([^\n\r]+)/) if exit_status_match && stderr_match error_msg = "Exit status: #{exit_status_match[1]}, Error: #{stderr_match[1]}" end elsif error_msg.length > 200 # For other long errors, truncate but keep the beginning error_msg = error_msg[0..200] + "..." end # Wrap long lines wrapped_error = error_msg.gsub(/.{80}/, "\\&\n") content << @pastel.red("Error: #{wrapped_error}") end box = TTY::Box.frame( content.join("\n"), title: {top_left: "❌ Failed Step: #{step_name}"}, border: :thick, padding: [1, 2], style: {border: {fg: :red}}, width: 80 ) @prompt.say(box) end end |
#show_workflow_status(workflow_data) ⇒ Object
Enhanced workflow display
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 107 def show_workflow_status(workflow_data) content = [] content << "#{@pastel.bold("Type:")} #{workflow_data[:workflow_type]}" content << "#{@pastel.bold("Steps:")} #{workflow_data[:steps]&.length || 0} total" content << "#{@pastel.bold("Completed:")} #{workflow_data[:completed_steps] || 0}" content << "#{@pastel.bold("Current:")} #{workflow_data[:current_step] || "None"}" if workflow_data[:progress_percentage] = TTY::ProgressBar.new( "#{@pastel.bold("Progress:")} [:bar] :percent%", total: 100, width: 30 ) .current = workflow_data[:progress_percentage] content << .render end box = TTY::Box.frame( content.join("\n"), title: {top_left: "📋 Workflow Status"}, border: :thick, padding: [1, 2] ) @prompt.say(box) end |
#simulate_step_execution(step_name) ⇒ Object
Simulate selecting a workflow step in test mode
96 97 98 99 100 101 102 103 104 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 96 def simulate_step_execution(step_name) return unless @headless @workflow_active = true @current_step = step_name questions = extract_questions_for_step(step_name) questions.each { |q| @prompt.say(q) } # Simulate quick completion @prompt.say("#{step_name.split("_").first} completed") if step_name.start_with?("00_PRD") end |
#single_select(title, items, default: 0) ⇒ Object
Single-select interface using TTY::Prompt
60 61 62 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 60 def single_select(title, items, default: 0) @prompt.select(title, items, default: default, cycle: true) end |
#update_job(job_id, updates) ⇒ Object
240 241 242 243 244 245 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 240 def update_job(job_id, updates) return unless @jobs[job_id] @jobs[job_id].merge!(updates) @jobs[job_id][:updated_at] = Time.now end |