Module: Ask::Skills
- Defined in:
- lib/ask/skills.rb,
lib/ask/skills/skill.rb,
lib/ask/skills/version.rb,
lib/ask/skills/registry.rb,
lib/ask/skills/formatter.rb,
lib/ask/skills/validator.rb,
lib/ask/skills/sources/base.rb,
lib/ask/skills/sources/gems.rb,
lib/ask/skills/sources/filesystem.rb
Defined Under Namespace
Modules: Source Classes: Error, Formatter, Registry, Skill, Validator
Constant Summary collapse
- VERSION =
"0.5.0"
Class Method Summary collapse
-
.builtin_skills_dir ⇒ Object
Built-in skills that ship with the gem.
-
.default_sources ⇒ Object
Default sources when no custom sources or agent directory given.
-
.discover(sources: nil, agent_dir: nil) ⇒ Registry
Discover skills from all configured sources.
-
.extract_body(content) ⇒ Object
Extract the markdown body from a file with frontmatter.
-
.load_file(path) ⇒ Object
Load a skill from an arbitrary markdown file path.
-
.parse_frontmatter(content) ⇒ Object
Simple frontmatter parsing for skill files.
- .process_metadata_value(value) ⇒ Object
Class Method Details
.builtin_skills_dir ⇒ Object
Built-in skills that ship with the gem.
36 37 38 |
# File 'lib/ask/skills.rb', line 36 def builtin_skills_dir File.join(__dir__, "skills") end |
.default_sources ⇒ Object
Default sources when no custom sources or agent directory given.
31 32 33 |
# File 'lib/ask/skills.rb', line 31 def default_sources build_source_list end |
.discover(sources: nil, agent_dir: nil) ⇒ Registry
Discover skills from all configured sources.
25 26 27 28 |
# File 'lib/ask/skills.rb', line 25 def discover(sources: nil, agent_dir: nil) all_sources = sources || build_source_list(agent_dir: agent_dir) Registry.new(all_sources) end |
.extract_body(content) ⇒ Object
Extract the markdown body from a file with frontmatter.
94 95 96 97 98 99 100 |
# File 'lib/ask/skills.rb', line 94 def extract_body(content) return content unless content.start_with?("---\n") end_idx = content.index("\n---\n", 4) return content unless end_idx body = content[(end_idx + 5)..] || "" body.sub(/\A\n/, "").strip end |
.load_file(path) ⇒ Object
Load a skill from an arbitrary markdown file path.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ask/skills.rb', line 41 def load_file(path) path = File.(path) content = File.read(path) frontmatter = parse_frontmatter(content) body = extract_body(content) name = frontmatter["name"] || File.basename(path, ".md") description = frontmatter["description"] || "Ad-hoc skill loaded from #{File.basename(path)}" Skill.new( name: name, description: description, instructions: body.empty? ? content : body, source: path ) end |
.parse_frontmatter(content) ⇒ Object
Simple frontmatter parsing for skill files.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ask/skills.rb', line 59 def parse_frontmatter(content) return {} unless content.start_with?("---\n") end_idx = content.index("\n---\n", 4) return {} unless end_idx yaml_str = content[4...end_idx] yaml = {} current_key = nil current_value = nil yaml_str.split("\n").each do |line| if (m = line.match(/\A(\w[\w_]*):\s*(.*)\z/)) if current_key yaml[current_key] = (current_value.strip) end current_key = m[1] current_value = m[2].strip elsif current_key && line.match?(/\A\s+/) current_value << " #{line.strip}" end end if current_key yaml[current_key] = (current_value.strip) end yaml end |
.process_metadata_value(value) ⇒ Object
88 89 90 91 |
# File 'lib/ask/skills.rb', line 88 def (value) return value unless value value.gsub(/\A"|"\z/, "").gsub(/\A'|'\z/, "") end |