Class: AgentSettings::Adapters::Codex

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

Overview

Adapter for Codex agent configuration.

Codex stores configuration in TOML files:

  • Global: ~/.codex/config.toml (user-level config)
  • Project: .codex/config.toml (project-level config, trusted only)
  • System: /etc/codex/config.toml (system-level config)

Codex has a unique "trust" model - project config is only used for trusted projects. Untrusted projects will have a warning and no project layer.

Environment variable CODEX_HOME can override the home directory where the global config is located.

Examples:

Trusted project

adapter = Codex.new
layers = adapter.layers(dir: "/work/my_app", env: ENV, trusted: true)
layers.count  #=> includes project layer

Untrusted project

layers = adapter.layers(dir: "/untrusted", env: ENV, trusted: false)
adapter.warnings(...)  #=> ["Project config ignored for untrusted project"]

Instance Method Summary collapse

Instance Method Details

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

Get environment variable overrides for Codex.

Checks for CODEX_HOME environment variable. When set, it changes the base directory for the global config (from ~ to the specified path).

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



52
53
54
# File 'lib/agent_settings/adapters/codex.rb', line 52

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 Codex.

Returns an array of Location objects for global, system (if exists), and project (if trusted) configs. Project config is excluded for untrusted projects.

Parameters:

  • dir (String)

    project directory path

  • env (Hash)

    environment variables hash (CODEX_HOME is used)

  • trusted (Boolean)

    whether the project is trusted

Returns:

  • (Array<Location>)

    config layers in precedence order



39
40
41
# File 'lib/agent_settings/adapters/codex.rb', line 39

def layers(dir:, env:, trusted:)
  build_layers(dir, env, trusted)
end

#warnings(dir:, env:, trusted:) ⇒ Array<String>

Get warnings for Codex configuration.

Returns a warning if the project is untrusted but has a config file. This helps users understand why their project config is being ignored.

Parameters:

  • dir (String)

    project directory path

  • env (Hash)

    environment variables hash (unused)

  • trusted (Boolean)

    whether the project is trusted

Returns:

  • (Array<String>)

    warning messages



65
66
67
68
69
70
71
# File 'lib/agent_settings/adapters/codex.rb', line 65

def warnings(dir:, env:, trusted:) # rubocop:disable Lint/UnusedMethodArgument
  warnings = []
  if !trusted && File.exist?(File.join(dir, ".codex", "config.toml"))
    warnings << "Project config ignored for untrusted project"
  end
  warnings
end