Class: AgentC::Tools::DirGlob
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- AgentC::Tools::DirGlob
- Defined in:
- lib/agent_c/tools/dir_glob.rb
Instance Attribute Summary collapse
-
#workspace_dir ⇒ Object
readonly
Returns the value of attribute workspace_dir.
Instance Method Summary collapse
- #execute(glob_pattern:, **params) ⇒ Object
-
#initialize(workspace_dir: nil) ⇒ DirGlob
constructor
A new instance of DirGlob.
Constructor Details
#initialize(workspace_dir: nil) ⇒ DirGlob
Returns a new instance of DirGlob.
16 17 18 19 |
# File 'lib/agent_c/tools/dir_glob.rb', line 16 def initialize(workspace_dir: nil, **) raise ArgumentError, "workspace_dir is required" unless workspace_dir @workspace_dir = workspace_dir end |
Instance Attribute Details
#workspace_dir ⇒ Object (readonly)
Returns the value of attribute workspace_dir.
15 16 17 |
# File 'lib/agent_c/tools/dir_glob.rb', line 15 def workspace_dir @workspace_dir end |
Instance Method Details
#execute(glob_pattern:, **params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/agent_c/tools/dir_glob.rb', line 21 def execute(glob_pattern:, **params) if params.any? return "The following params were passed but are not allowed: #{params.keys.join(",")}" end unless Paths.allowed?(workspace_dir, glob_pattern) return "Path: #{glob_pattern} not acceptable. Must be a child of directory: #{workspace_dir}." end results = ( Dir .glob(File.join(workspace_dir, glob_pattern)) .select { Paths.allowed?(workspace_dir, _1) } ) warning = ( if results.count > 30 "Returning 30 of #{results.count} results" end ) [warning, results.take(30).to_json].compact.join("\n") end |