Module: OllamaAgent::AgentRootResolver

Defined in:
lib/ollama_agent/agent_root_resolver.rb

Overview

Resolves and normalizes the agent workspace root from explicit config or ENV.

Class Method Summary collapse

Class Method Details

.resolve(explicit, env: ENV, cwd: Dir.pwd) ⇒ String

Returns absolute path (best-effort realpath when the path exists).

Parameters:

  • explicit (String, nil)

    path from AgentConfig

  • env (Hash) (defaults to: ENV)

    typically ENV

  • cwd (String) (defaults to: Dir.pwd)

    directory for expanding relative paths

Returns:

  • (String)

    absolute path (best-effort realpath when the path exists)



12
13
14
15
16
17
18
19
20
21
# File 'lib/ollama_agent/agent_root_resolver.rb', line 12

def resolve(explicit, env: ENV, cwd: Dir.pwd)
  raw = explicit
  raw = env.fetch("OLLAMA_AGENT_ROOT", nil) if raw.nil? || raw.to_s.strip.empty?
  raw = cwd if raw.nil? || raw.to_s.strip.empty?

  expanded = File.expand_path(raw.to_s, cwd)
  File.realpath(expanded)
rescue Errno::ENOENT, Errno::ELOOP, Errno::EACCES, Errno::ENOTDIR
  expanded
end