consolle 0.2.9 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 826cb825a86940fa018abc635b0c7b5914999d85da2c079801d7b98a85166adb
4
- data.tar.gz: 919448817dd2064b93214be249eeb840bb328ef3c907ab9f8456daf2a8d45992
3
+ metadata.gz: 985e37c4ac0dab7d0404e36898e75e23e4337a9d5e57b379f4e4f6b57e6461b2
4
+ data.tar.gz: fe8fa63ff1d743359391c81a0d3f1a472d494f72eb86a88d6be1e852d1f57e5f
5
5
  SHA512:
6
- metadata.gz: a3fb3a9902a388e4fe3d551e867c4d6ceec83aff1087e54a48f972c5bb1e029b9216ca4baa5a7c83d1eeee9905285607093cb09e790eda60583f7a66efa501d3
7
- data.tar.gz: 4a5de0ff45adc32c57a35595b6743133a7f4d5cf1911d0c6dba50c5cd1ae11b0779942845af3a69d8d01c6ddb77745a81d106dfa2639b3e41ee34c91c593fcf2
6
+ metadata.gz: d490d26a53d2db34d1943c162dcbeea8b359632c36846ddf803afcee7b6d93f11cc1e759e9e06b66b743d2fd38c2d8ba71a39ac5623318f106227229bf977ad6
7
+ data.tar.gz: 94610670b7059fe04fff2fb143b63502c29171b3f435c06f808897f74cbd05e16732efcf89ea9a27e4944680501d0b7ed93879ce10e5b67b02e57349ada15815
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.3.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consolle (0.2.9)
4
+ consolle (0.3.1)
5
5
  logger (~> 1.0)
6
6
  thor (~> 1.0)
7
7
 
@@ -5,6 +5,7 @@ require 'json'
5
5
  require 'timeout'
6
6
  require 'securerandom'
7
7
  require 'fileutils'
8
+ require_relative '../constants'
8
9
 
9
10
  module Consolle
10
11
  module Adapters
@@ -20,7 +21,7 @@ module Consolle
20
21
  @rails_env = rails_env || 'development'
21
22
  @verbose = verbose
22
23
  @command = command || 'bin/rails console'
23
- @wait_timeout = wait_timeout || 15
24
+ @wait_timeout = wait_timeout || Consolle::DEFAULT_WAIT_TIMEOUT
24
25
  @server_pid = nil
25
26
  end
26
27
 
@@ -270,13 +271,20 @@ module Consolle
270
271
  File.unlink(pid_file) if File.exist?(pid_file)
271
272
  end
272
273
 
273
- def wait_for_server(timeout: 15)
274
+ def wait_for_server(timeout: Consolle::DEFAULT_WAIT_TIMEOUT)
274
275
  deadline = Time.now + timeout
275
276
  server_pid = nil
276
277
  error_found = false
277
278
  error_message = nil
278
279
  last_log_check = Time.now
279
280
  ssh_auth_detected = false
281
+
282
+ # Record the initial log file position to avoid reading old errors
283
+ initial_log_pos = if File.exist?(@log_path)
284
+ File.size(@log_path)
285
+ else
286
+ 0
287
+ end
280
288
 
281
289
  puts "Waiting for console to start (timeout: #{timeout}s)..." if @verbose
282
290
 
@@ -290,12 +298,15 @@ module Consolle
290
298
  rescue Errno::ESRCH
291
299
  # Process died - check log for error
292
300
  if File.exist?(@log_path)
293
- log_content = File.read(@log_path)
294
- if log_content.include?('[Server] Error:')
295
- error_lines = log_content.lines.grep(/\[Server\] Error:/)
296
- error_message = error_lines.last.strip if error_lines.any?
297
- else
298
- error_message = "Server process died unexpectedly"
301
+ File.open(@log_path, 'r') do |f|
302
+ f.seek(initial_log_pos)
303
+ log_content = f.read
304
+ if log_content.include?('[Server] Error:')
305
+ error_lines = log_content.lines.grep(/\[Server\] Error:/)
306
+ error_message = error_lines.last.strip if error_lines.any?
307
+ else
308
+ error_message = "Server process died unexpectedly"
309
+ end
299
310
  end
300
311
  else
301
312
  error_message = "Server process died unexpectedly"
@@ -308,29 +319,32 @@ module Consolle
308
319
  # Check log file periodically for errors or SSH auth messages
309
320
  if Time.now - last_log_check > 0.5
310
321
  last_log_check = Time.now
311
- if File.exist?(@log_path)
312
- log_content = File.read(@log_path)
313
-
314
- # Check for explicit errors
315
- if log_content.include?('[Server] Error:')
316
- error_lines = log_content.lines.grep(/\[Server\] Error:/)
317
- error_message = error_lines.last.strip if error_lines.any?
318
- error_found = true
319
- break
320
- end
321
-
322
- # Check for SSH authentication messages
323
- if !ssh_auth_detected && (log_content.include?('SSH') ||
324
- log_content.include?('ssh') ||
325
- log_content.include?('Authenticating') ||
326
- log_content.include?('authentication') ||
327
- log_content.include?('1Password') ||
328
- @command.include?('kamal') ||
329
- @command.include?('ssh'))
330
- ssh_auth_detected = true
331
- puts "SSH authentication detected, extending timeout..." if @verbose
332
- # Extend deadline for SSH auth
333
- deadline = Time.now + [timeout, 60].max
322
+ if File.exist?(@log_path) && File.size(@log_path) > initial_log_pos
323
+ File.open(@log_path, 'r') do |f|
324
+ f.seek(initial_log_pos)
325
+ log_content = f.read
326
+
327
+ # Check for explicit errors
328
+ if log_content.include?('[Server] Error:')
329
+ error_lines = log_content.lines.grep(/\[Server\] Error:/)
330
+ error_message = error_lines.last.strip if error_lines.any?
331
+ error_found = true
332
+ break
333
+ end
334
+
335
+ # Check for SSH authentication messages
336
+ if !ssh_auth_detected && (log_content.include?('SSH') ||
337
+ log_content.include?('ssh') ||
338
+ log_content.include?('Authenticating') ||
339
+ log_content.include?('authentication') ||
340
+ log_content.include?('1Password') ||
341
+ @command.include?('kamal') ||
342
+ @command.include?('ssh'))
343
+ ssh_auth_detected = true
344
+ puts "SSH authentication detected, extending timeout..." if @verbose
345
+ # Extend deadline for SSH auth
346
+ deadline = Time.now + [timeout, 60].max
347
+ end
334
348
  end
335
349
  end
336
350
  end
data/lib/consolle/cli.rb CHANGED
@@ -7,6 +7,7 @@ require 'socket'
7
7
  require 'timeout'
8
8
  require 'securerandom'
9
9
  require 'date'
10
+ require_relative 'constants'
10
11
  require_relative 'adapters/rails_console'
11
12
 
12
13
  module Consolle
@@ -132,7 +133,7 @@ module Consolle
132
133
  LONGDESC
133
134
  method_option :rails_env, type: :string, aliases: '-e', desc: 'Rails environment', default: 'development'
134
135
  method_option :command, type: :string, aliases: '-c', desc: 'Custom console command', default: 'bin/rails console'
135
- method_option :wait_timeout, type: :numeric, aliases: '-w', desc: 'Timeout for console startup (seconds)', default: 15
136
+ method_option :wait_timeout, type: :numeric, aliases: '-w', desc: 'Timeout for console startup (seconds)', default: Consolle::DEFAULT_WAIT_TIMEOUT
136
137
  def start
137
138
  ensure_rails_project!
138
139
  ensure_project_directories
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Consolle
4
+ # Default timeout for console startup (in seconds)
5
+ DEFAULT_WAIT_TIMEOUT = 25
6
+ end
@@ -4,6 +4,7 @@ require 'pty'
4
4
  require 'timeout'
5
5
  require 'fcntl'
6
6
  require 'logger'
7
+ require_relative '../constants'
7
8
  require_relative '../errors'
8
9
 
9
10
  # Ruby 3.4.0+ extracts base64 as a default gem
@@ -32,7 +33,7 @@ module Consolle
32
33
  @rails_env = rails_env
33
34
  @command = command || 'bin/rails console'
34
35
  @logger = logger || Logger.new(STDOUT)
35
- @wait_timeout = wait_timeout || 15
36
+ @wait_timeout = wait_timeout || Consolle::DEFAULT_WAIT_TIMEOUT
36
37
  @pid = nil
37
38
  @reader = nil
38
39
  @writer = nil
@@ -317,6 +318,13 @@ module Consolle
317
318
  chunk = @reader.read_nonblock(4096)
318
319
  output << chunk
319
320
  marker_found = output.include?(marker)
321
+
322
+ # Respond to cursor position request during initialization
323
+ if chunk.include?("\e[6n")
324
+ logger.debug "[ConsoleSupervisor] Detected cursor position request during init, sending response"
325
+ @writer.write("\e[1;1R")
326
+ @writer.flush
327
+ end
320
328
  rescue IO::WaitReadable
321
329
  IO.select([@reader], nil, nil, 0.1)
322
330
  rescue Errno::EIO
@@ -387,12 +395,17 @@ module Consolle
387
395
 
388
396
  def wait_for_prompt(timeout: 15, consume_all: false)
389
397
  output = +''
390
- deadline = Time.now + timeout
398
+ start_time = Time.now
399
+ deadline = start_time + timeout
391
400
  prompt_found = false
392
401
  last_data_time = Time.now
393
402
 
403
+ logger.info "[ConsoleSupervisor] Waiting for prompt with timeout: #{timeout}s (deadline: #{deadline}, now: #{start_time})"
404
+
394
405
  loop do
395
- if Time.now > deadline
406
+ current_time = Time.now
407
+ if current_time > deadline
408
+ logger.error "[ConsoleSupervisor] Timeout reached. Current: #{current_time}, Deadline: #{deadline}, Elapsed: #{current_time - start_time}s"
396
409
  logger.error "[ConsoleSupervisor] Output so far: #{output.inspect}"
397
410
  logger.error "[ConsoleSupervisor] Stripped: #{strip_ansi(output).inspect}"
398
411
  raise Timeout::Error, "No prompt after #{timeout} seconds"
@@ -414,6 +427,13 @@ module Consolle
414
427
  last_data_time = Time.now
415
428
  logger.debug "[ConsoleSupervisor] Got chunk: #{chunk.inspect}"
416
429
 
430
+ # Respond to cursor position request (ESC[6n)
431
+ if chunk.include?("\e[6n")
432
+ logger.debug "[ConsoleSupervisor] Detected cursor position request, sending response"
433
+ @writer.write("\e[1;1R") # Report cursor at position 1,1
434
+ @writer.flush
435
+ end
436
+
417
437
  clean = strip_ansi(output)
418
438
  # Check each line for prompt pattern
419
439
  clean.lines.each do |line|
data/lib/consolle.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'consolle/version'
4
+ require_relative 'consolle/constants'
4
5
  require_relative 'consolle/errors'
5
6
  require_relative 'consolle/cli'
6
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consolle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nacyot
@@ -79,6 +79,7 @@ files:
79
79
  - lib/consolle.rb
80
80
  - lib/consolle/adapters/rails_console.rb
81
81
  - lib/consolle/cli.rb
82
+ - lib/consolle/constants.rb
82
83
  - lib/consolle/errors.rb
83
84
  - lib/consolle/server/console_socket_server.rb
84
85
  - lib/consolle/server/console_supervisor.rb