Class: OllamaAgent::Runtime::KernelToolSeed::PlanningSandbox
- Inherits:
-
Object
- Object
- OllamaAgent::Runtime::KernelToolSeed::PlanningSandbox
- Defined in:
- lib/ollama_agent/runtime/kernel_tool_seed.rb
Overview
Read-only planning helpers scoped to workspace_root (no Agent / TTY).
Instance Method Summary collapse
-
#initialize(root) ⇒ PlanningSandbox
constructor
A new instance of PlanningSandbox.
- #list_files(directory: ".", max_entries: 100, max_depth: nil, **_ignored) ⇒ Object
- #read_file(path:, start_line: nil, end_line: nil, **_ignored) ⇒ Object
- #search_files(pattern:, directory: ".", **_ignored) ⇒ Object
Constructor Details
#initialize(root) ⇒ PlanningSandbox
Returns a new instance of PlanningSandbox.
101 102 103 104 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 101 def initialize(root) @root = File.(root.to_s) @guard = Security::ResourceGuard.new(root: @root) end |
Instance Method Details
#list_files(directory: ".", max_entries: 100, max_depth: nil, **_ignored) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 119 def list_files(directory: ".", max_entries: 100, max_depth: nil, **_ignored) dir = directory.to_s.empty? ? "." : directory.to_s base = File.(dir, @root) return "path not allowed" unless @guard.allow?(base) return "Not a directory: #{dir}" unless File.directory?(base) cap = clamp_list_limit(max_entries) paths = collect_relative_paths(base, cap, max_depth: max_depth) return "(no files listed)" if paths.empty? body = paths.sort.join("\n") return body if paths.size < cap "#{body}\n(list truncated at #{cap} entries; pass max_entries or narrow directory)" end |
#read_file(path:, start_line: nil, end_line: nil, **_ignored) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 106 def read_file(path:, start_line: nil, end_line: nil, **_ignored) abs = File.(path.to_s, @root) return "path not allowed" unless @guard.allow?(abs) return "Error reading file: not a file" unless File.file?(abs) return read_line_range(abs, start_line, end_line) if start_line || end_line return "Error reading file: file too large (max #{MAX_READ_BYTES} bytes)" if File.size(abs) > MAX_READ_BYTES File.read(abs, encoding: Encoding::UTF_8) rescue Errno::ENOENT => e "Error reading file: #{e.}" end |
#search_files(pattern:, directory: ".", **_ignored) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ollama_agent/runtime/kernel_tool_seed.rb', line 135 def search_files(pattern:, directory: ".", **_ignored) pat = pattern.to_s return "Error: search_files requires a non-empty pattern" if pat.strip.empty? dir = directory.to_s.empty? ? "." : directory.to_s abs = File.(dir, @root) return "path not allowed" unless @guard.allow?(abs) rg = SearchBackend.rg_executable grep = SearchBackend.grep_executable return SearchTextBackend. if rg.nil? && grep.nil? SearchTextBackend.search(ripgrep_bin: rg, grep_bin: grep, pattern: pat, target: abs) end |