Class: AgentSkills::Loader

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

Constant Summary collapse

DEFAULT_PATHS =
[
  File.expand_path("~/.config/claude/skills"),
  ".claude/skills",
  "skills"
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths: DEFAULT_PATHS) ⇒ Loader

Returns a new instance of Loader.



13
14
15
16
# File 'lib/agent_skills/loader.rb', line 13

def initialize(paths: DEFAULT_PATHS)
  @paths = Array(paths)
  @skills = {}
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



11
12
13
# File 'lib/agent_skills/loader.rb', line 11

def paths
  @paths
end

#skillsObject (readonly)

Returns the value of attribute skills.



11
12
13
# File 'lib/agent_skills/loader.rb', line 11

def skills
  @skills
end

Instance Method Details

#[](name) ⇒ Object



31
32
33
# File 'lib/agent_skills/loader.rb', line 31

def [](name)
  @skills[name]
end

#countObject



35
36
37
# File 'lib/agent_skills/loader.rb', line 35

def count
  @skills.size
end

#discoverObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/agent_skills/loader.rb', line 18

def discover
  @skills = {}

  @paths.each do |base_path|
    expanded = File.expand_path(base_path)
    next unless File.directory?(expanded)

    discover_in_path(expanded)
  end

  @skills
end

#each(&block) ⇒ Object



39
40
41
# File 'lib/agent_skills/loader.rb', line 39

def each(&block)
  @skills.each(&block)
end

#find_relevant(query) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/agent_skills/loader.rb', line 43

def find_relevant(query)
  return [] if query.nil? || query.empty?

  keywords = query.downcase.split(/\s+/)

  @skills.values.select do |skill|
    text = "#{skill.name} #{skill.description}".downcase
    keywords.any? { |keyword| text.include?(keyword) }
  end
end