Class: AgentSettings::Adapters::Opencode

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_settings/adapters/opencode.rb

Overview

Adapter for OpenCode agent configuration.

OpenCode stores configuration in JSON files:

  • Global: ~/.config/opencode/opencode.json (user-level config)
  • Project: opencode.json (discovered by walking up from project directory)

OpenCode supports multiple environment variable overrides:

  • OPENCODE_CONFIG: Direct path to config file
  • OPENCODE_CONFIG_DIR: Directory containing opencode.json
  • OPENCODE_CONFIG_CONTENT: Inline JSON config content

The project config uses discovery - it walks up from the provided directory looking for opencode.json, similar to how git finds .git.

Examples:

adapter = Opencode.new
layers = adapter.layers(dir: "/work/my_app", env: ENV, trusted: true)
env_overrides = adapter.env_overrides(dir: "/work/my_app", env: ENV, trusted: true)

Instance Method Summary collapse

Instance Method Details

#env_overrides(dir:, env:, trusted:) ⇒ Array<EnvOverride>

Get environment variable overrides for OpenCode.

Checks for three environment variables:

  • OPENCODE_CONFIG: Path to config file (active if file exists)
  • OPENCODE_CONFIG_DIR: Directory containing opencode.json
  • OPENCODE_CONFIG_CONTENT: Inline JSON (always active if set)

Parameters:

  • dir (String)

    project directory path (unused)

  • env (Hash)

    environment variables hash

  • trusted (Boolean)

    whether the project is trusted (unused)

Returns:

  • (Array<EnvOverride>)

    detected environment overrides



50
51
52
# File 'lib/agent_settings/adapters/opencode.rb', line 50

def env_overrides(dir:, env:, trusted:) # rubocop:disable Lint/UnusedMethodArgument
  build_env_overrides(env)
end

#layers(dir:, env:, trusted:) ⇒ Array<Location>

Get all config layers for OpenCode.

Returns an array of Location objects for global and project configs. Project config is discovered by walking up the directory tree from the provided dir.

Parameters:

  • dir (String)

    project directory path (starting point for discovery)

  • env (Hash)

    environment variables hash (unused for layers)

  • trusted (Boolean)

    whether the project is trusted (unused)

Returns:

  • (Array<Location>)

    config layers in precedence order



35
36
37
# File 'lib/agent_settings/adapters/opencode.rb', line 35

def layers(dir:, env:, trusted:) # rubocop:disable Lint/UnusedMethodArgument
  build_layers(dir)
end

#warningsArray<String>

Get warnings for OpenCode configuration.

OpenCode doesn't produce any warnings currently.

Returns:

  • (Array<String>)

    empty array



59
# File 'lib/agent_settings/adapters/opencode.rb', line 59

def warnings(*) = []