Module: AgentSettings::LocationDiscovery Private
- Defined in:
- lib/agent_settings/location_discovery.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Internal module for discovering agent config locations.
LocationDiscovery contains the core logic for finding and resolving where agent configuration files are located. It uses adapters (one per agent) to handle agent-specific rules, then applies common precedence logic to determine the effective configuration.
This module is used internally by the AgentSettings public API methods. You typically don't need to call it directly.
Class Method Summary collapse
-
.all(dir:, env:, trusted:) ⇒ Hash{Symbol => AgentConfigPath}
private
Resolve config paths for all supported agents.
-
.find_effective(layers, env_overrides) ⇒ Location?
private
Determine the effective config location.
-
.global(agent, env:, dir:, trusted:) ⇒ Location?
private
Find the global config location for an agent.
-
.project(agent, dir:, env:, trusted:) ⇒ Location?
private
Find the project config location for an agent.
-
.resolve(agent, dir:, env:, trusted:) ⇒ AgentConfigPath
private
Resolve complete config path information for an agent.
Class Method Details
.all(dir:, env:, trusted:) ⇒ Hash{Symbol => AgentConfigPath}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve config paths for all supported agents.
Iterates through all known agents and resolves each one, returning a hash mapping agent symbols to AgentConfigPath objects.
96 97 98 99 100 |
# File 'lib/agent_settings/location_discovery.rb', line 96 def all(dir:, env:, trusted:) Registry::AGENTS.to_h do |agent| [agent, resolve(agent, dir: dir, env: env, trusted: trusted)] end end |
.find_effective(layers, env_overrides) ⇒ Location?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine the effective config location.
The effective location is determined by precedence:
- If an environment override is active, convert it to a Location
- Otherwise, use the first existing layer
- If no layers exist, use the first layer (even though it doesn't exist)
112 113 114 115 116 117 |
# File 'lib/agent_settings/location_discovery.rb', line 112 def find_effective(layers, env_overrides) active_override = env_overrides.find(&:active?) return active_override.to_location if active_override layers.find(&:active?) || layers.first end |
.global(agent, env:, dir:, trusted:) ⇒ Location?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find the global config location for an agent.
Queries the appropriate adapter and extracts the global-scoped location from the layers.
28 29 30 31 32 |
# File 'lib/agent_settings/location_discovery.rb', line 28 def global(agent, env:, dir:, trusted:) adapter = Registry.adapter(agent) layers = adapter.layers(dir: dir, env: env, trusted: trusted) layers.find { |l| l.scope == :global } end |
.project(agent, dir:, env:, trusted:) ⇒ Location?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find the project config location for an agent.
Queries the appropriate adapter and extracts the project-scoped location from the layers. Note that some agents (like Codex) may not return a project location for untrusted projects.
45 46 47 48 49 |
# File 'lib/agent_settings/location_discovery.rb', line 45 def project(agent, dir:, env:, trusted:) adapter = Registry.adapter(agent) layers = adapter.layers(dir: dir, env: env, trusted: trusted) layers.find { |l| l.scope == :project } end |
.resolve(agent, dir:, env:, trusted:) ⇒ AgentConfigPath
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resolve complete config path information for an agent.
This is the main discovery method. It:
- Gets the appropriate adapter for the agent
- Retrieves all config layers from the adapter
- Retrieves any environment variable overrides
- Retrieves any warnings
- Determines the effective location based on precedence
- Builds and returns an AgentConfigPath with all information
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/agent_settings/location_discovery.rb', line 66 def resolve(agent, dir:, env:, trusted:) # rubocop:disable Metrics/MethodLength -- orchestrates adapter calls and builds complete AgentConfigPath adapter = Registry.adapter(agent) layers = adapter.layers(dir: dir, env: env, trusted: trusted) env_overrides = adapter.env_overrides(dir: dir, env: env, trusted: trusted) warnings = adapter.warnings(dir: dir, env: env, trusted: trusted) effective = find_effective(layers, env_overrides) global = layers.find { |l| l.scope == :global } project = layers.find { |l| l.scope == :project } AgentConfigPath.new( agent: agent, effective: effective, global: global, project: project, layers: layers, env_overrides: env_overrides, warnings: warnings ) end |