Class: Aidp::Interfaces::TtyCommandExecutor
- Inherits:
-
Object
- Object
- Aidp::Interfaces::TtyCommandExecutor
- Includes:
- CommandExecutorInterface
- Defined in:
- lib/aidp/interfaces/command_executor_interface.rb
Overview
TtyCommandExecutor wraps TTY::Command for command execution. This adapter provides the standard implementation used by AIDP.
Instance Method Summary collapse
-
#execute(command, args: [], input: nil, timeout: nil, **options) ⇒ CommandResult
Execute a shell command using TTY::Command.
-
#initialize(logger: nil, component_name: "command_executor") ⇒ TtyCommandExecutor
constructor
A new instance of TtyCommandExecutor.
Constructor Details
#initialize(logger: nil, component_name: "command_executor") ⇒ TtyCommandExecutor
Returns a new instance of TtyCommandExecutor.
133 134 135 136 |
# File 'lib/aidp/interfaces/command_executor_interface.rb', line 133 def initialize(logger: nil, component_name: "command_executor") @logger = logger @component_name = component_name end |
Instance Method Details
#execute(command, args: [], input: nil, timeout: nil, **options) ⇒ CommandResult
Execute a shell command using TTY::Command.
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 |
# File 'lib/aidp/interfaces/command_executor_interface.rb', line 146 def execute(command, args: [], input: nil, timeout: nil, **) require "tty-command" log_debug("executing_command", command: command, args: args, timeout: timeout) start_time = Time.now begin cmd_obj = TTY::Command.new(printer: :null) # Prepare input data input_data = resolve_input(input) # Execute command - use run! to get result even on non-zero exit result = cmd_obj.run!(command, *args, input: input_data, timeout: timeout, **) duration = Time.now - start_time log_debug("command_completed", command: command, exit_status: result.exit_status, duration: duration.round(2)) CommandResult.new( stdout: result.out, stderr: result.err, exit_status: result.exit_status ) rescue TTY::Command::TimeoutExceeded duration = Time.now - start_time log_debug("command_timeout", command: command, timeout: timeout, duration: duration.round(2)) raise CommandTimeoutError.new(command: command, timeout: timeout) rescue Errno::ENOENT, Errno::EACCES => e # Command not found or not executable duration = Time.now - start_time log_debug("command_not_found", command: command, error: e., duration: duration.round(2)) raise CommandExecutionError.new(command: command, original_error: e) rescue => e duration = Time.now - start_time log_debug("command_failed", command: command, error: e., duration: duration.round(2)) raise CommandExecutionError.new(command: command, original_error: e) end end |