Module: OllamaAgent::ExternalAgents::Probe

Defined in:
lib/ollama_agent/external_agents/probe.rb

Overview

Resolves executables and optional –version for registry entries. rubocop:disable Metrics/ModuleLength – CLI resolution + Anthropic transport in one module

Class Method Summary collapse

Class Method Details

.capture_version(agent, exe) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ollama_agent/external_agents/probe.rb', line 69

def capture_version(agent, exe)
  return anthropic_model_label(agent) if anthropic_executable?(agent, exe)

  argv_templ = agent["version_argv"]
  return nil unless argv_templ.is_a?(Array) && !argv_templ.empty?

  argv = ArgvInterp.expand(argv_templ, "binary" => exe, "task_file" => "", "root" => "")
  out, err, status = Open3.capture3(*argv)
  return nil unless status.success?

  s = out.to_s.strip
  s = err.to_s.strip if s.empty?
  return nil if s.empty?

  s.lines.first&.strip
rescue StandardError
  nil
end

.clear_cache!Object

rubocop:enable Metrics/MethodLength



105
106
107
# File 'lib/ollama_agent/external_agents/probe.rb', line 105

def clear_cache!
  status_cache.clear
end

.fetch_status(agent) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ollama_agent/external_agents/probe.rb', line 36

def fetch_status(agent)
  cache_key = status_cache_key(agent)
  cached = status_cache[cache_key]
  return cached.dup if cached

  exe = resolve_executable(agent)
  if exe.nil?
    status = {
      "id" => agent["id"].to_s,
      "available" => false,
      "path" => nil,
      "version" => nil,
      "capabilities" => agent["capabilities"] || [],
      "error" => agent_unavailable_message(agent)
    }
    status_cache[cache_key] = status
    return status.dup
  end

  status = {
    "id" => agent["id"].to_s,
    "available" => true,
    "path" => exe,
    "version" => capture_version(agent, exe),
    "capabilities" => agent["capabilities"] || [],
    "error" => nil
  }
  status_cache[cache_key] = status
  status.dup
end

rubocop:disable Metrics/MethodLength



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ollama_agent/external_agents/probe.rb', line 90

def print_table(registry, io: $stdout)
  io.puts "id\tok?\tpath\tversion\tcapabilities"
  registry.agents.each do |a|
    r = fetch_status(a)
    io.puts [
      r["id"],
      r["available"] ? "yes" : "no",
      r["path"] || "-",
      (r["version"] || "-").to_s[0, 80],
      (r["capabilities"] || []).join(",")
    ].join("\t")
  end
end

.resolve_executable(agent) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength – branching PATH vs env vs Anthropic



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ollama_agent/external_agents/probe.rb', line 16

def resolve_executable(agent)
  return resolve_anthropic_executable(agent) if agent["transport"].to_s == "anthropic_api"

  env_key = agent["env_path"]
  if env_key && EnvHelpers.env_present?(env_key)
    path = File.expand_path(ENV[env_key].to_s.strip)
    return path if File.file?(path)
  end

  name = agent["binary"].to_s
  return nil if name.empty?

  resolved = resolve_via_command_v(name)
  return resolved if resolved

  resolve_via_path_walk(name)
end

.status_cache_key(agent) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/ollama_agent/external_agents/probe.rb', line 109

def status_cache_key(agent)
  env_key = agent["env_path"].to_s
  env_val = env_key.empty? ? "" : ENV.fetch(env_key, "")
  [
    agent["id"].to_s,
    agent["binary"].to_s,
    env_key,
    env_val
  ].join("|")
end