Module: AgentHarness::Extensions::Loader
- Defined in:
- lib/agent_harness/extensions.rb
Class Method Summary collapse
- .discover(directory) ⇒ Object
- .load(path, adapter: nil) ⇒ Object
- .normalize_adapter(adapter, path) ⇒ Object
- .pi_directory?(path) ⇒ Boolean
Class Method Details
.discover(directory) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/agent_harness/extensions.rb', line 291 def discover(directory) resolved = File.(directory) return [] unless File.directory?(resolved) extensions = [] Dir.glob(File.join(resolved, "*")).sort.each do |child| next unless File.directory?(child) || File.file?(child) begin extensions.concat(load(child)) rescue ConfigurationError next end end extensions end |
.load(path, adapter: nil) ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/agent_harness/extensions.rb', line 254 def load(path, adapter: nil) resolved_path = File.(path) adapter_name = normalize_adapter(adapter, resolved_path) case adapter_name when :pi Adapters::Pi.load(resolved_path) when :skill Adapters::Skill.load(resolved_path) else raise ConfigurationError, "Unknown extension adapter: #{adapter_name.inspect}" end end |
.normalize_adapter(adapter, path) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/agent_harness/extensions.rb', line 268 def normalize_adapter(adapter, path) return adapter.to_sym if adapter return :pi if File.directory?(path) && pi_directory?(path) return :pi if File.file?(path) && File.extname(path).match?(/\A\.(?:[jt]s|json)\z/i) return :skill if File.file?(path) && File.extname(path) == ".md" if File.directory?(path) raise ConfigurationError, "Cannot infer extension adapter for directory: #{path}" end raise ConfigurationError, "Could not infer adapter for extension source: #{path}" end |
.pi_directory?(path) ⇒ Boolean
280 281 282 283 284 285 286 287 288 289 |
# File 'lib/agent_harness/extensions.rb', line 280 def pi_directory?(path) return true if File.exist?(File.join(path, "package.json")) return true if File.exist?(File.join(path, "index.ts")) || File.exist?(File.join(path, "index.js")) return true if File.directory?(File.join(path, "extensions")) # Detect bare Pi-style directories containing .ts/.js source files # even without package.json or index.ts, since Pi.load can resolve them. return true if Dir.glob(File.join(path, "*.{ts,js}")).any? false end |