Class: AgentSkills::Packager

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

Constant Summary collapse

SKILL_EXTENSION =
".skill"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(skill_path) ⇒ Packager

Returns a new instance of Packager.



18
19
20
# File 'lib/agent_skills/packager.rb', line 18

def initialize(skill_path)
  @skill_path = skill_path
end

Class Method Details

.pack(skill_path, output: nil) ⇒ Object



10
11
12
# File 'lib/agent_skills/packager.rb', line 10

def self.pack(skill_path, output: nil)
  new(skill_path).pack(output: output)
end

.unpack(skill_file, output:) ⇒ Object



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

def self.unpack(skill_file, output:)
  new(nil).unpack(skill_file, output: output)
end

Instance Method Details

#pack(output: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/agent_skills/packager.rb', line 22

def pack(output: nil)
  validate_skill!

  skill = Skill.load(@skill_path)
  Validator.validate!(skill)

  output_file = output || "#{skill.name}#{SKILL_EXTENSION}"

  create_zip(output_file)
  output_file
end

#unpack(skill_file, output:) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/agent_skills/packager.rb', line 34

def unpack(skill_file, output:)
  raise NotFoundError, "Skill file not found: #{skill_file}" unless File.exist?(skill_file)

  FileUtils.mkdir_p(output)

  Zip::File.open(skill_file) do |zip|
    zip.each do |entry|
      dest = File.join(output, entry.name)
      FileUtils.mkdir_p(File.dirname(dest))
      entry.extract(dest) { true } # overwrite existing
    end
  end

  # Return the extracted skill directory
  skill_dirs = Dir.glob(File.join(output, "*", "SKILL.md")).map { |f| File.dirname(f) }
  skill_dirs.first || output
end