Class: Ace::Llm::Providers::Cli::Atoms::ProviderDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/llm/providers/cli/atoms/provider_detector.rb

Overview

Detects whether a CLI tool is installed and retrieves its version

Class Method Summary collapse

Class Method Details

.available?(cli_name) ⇒ Boolean

Check if a CLI tool is available on the system

Parameters:

  • cli_name (String)

    Name of the CLI tool

Returns:

  • (Boolean)

    true if the tool is found in PATH



15
16
17
# File 'lib/ace/llm/providers/cli/atoms/provider_detector.rb', line 15

def self.available?(cli_name)
  system("which", cli_name, out: File::NULL, err: File::NULL)
end

.extract_version(output) ⇒ String

Extract version number from command output

Parameters:

  • output (String)

    Raw command output

Returns:

  • (String)

    Extracted version or first line



34
35
36
37
38
39
40
41
42
# File 'lib/ace/llm/providers/cli/atoms/provider_detector.rb', line 34

def self.extract_version(output)
  if output =~ /(\d+\.\d+\.\d+)/
    $1
  elsif output =~ /v(\d+\.\d+)/
    $1
  else
    output.lines.first&.strip || "Unknown"
  end
end

.version(check_cmd) ⇒ String

Get the version of a CLI tool

Parameters:

  • check_cmd (Array<String>)

    Command to run for version check

Returns:

  • (String)

    Version string or “Unknown”



22
23
24
25
26
27
28
29
# File 'lib/ace/llm/providers/cli/atoms/provider_detector.rb', line 22

def self.version(check_cmd)
  stdout, _, status = Open3.capture3(*check_cmd)
  return "Unknown" unless status.success?

  extract_version(stdout)
rescue Errno::ENOENT, Errno::EACCES
  "Unknown"
end