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 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
- #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.
-
#start_display_loop ⇒ Object
Simple display initialization - no background threads.
- #stop_display_loop ⇒ Object
- #update_job(job_id, updates) ⇒ Object
Constructor Details
#initialize(prompt: TTY::Prompt.new, tty: $stdin) ⇒ EnhancedTUI
Returns a new instance of EnhancedTUI.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 23 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 Method Details
#add_job(job_id, job_data) ⇒ Object
Job management methods - interface for EnhancedRunner
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 234 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)
92 93 94 95 96 97 98 99 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 92 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
61 62 63 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 61 def get_confirmation(, default: true) @prompt.yes?() end |
#get_user_input(prompt = "💬 You: ") ⇒ Object
Input methods using TTY::Prompt only - no background threads
57 58 59 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 57 def get_user_input(prompt = "💬 You: ") @prompt.ask(prompt) end |
#multiselect(title, items, selected: []) ⇒ Object
Multiselect interface using TTY::Prompt
71 72 73 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 71 def multiselect(title, items, selected: []) @prompt.multi_select(title, items, default: selected) end |
#remove_job(job_id) ⇒ Object
253 254 255 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 253 def remove_job(job_id) @jobs.delete(job_id) end |
#show_input_area(message) ⇒ Object
257 258 259 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 257 def show_input_area() @prompt.say("📝 #{message}", color: :cyan) end |
#show_message(message, type = :info) ⇒ Object
Display methods using TTY::Prompt
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 76 def (, type = :info) case type when :info @prompt.say("ℹ #{message}", color: :blue) when :success @prompt.say("✓ #{message}", color: :green) when :warning @prompt.say("⚠ #{message}", color: :yellow) when :error @prompt.say("✗ #{message}", color: :red) else @prompt.say() end end |
#show_step_execution(step_name, status, details = {}) ⇒ Object
Enhanced step execution display
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 226 227 228 229 230 231 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 140 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
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 113 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
102 103 104 105 106 107 108 109 110 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 102 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
66 67 68 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 66 def single_select(title, items, default: 0) @prompt.select(title, items, default: default, cycle: true) end |
#start_display_loop ⇒ Object
Simple display initialization - no background threads
47 48 49 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 47 def start_display_loop # Display loop is now just a no-op for compatibility end |
#stop_display_loop ⇒ Object
51 52 53 54 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 51 def stop_display_loop # Simple cleanup - no background threads to stop restore_screen end |
#update_job(job_id, updates) ⇒ Object
246 247 248 249 250 251 |
# File 'lib/aidp/harness/ui/enhanced_tui.rb', line 246 def update_job(job_id, updates) return unless @jobs[job_id] @jobs[job_id].merge!(updates) @jobs[job_id][:updated_at] = Time.now end |