Class: Aidp::Harness::ProviderInfo

Inherits:
Object
  • Object
show all
Includes:
RescueLogging
Defined in:
lib/aidp/harness/provider_info.rb

Overview

Stores detailed information about AI providers gathered from their CLI tools

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RescueLogging

__log_rescue_impl, log_rescue, #log_rescue

Constructor Details

#initialize(provider_name, root_dir = nil) ⇒ ProviderInfo

Returns a new instance of ProviderInfo.



17
18
19
20
21
22
# File 'lib/aidp/harness/provider_info.rb', line 17

def initialize(provider_name, root_dir = nil)
  @provider_name = provider_name
  @root_dir = root_dir || Dir.pwd
  @info_file_path = File.join(@root_dir, ".aidp", "providers", "#{provider_name}_info.yml")
  ensure_directory_exists
end

Instance Attribute Details

#info_file_pathObject (readonly)

Returns the value of attribute info_file_path.



15
16
17
# File 'lib/aidp/harness/provider_info.rb', line 15

def info_file_path
  @info_file_path
end

#provider_nameObject (readonly)

Returns the value of attribute provider_name.



15
16
17
# File 'lib/aidp/harness/provider_info.rb', line 15

def provider_name
  @provider_name
end

Instance Method Details

#auth_methodObject

Get authentication method



97
98
99
100
101
102
# File 'lib/aidp/harness/provider_info.rb', line 97

def auth_method
  info = load_info
  return nil unless info

  info[:auth_method]
end

#available_flagsObject

Get available flags/options



105
106
107
108
109
110
# File 'lib/aidp/harness/provider_info.rb', line 105

def available_flags
  info = load_info
  return {} unless info

  info[:flags] || {}
end

#gather_infoObject

Gather information about the provider by introspecting its CLI



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/aidp/harness/provider_info.rb', line 25

def gather_info
  info = {
    provider: @provider_name,
    last_checked: Time.now.iso8601,
    cli_available: false,
    help_output: nil,
    capabilities: {},
    permission_modes: [],
    mcp_support: false,
    mcp_servers: [],
    auth_method: nil,
    flags: {}
  }

  # Try to get help output from the provider CLI
  help_output = fetch_help_output
  if help_output
    info[:cli_available] = true
    info[:help_output] = help_output
    info.merge!(parse_help_output(help_output))
  end

  # Try to get MCP server list if supported
  if info[:mcp_support]
    mcp_servers = fetch_mcp_servers
    info[:mcp_servers] = mcp_servers if mcp_servers
  end

  save_info(info)
  info
end

#has_mcp_servers?Boolean

Check if provider has MCP servers configured

Returns:

  • (Boolean)


121
122
123
# File 'lib/aidp/harness/provider_info.rb', line 121

def has_mcp_servers?
  mcp_servers.any?
end

#info(force_refresh: false, max_age: 86400) ⇒ Object

Get provider info, refreshing if needed



69
70
71
72
73
74
75
76
77
78
# File 'lib/aidp/harness/provider_info.rb', line 69

def info(force_refresh: false, max_age: 86400)
  existing_info = load_info

  # Refresh if forced, missing, or stale
  if force_refresh || existing_info.nil? || info_stale?(existing_info, max_age)
    gather_info
  else
    existing_info
  end
end

#load_infoObject

Load stored provider info



58
59
60
61
62
63
64
65
66
# File 'lib/aidp/harness/provider_info.rb', line 58

def load_info
  return nil unless File.exist?(@info_file_path)

  YAML.safe_load_file(@info_file_path, permitted_classes: [Time, Symbol])
rescue => e
  log_rescue(e, component: "provider_info", action: "load_yaml", fallback: nil, provider: @provider_name, path: @info_file_path)
  warn "Failed to load provider info for #{@provider_name}: #{e.message}"
  nil
end

#mcp_serversObject

Get configured MCP servers



113
114
115
116
117
118
# File 'lib/aidp/harness/provider_info.rb', line 113

def mcp_servers
  info = load_info
  return [] unless info

  info[:mcp_servers] || []
end

#permission_modesObject

Get permission modes available



89
90
91
92
93
94
# File 'lib/aidp/harness/provider_info.rb', line 89

def permission_modes
  info = load_info
  return [] unless info

  info[:permission_modes] || []
end

#supports_mcp?Boolean

Check if provider supports MCP servers

Returns:

  • (Boolean)


81
82
83
84
85
86
# File 'lib/aidp/harness/provider_info.rb', line 81

def supports_mcp?
  info = load_info
  return false unless info

  info[:mcp_support] == true
end