Class: AIHype::PTYController
- Inherits:
-
Object
- Object
- AIHype::PTYController
- Defined in:
- lib/aihype/pty_controller.rb
Constant Summary collapse
- PROMPT_TIMEOUT =
0.5
- BUFFER_LINES =
20
Instance Attribute Summary collapse
-
#ai_matcher ⇒ Object
readonly
Returns the value of attribute ai_matcher.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#blacklist ⇒ Object
readonly
Returns the value of attribute blacklist.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(command:, args: [], config_path:, log_path:, verbose: false) ⇒ PTYController
constructor
A new instance of PTYController.
- #run ⇒ Object
Constructor Details
#initialize(command:, args: [], config_path:, log_path:, verbose: false) ⇒ PTYController
Returns a new instance of PTYController.
17 18 19 20 21 22 23 24 25 |
# File 'lib/aihype/pty_controller.rb', line 17 def initialize(command:, args: [], config_path:, log_path:, verbose: false) @command = command @args = args @config_path = config_path @log_path = log_path @verbose = verbose @line_buffer = String.new @recent_lines = [] end |
Instance Attribute Details
#ai_matcher ⇒ Object (readonly)
Returns the value of attribute ai_matcher.
12 13 14 |
# File 'lib/aihype/pty_controller.rb', line 12 def ai_matcher @ai_matcher end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
12 13 14 |
# File 'lib/aihype/pty_controller.rb', line 12 def args @args end |
#blacklist ⇒ Object (readonly)
Returns the value of attribute blacklist.
12 13 14 |
# File 'lib/aihype/pty_controller.rb', line 12 def blacklist @blacklist end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
12 13 14 |
# File 'lib/aihype/pty_controller.rb', line 12 def command @command end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/aihype/pty_controller.rb', line 12 def logger @logger end |
Instance Method Details
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aihype/pty_controller.rb', line 27 def run # Load components @blacklist = Blacklist.from_file(@config_path) @ai_matcher = AIMatcher.new @logger = Logger.new(log_file_path: @log_path, verbose: @verbose) @core = Core.new(blacklist: @blacklist, ai_matcher: @ai_matcher, logger: @logger) @logger.log_startup(@blacklist.enabled_rules.length, @config_path) # Spawn child process via PTY PTY.spawn(@command, *@args) do |pty_out, pty_in, pid| exit_code = process_pty_io(pty_out, pty_in, pid) return exit_code end 0 rescue InvalidMemoryFileError, Errno::ENOENT => e $stderr.puts "Error: Invalid or missing config file: #{e.message}" 2 rescue StandardError => e $stderr.puts "Error: #{e.message}" $stderr.puts e.backtrace.join("\n") if @verbose 1 end |