Class: AgentHarness::Providers::Aider

Inherits:
Base
  • Object
show all
Includes:
TokenUsageParsing
Defined in:
lib/agent_harness/providers/aider.rb

Overview

Aider AI coding assistant provider

Provides integration with the Aider CLI tool.

Defined Under Namespace

Classes: HistoryFileHandle

Constant Summary collapse

UV_VERSION =
"0.8.17"
SUPPORTED_CLI_VERSION =
"0.86.2"
SUPPORTED_CLI_REQUIREMENT =
Gem::Requirement.new(">= #{SUPPORTED_CLI_VERSION}", "< 0.87.0").freeze
PYTHON_VERSION =
"python3.12"
BINARY_PATH =
"/usr/local/bin/aider"
UV_TOOL_ENV =
{
  "UV_TOOL_BIN_DIR" => "/usr/local/bin",
  "UV_TOOL_DIR" => "/opt/uv/tools",
  "UV_PYTHON_INSTALL_DIR" => "/opt/uv/python"
}.freeze

Constants inherited from Base

Base::COMMON_ERROR_PATTERNS, Base::DEFAULT_SMOKE_TEST_CONTRACT

Instance Attribute Summary

Attributes inherited from Base

#config, #executor, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#configure, #initialize, #sandboxed_environment?

Methods included from Adapter

#auth_type, #build_mcp_flags, #dangerous_mode_flags, #fetch_mcp_servers, #health_status, included, metadata_package_name, normalize_metadata_installation, normalize_metadata_source_type, normalize_metadata_version_requirement, #parse_rate_limit_reset, #smoke_test, #smoke_test_contract, #supported_mcp_transports, #supports_dangerous_mode?, #supports_mcp?, #supports_text_mode?, #supports_tool_control?, #validate_config, #validate_mcp_servers!

Constructor Details

This class inherits a constructor from AgentHarness::Providers::Base

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/agent_harness/providers/aider.rb', line 36

def available?
  executor = AgentHarness.configuration.command_executor
  !!executor.which(binary_name)
end

.binary_nameObject



32
33
34
# File 'lib/agent_harness/providers/aider.rb', line 32

def binary_name
  "aider"
end

.discover_modelsObject



61
62
63
64
65
66
67
68
69
# File 'lib/agent_harness/providers/aider.rb', line 61

def discover_models
  return [] unless available?

  # Aider supports multiple model providers
  [
    {name: "gpt-4o", family: "gpt-4o", tier: "standard", provider: "aider"},
    {name: "claude-3-5-sonnet", family: "claude-3-5-sonnet", tier: "standard", provider: "aider"}
  ]
end

.firewall_requirementsObject



41
42
43
44
45
46
47
48
49
# File 'lib/agent_harness/providers/aider.rb', line 41

def firewall_requirements
  {
    domains: [
      "api.openai.com",
      "api.anthropic.com"
    ],
    ip_ranges: []
  }
end

.installation_contract(version: SUPPORTED_CLI_VERSION) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/agent_harness/providers/aider.rb', line 71

def installation_contract(version: SUPPORTED_CLI_VERSION)
  version = version.strip if version.respond_to?(:strip)

  unless version.is_a?(String) && !version.empty?
    raise ArgumentError,
      "Unsupported Aider CLI version #{version.inspect}; " \
      "supported versions must satisfy #{SUPPORTED_CLI_REQUIREMENT}"
  end

  parsed_version = begin
    Gem::Version.new(version)
  rescue ArgumentError
    raise ArgumentError,
      "Unsupported Aider CLI version #{version.inspect}; " \
      "supported versions must satisfy #{SUPPORTED_CLI_REQUIREMENT}"
  end

  unless SUPPORTED_CLI_REQUIREMENT.satisfied_by?(parsed_version)
    raise ArgumentError,
      "Unsupported Aider CLI version #{version.inspect}; " \
      "supported versions must satisfy #{SUPPORTED_CLI_REQUIREMENT}"
  end

  default_package = "aider-chat==#{version}".freeze
  bootstrap_command = [
    "python3", "-m", "pip", "install", "--no-cache-dir", "--break-system-packages", "uv==#{UV_VERSION}"
  ].freeze
  install_command_prefix = [
    "uv", "tool", "install", "--force", "--python", PYTHON_VERSION, "--with", "pip"
  ].freeze
  install_command = (install_command_prefix + [default_package]).freeze
  supported_versions = [version].freeze
  version_requirement = SUPPORTED_CLI_REQUIREMENT.requirements
    .map { |op, ver| "#{op} #{ver}".freeze }
    .freeze

  contract = {
    source: :uv_tool,
    bootstrap_source: :pip,
    bootstrap_package: "uv==#{UV_VERSION}",
    bootstrap_commands: [bootstrap_command].freeze,
    install_environment: UV_TOOL_ENV,
    package: default_package,
    package_name: "aider-chat",
    version: version,
    version_format: "%{package_name}==%{version}",
    version_requirement: version_requirement,
    binary_name: binary_name,
    binary_path: BINARY_PATH,
    install_command_prefix: install_command_prefix,
    install_command: install_command,
    supported_versions: supported_versions
  }

  contract.each_value do |value|
    value.freeze if value.is_a?(String)
  end
  contract.freeze
end

.instruction_file_pathsObject



51
52
53
54
55
56
57
58
59
# File 'lib/agent_harness/providers/aider.rb', line 51

def instruction_file_paths
  [
    {
      path: ".aider.conf.yml",
      description: "Aider configuration file",
      symlink: false
    }
  ]
end

.provider_nameObject



28
29
30
# File 'lib/agent_harness/providers/aider.rb', line 28

def provider_name
  :aider
end

.smoke_test_contractObject



131
132
133
# File 'lib/agent_harness/providers/aider.rb', line 131

def smoke_test_contract
  Base::DEFAULT_SMOKE_TEST_CONTRACT
end

Instance Method Details

#capabilitiesObject



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/agent_harness/providers/aider.rb', line 161

def capabilities
  {
    streaming: true,
    file_upload: true,
    vision: false,
    tool_use: true,
    json_mode: false,
    mcp: false,
    dangerous_mode: false
  }
end

#configuration_schemaObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/agent_harness/providers/aider.rb', line 144

def configuration_schema
  {
    fields: [
      {
        name: :model,
        type: :string,
        label: "Model",
        required: false,
        hint: "Model identifier (supports OpenAI, Anthropic, and other model names)",
        accepts_arbitrary: true
      }
    ],
    auth_modes: [:api_key],
    openai_compatible: false
  }
end

#display_nameObject



140
141
142
# File 'lib/agent_harness/providers/aider.rb', line 140

def display_name
  "Aider"
end

#error_patternsObject



173
174
175
176
177
178
# File 'lib/agent_harness/providers/aider.rb', line 173

def error_patterns
  COMMON_ERROR_PATTERNS.merge(
    auth_expired: COMMON_ERROR_PATTERNS[:auth_expired] + [/incorrect.*api.*key/i],
    transient: COMMON_ERROR_PATTERNS[:transient] + [/connection.*reset/i]
  )
end

#execution_semanticsObject



180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/agent_harness/providers/aider.rb', line 180

def execution_semantics
  {
    prompt_delivery: :flag,
    output_format: :text,
    sandbox_aware: false,
    uses_subcommand: false,
    non_interactive_flag: "--yes",
    legitimate_exit_codes: [0],
    stderr_is_diagnostic: true,
    parses_rate_limit_reset: false
  }
end

#nameObject



136
137
138
# File 'lib/agent_harness/providers/aider.rb', line 136

def name
  "aider"
end

#send_message(prompt:, **options) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/agent_harness/providers/aider.rb', line 206

def send_message(prompt:, **options)
  log_debug("send_message_start", prompt_length: prompt.length, options: options.keys)

  options = normalize_provider_runtime(options)
  runtime = options[:provider_runtime]

  options = normalize_mcp_servers(options)
  validate_mcp_servers!(options[:mcp_servers]) if options[:mcp_servers]&.any?

  timeout = options[:timeout] || @config.timeout || default_timeout
  raise TimeoutError, "Command timed out before execution started" if timeout <= 0

  start_time = Time.now
  llm_history_path = prepare_llm_history_file!
  command = build_command(prompt, options.merge(llm_history_path: llm_history_path))
  preparation = build_execution_preparation(options)
  remaining_timeout = timeout - (Time.now - start_time)
  raise TimeoutError, "Command timed out before execution started" if remaining_timeout <= 0

  result = execute_with_timeout(
    command,
    timeout: remaining_timeout,
    env: build_env(options),
    preparation: preparation,
    **command_execution_options(options)
  )
  duration = Time.now - start_time

  response = parse_response(result, duration: duration, llm_history_path: llm_history_path)
  effective_runtime_model = normalized_model_name(runtime&.model)
  if effective_runtime_model
    response = Response.new(
      output: response.output,
      exit_code: response.exit_code,
      duration: response.duration,
      provider: response.provider,
      model: effective_runtime_model,
      tokens: response.tokens,
      metadata: response.,
      error: response.error
    )
  end

  track_tokens(response) if response.tokens

  log_debug("send_message_complete", duration: duration, tokens: response.tokens)

  response
rescue McpConfigurationError, McpUnsupportedError, McpTransportUnsupportedError
  raise
rescue => e
  handle_error(e, prompt: prompt, options: options)
ensure
  cleanup_llm_history_file!(llm_history_path)
end

#session_flags(session_id) ⇒ Object



197
198
199
200
# File 'lib/agent_harness/providers/aider.rb', line 197

def session_flags(session_id)
  return [] unless session_id && !session_id.empty?
  ["--restore-chat-history", session_id]
end

#supports_sessions?Boolean

Returns:

  • (Boolean)


193
194
195
# File 'lib/agent_harness/providers/aider.rb', line 193

def supports_sessions?
  true
end

#supports_token_counting?Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/agent_harness/providers/aider.rb', line 202

def supports_token_counting?
  true
end