Module: Axn::Tools::AdapterRoots

Defined in:
lib/axn/tools/adapter_roots.rb

Overview

Mixed into an adapter's config module (which already extend Axn::Configurable) to declare a validated tool_roots directory list. Each adapter names the directories it consumes; the registry reads <adapter>.config.tool_roots to compute directory-based membership. Validation reuses core's single broad-path guard so no adapter can widen a root to app/, ., actions, or a .. traversal that would bulk-expose every business action.

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



11
12
13
# File 'lib/axn/tools/adapter_roots.rb', line 11

def self.extended(base)
  base.setting :tool_roots, default: [], validate: ->(value) { AdapterRoots.validate!(value) }
end

.validate!(value) ⇒ Object

Returns true when valid; raises ArgumentError with a specific message otherwise. Raising from a validate: lambda propagates through Setting#validate! (Axn::Configurable), so a bad root fails at assignment rather than with the generic "got invalid value".



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/axn/tools/adapter_roots.rb', line 18

def self.validate!(value)
  unless value.is_a?(Array) && value.all? { |entry| entry.is_a?(String) }
    raise ArgumentError, "tool_roots must be an Array of Strings; got #{value.inspect}"
  end

  value.each do |entry|
    next unless Axn::Configuration.broad_tool_root?(entry)

    raise ArgumentError,
          "tool_roots entry #{entry.inspect} is too broad: it resolves to the project root, escapes " \
          "via `..`, or ends in a broad directory (`actions`/`app`) that would auto-expose every " \
          "business action. Use a dedicated narrow subdir such as `agent_tools` or `actions/tools`."
  end

  true
end