Class: AgentHarness::Providers::Opencode

Inherits:
Base
  • Object
show all
Defined in:
lib/agent_harness/providers/opencode.rb

Overview

OpenCode CLI provider

Provides integration with the OpenCode CLI tool.

Constant Summary collapse

CLI_PACKAGE =
"opencode-ai"
SUPPORTED_CLI_VERSION =
"1.3.2"
SUPPORTED_CLI_REQUIREMENT =
Gem::Requirement.new(">= #{SUPPORTED_CLI_VERSION}", "< 1.4.0").freeze
INSTALL_COMMAND_PREFIX =
["npm", "install", "-g", "--ignore-scripts"].freeze
SUPPORTED_CLI_VERSIONS =
[SUPPORTED_CLI_VERSION].freeze
VERSION_REQUIREMENT_STRINGS =
SUPPORTED_CLI_REQUIREMENT.requirements
.map { |op, ver| "#{op} #{ver}".freeze }
.freeze
DEFAULT_INSTALLATION_CONTRACT =
build_installation_contract(SUPPORTED_CLI_VERSION)

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?, #send_message

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, #send_message, #session_flags, #smoke_test, #smoke_test_contract, #supported_mcp_transports, #supports_dangerous_mode?, #supports_mcp?, #supports_sessions?, #validate_config, #validate_mcp_servers!

Constructor Details

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

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/agent_harness/providers/opencode.rb', line 29

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

.binary_nameObject



25
26
27
# File 'lib/agent_harness/providers/opencode.rb', line 25

def binary_name
  "opencode"
end

.discover_modelsObject



56
57
58
59
# File 'lib/agent_harness/providers/opencode.rb', line 56

def discover_models
  return [] unless available?
  []
end

.firewall_requirementsObject



43
44
45
46
47
48
49
50
# File 'lib/agent_harness/providers/opencode.rb', line 43

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

.install_command(version: SUPPORTED_CLI_VERSION) ⇒ Object



68
69
70
# File 'lib/agent_harness/providers/opencode.rb', line 68

def install_command(version: SUPPORTED_CLI_VERSION)
  installation_contract(version: version)[:install_command]
end

.installation_contract(version: SUPPORTED_CLI_VERSION) ⇒ Object



61
62
63
64
65
66
# File 'lib/agent_harness/providers/opencode.rb', line 61

def installation_contract(version: SUPPORTED_CLI_VERSION)
  normalized_version = normalize_install_version(version)
  return DEFAULT_INSTALLATION_CONTRACT if normalized_version == SUPPORTED_CLI_VERSION

  build_installation_contract(normalized_version)
end

.instruction_file_pathsObject



52
53
54
# File 'lib/agent_harness/providers/opencode.rb', line 52

def instruction_file_paths
  []
end

.provider_metadata_overridesObject



34
35
36
37
38
39
40
41
# File 'lib/agent_harness/providers/opencode.rb', line 34

def 
  {
    auth: {
      service: :openai,
      api_family: :openai_compatible
    }
  }
end

.provider_nameObject



21
22
23
# File 'lib/agent_harness/providers/opencode.rb', line 21

def provider_name
  :opencode
end

.smoke_test_contractObject



72
73
74
# File 'lib/agent_harness/providers/opencode.rb', line 72

def smoke_test_contract
  Base::DEFAULT_SMOKE_TEST_CONTRACT
end

Instance Method Details

#capabilitiesObject



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/agent_harness/providers/opencode.rb', line 138

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

#configuration_schemaObject



130
131
132
133
134
135
136
# File 'lib/agent_harness/providers/opencode.rb', line 130

def configuration_schema
  {
    fields: [],
    auth_modes: [:api_key],
    openai_compatible: true
  }
end

#display_nameObject



126
127
128
# File 'lib/agent_harness/providers/opencode.rb', line 126

def display_name
  "OpenCode CLI"
end

#error_patternsObject



150
151
152
# File 'lib/agent_harness/providers/opencode.rb', line 150

def error_patterns
  COMMON_ERROR_PATTERNS
end

#execution_semanticsObject



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/agent_harness/providers/opencode.rb', line 154

def execution_semantics
  {
    prompt_delivery: :arg,
    output_format: :text,
    sandbox_aware: false,
    uses_subcommand: true,
    non_interactive_flag: nil,
    legitimate_exit_codes: [0],
    stderr_is_diagnostic: true,
    parses_rate_limit_reset: false
  }
end

#nameObject



122
123
124
# File 'lib/agent_harness/providers/opencode.rb', line 122

def name
  "opencode"
end