Module: AgentHarness::Skills

Defined in:
lib/agent_harness/skills.rb

Overview

Filesystem-backed registry for reusable agent skills.

Constant Summary collapse

AGENT_HARNESS_SKILLS_DIR =
File.join(".agent-harness", "skills")
SHARED_SKILLS_DIR =
File.join(".agents", "skills")

Class Method Summary collapse

Class Method Details

.discover(cwd: Dir.pwd, home: Dir.home, refresh: false) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/agent_harness/skills.rb', line 10

def discover(cwd: Dir.pwd, home: Dir.home, refresh: false)
  cache_key = [File.expand_path(cwd), File.expand_path(home)]
  @discovered ||= {}
  @registry ||= {}
  @discovered.delete(cache_key) if refresh
  @discovered[cache_key] ||= discover_registry(cwd: cwd, home: home)

  combined_registry(cache_key).values
end

.find(name, cwd: Dir.pwd, home: Dir.home) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/agent_harness/skills.rb', line 20

def find(name, cwd: Dir.pwd, home: Dir.home)
  cache_key = [File.expand_path(cwd), File.expand_path(home)]
  discover(cwd: cwd, home: home)

  combined_registry(cache_key).fetch(normalize_lookup_key(name)) do
    raise ConfigurationError, "Unknown skill: #{name}"
  end
end

.register(name, attributes) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/agent_harness/skills.rb', line 29

def register(name, attributes)
  @registry ||= {}
  skill = case attributes
  when Skill
    attributes
  when Hash
    Skill.from_hash(attributes.merge(name: name))
  else
    raise ConfigurationError, "Skill registration must be a Skill or Hash"
  end

  @registry[skill.name] = skill
end

.reset!Object



60
61
62
63
# File 'lib/agent_harness/skills.rb', line 60

def reset!
  @registry = {}
  @discovered = {}
end

.resolve(reference, cwd: Dir.pwd, home: Dir.home) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/agent_harness/skills.rb', line 43

def resolve(reference, cwd: Dir.pwd, home: Dir.home)
  case reference
  when nil
    nil
  when Skill
    reference
  when Hash
    Skill.from_hash(reference)
  else
    find(reference, cwd: cwd, home: home)
  end
end

.resolve_all(references, cwd: Dir.pwd, home: Dir.home) ⇒ Object



56
57
58
# File 'lib/agent_harness/skills.rb', line 56

def resolve_all(references, cwd: Dir.pwd, home: Dir.home)
  Array(references).filter_map { |reference| resolve(reference, cwd: cwd, home: home) }
end