Class: RubyLLM::Toolbox::Tools::TomlQuery

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_llm/toolbox/tools/toml_query.rb

Overview

SAFE. Parses TOML (from a file in fs_root or an inline string) and either pretty-prints it (as JSON, for readability) or extracts a value with a dot/bracket path. In-process, read-only — handy for Cargo.toml, pyproject.toml, and similar config.

Path syntax matches json_query / yaml_query: dependencies.serde.version, products.name, products[].name

Constant Summary collapse

MAX_BYTES =
5 * 1024 * 1024

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#call, exec_tool!, exec_tool?, #initialize, #name

Constructor Details

This class inherits a constructor from RubyLLM::Toolbox::Base

Instance Method Details

#execute(path: nil, toml: nil, query: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_llm/toolbox/tools/toml_query.rb', line 36

def execute(path: nil, toml: nil, query: nil)
  source = load_source(path, toml)
  return source if source.is_a?(Hash) # error

  data = Toml.parse(source)
  result = query.to_s.strip.empty? ? data : DataPath.query(data, query)
  truncate(JSON.pretty_generate(result))
rescue Safety::PathJail::Jailbreak => e
  error(e.message, code: :path_denied)
rescue Toml::ParseError => e
  error("invalid TOML: #{e.message}", code: :bad_toml)
rescue DataPath::Error => e
  error(e.message, code: :bad_query)
end