Class: OllamaAgent::Plugins::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/plugins/loader.rb

Overview

Loads plugins from:

1. OLLAMA_AGENT_PLUGINS env var (comma-separated require paths)
2. ~/.config/ollama_agent/plugins.rb  (user global plugins)
3. <project_root>/.ollama_agent/plugins.rb  (project-local plugins)
4. Gem-installed plugins with name matching "ollama_agent_*"

Each loaded file is expected to call:

OllamaAgent::Plugins::Registry.register(:my_plugin) { |r| ... }

Constant Summary collapse

GLOBAL_PLUGINS_PATH =
File.join(Dir.home, ".config", "ollama_agent", "plugins.rb")
GEM_PLUGIN_PREFIX =
"ollama_agent_"

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd, registry: nil) ⇒ Loader

Returns a new instance of Loader.



19
20
21
22
# File 'lib/ollama_agent/plugins/loader.rb', line 19

def initialize(root: Dir.pwd, registry: nil)
  @root     = File.expand_path(root)
  @registry = registry || Registry.instance
end

Instance Method Details

#load_all(skip_gems: false) ⇒ Array<String>

Load all applicable plugins.

Parameters:

  • skip_gems (Boolean) (defaults to: false)

    skip gem-installed plugins (useful in tests)

Returns:

  • (Array<String>)

    paths/names of successfully loaded plugins



27
28
29
30
31
32
33
34
35
36
# File 'lib/ollama_agent/plugins/loader.rb', line 27

def load_all(skip_gems: false)
  loaded = []

  loaded.concat(load_env_plugins)
  loaded.concat(load_file_plugin(GLOBAL_PLUGINS_PATH))
  loaded.concat(load_file_plugin(project_plugins_path))
  loaded.concat(load_gem_plugins) unless skip_gems

  loaded
end

#load_plugin(path_or_require) ⇒ Object

Load a single plugin from a require path or file.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ollama_agent/plugins/loader.rb', line 39

def load_plugin(path_or_require)
  if File.exist?(path_or_require)
    require File.expand_path(path_or_require)
  else
    require path_or_require
  end
  [path_or_require]
rescue LoadError => e
  warn "ollama_agent: plugin load failed (#{path_or_require}): #{e.message}" if debug?
  []
rescue StandardError => e
  warn "ollama_agent: plugin error (#{path_or_require}): #{e.message}"
  []
end