Module: AgentSettings
- Defined in:
- lib/agent_settings.rb,
lib/agent_settings/version.rb,
lib/agent_settings/location.rb,
lib/agent_settings/registry.rb,
lib/agent_settings/env_override.rb,
lib/agent_settings/adapters/codex.rb,
lib/agent_settings/adapters/claude.rb,
lib/agent_settings/adapters/opencode.rb,
lib/agent_settings/agent_config_path.rb,
lib/agent_settings/location_discovery.rb
Overview
Discover config locations for Claude Code, OpenCode, and Codex.
This gem provides a clean interface to find where agent configuration files are located, whether they exist, and which one is currently effective based on precedence rules and environment variable overrides.
Trusted vs Untrusted Projects
The trusted parameter controls whether project-level config is included
in resolution. This is a security feature for Codex:
- Trusted projects (
trusted: true): Project config is included in resolution. Use this for projects you own or have reviewed. - Untrusted projects (
trusted: false): Project config is ignored for Codex. This prevents untrusted code repositories from injecting malicious configuration. A warning is added if a.codex/config.tomlfile exists but is ignored.
Claude Code and OpenCode do not use the trust model - their project configs
are always included regardless of the trusted parameter.
Defined Under Namespace
Modules: Adapters, LocationDiscovery, Registry Classes: AgentConfigPath, EnvOverride, Error, Location, UnknownAgentError
Constant Summary collapse
- VERSION =
Current gem version.
"0.1.1"
Class Method Summary collapse
-
.all(dir:, env: ENV, trusted: true) ⇒ Hash{Symbol => AgentConfigPath}
Resolve config paths for all supported agents.
-
.global(agent, env: ENV, dir: Dir.pwd, trusted: true) ⇒ Location?
Get the global config location for an agent.
-
.project(agent, dir:, env: ENV, trusted: true) ⇒ Location?
Get the project-level config location for an agent.
-
.resolve(agent, dir:, env: ENV, trusted: true) ⇒ AgentConfigPath
Resolve the complete config path information for an agent.
Class Method Details
.all(dir:, env: ENV, trusted: true) ⇒ Hash{Symbol => AgentConfigPath}
Resolve config paths for all supported agents.
Returns a hash mapping each agent symbol to its AgentConfigPath result. Useful for getting an overview of all agent configurations at once.
148 149 150 |
# File 'lib/agent_settings.rb', line 148 def all(dir:, env: ENV, trusted: true) LocationDiscovery.all(dir: dir, env: env, trusted: trusted) end |
.global(agent, env: ENV, dir: Dir.pwd, trusted: true) ⇒ Location?
Get the global config location for an agent.
The global config is typically stored in the user's home directory and applies across all projects.
71 72 73 |
# File 'lib/agent_settings.rb', line 71 def global(agent, env: ENV, dir: Dir.pwd, trusted: true) LocationDiscovery.global(agent, env: env, dir: dir, trusted: trusted) end |
.project(agent, dir:, env: ENV, trusted: true) ⇒ Location?
Get the project-level config location for an agent.
Project configs are stored within the project directory and apply only to that specific project.
Note: For Codex, project config is ignored when trusted: false.
This is a security measure to prevent untrusted repositories from
injecting malicious configuration. In this case, returns nil and
a warning is added to the resolve result.
95 96 97 |
# File 'lib/agent_settings.rb', line 95 def project(agent, dir:, env: ENV, trusted: true) LocationDiscovery.project(agent, dir: dir, env: env, trusted: trusted) end |
.resolve(agent, dir:, env: ENV, trusted: true) ⇒ AgentConfigPath
Resolve the complete config path information for an agent.
This is the primary method for discovering all config-related information for an agent. It returns an AgentConfigPath object containing the effective config location, global and project locations, all layers by precedence, environment variable overrides, and any warnings.
The effective location is determined by:
- Active environment variable overrides (highest precedence)
- First existing layer in precedence order
- First layer if none exist
128 129 130 |
# File 'lib/agent_settings.rb', line 128 def resolve(agent, dir:, env: ENV, trusted: true) LocationDiscovery.resolve(agent, dir: dir, env: env, trusted: trusted) end |