Class: AgentSkills::Skill
- Inherits:
-
Object
- Object
- AgentSkills::Skill
- Defined in:
- lib/agent_skills/skill.rb
Constant Summary collapse
- FRONTMATTER_REGEX =
/\A---\s*\n(.+?)\n---\s*\n(.*)/m
Instance Attribute Summary collapse
-
#allowed_tools ⇒ Object
readonly
Returns the value of attribute allowed_tools.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#compatibility ⇒ Object
readonly
Returns the value of attribute compatibility.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#license ⇒ Object
readonly
Returns the value of attribute license.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #assets ⇒ Object
-
#initialize(path:, name:, description:, body:, license: nil, compatibility: nil, metadata: {}, allowed_tools: []) ⇒ Skill
constructor
A new instance of Skill.
- #references ⇒ Object
- #scripts ⇒ Object
- #to_h ⇒ Object
- #to_prompt_xml ⇒ Object
Constructor Details
#initialize(path:, name:, description:, body:, license: nil, compatibility: nil, metadata: {}, allowed_tools: []) ⇒ Skill
Returns a new instance of Skill.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/agent_skills/skill.rb', line 12 def initialize(path:, name:, description:, body:, license: nil, compatibility: nil, metadata: {}, allowed_tools: []) @path = path @name = name @description = description @body = body @license = license @compatibility = compatibility = @allowed_tools = allowed_tools end |
Instance Attribute Details
#allowed_tools ⇒ Object (readonly)
Returns the value of attribute allowed_tools.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def allowed_tools @allowed_tools end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def body @body end |
#compatibility ⇒ Object (readonly)
Returns the value of attribute compatibility.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def compatibility @compatibility end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def description @description end |
#license ⇒ Object (readonly)
Returns the value of attribute license.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def license @license end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/agent_skills/skill.rb', line 9 def path @path end |
Class Method Details
.load(skill_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/agent_skills/skill.rb', line 24 def self.load(skill_path) skill_md_path = File.join(skill_path, "SKILL.md") unless File.exist?(skill_md_path) raise NotFoundError, "SKILL.md not found in #{skill_path}" end content = File.read(skill_md_path, encoding: "UTF-8") parse(content, skill_path) end |
.parse(content, path = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/agent_skills/skill.rb', line 35 def self.parse(content, path = nil) match = content.match(FRONTMATTER_REGEX) unless match raise ParseError, "Invalid SKILL.md format: missing YAML frontmatter" end frontmatter = YAML.safe_load(match[1], symbolize_names: true) body = match[2].strip new( path: path, name: frontmatter[:name], description: frontmatter[:description], license: frontmatter[:license], compatibility: frontmatter[:compatibility], metadata: frontmatter[:metadata] || {}, allowed_tools: parse_allowed_tools(frontmatter[:"allowed-tools"]), body: body ) end |
Instance Method Details
#assets ⇒ Object
69 70 71 72 73 |
# File 'lib/agent_skills/skill.rb', line 69 def assets return [] unless @path Dir.glob(File.join(@path, "assets", "*")).select { |f| File.file?(f) } end |
#references ⇒ Object
63 64 65 66 67 |
# File 'lib/agent_skills/skill.rb', line 63 def references return [] unless @path Dir.glob(File.join(@path, "references", "*.md")) end |
#scripts ⇒ Object
57 58 59 60 61 |
# File 'lib/agent_skills/skill.rb', line 57 def scripts return [] unless @path Dir.glob(File.join(@path, "scripts", "*")).select { |f| File.file?(f) } end |
#to_h ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/agent_skills/skill.rb', line 86 def to_h { name: @name, description: @description, license: @license, compatibility: @compatibility, metadata: , allowed_tools: @allowed_tools, body: @body }.compact end |
#to_prompt_xml ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/agent_skills/skill.rb', line 75 def to_prompt_xml " <skill name=\"\#{@name}\">\n <description>\#{@description}</description>\n <instructions>\n \#{@body}\n </instructions>\n </skill>\n XML\nend\n".strip |