class LittleGhost::CodeMode::Catalog
Normalizes a trusted Tool catalog for a guest language and rejects names that would collide or shadow code-mode controls.
Attributes
Frozen normalized Tool definitions in declaration order.
Public Class Methods
# File lib/little_ghost/code_mode/catalog.rb, line 13 def initialize(specifications, normalize:, reserved: %w[exec wait stop]) aliases = {} @definitions = Array(specifications).map do |specification| canonical_name = value(specification, :name).to_s name = normalize.call(canonical_name).to_s if reserved.include?(name) raise ConfigurationError, "Code-mode tool name #{canonical_name.inspect} conflicts with reserved tool #{name.inspect}" end if aliases.key?(name) raise ConfigurationError, "Code-mode tool names #{aliases.fetch(name).inspect} and #{canonical_name.inspect} both normalize to #{name.inspect}" end aliases[name] = canonical_name { "name" => name.freeze, "canonical_name" => canonical_name.freeze, "description" => value(specification, :description, "").to_s.freeze, "input_schema" => value(specification, :input_schema, {}).freeze, "specification" => specification }.freeze end.freeze @by_name = @definitions.to_h { |definition| [definition.fetch("name"), definition] }.freeze end
Normalizes trusted Tool specifications with normalize. Names in reserved and names that collide after normalization are rejected.
Public Instance Methods
Source
# File lib/little_ghost/code_mode/catalog.rb, line 39 def fetch(name) = @by_name.fetch(name.to_s)
Returns the normalized definition for name.
Source
# File lib/little_ghost/code_mode/catalog.rb, line 41 def key?(name) = @by_name.key?(name.to_s)
Indicates whether name is present in the catalog.