Class: Shai::SkillScanner
- Inherits:
-
Object
- Object
- Shai::SkillScanner
- Defined in:
- lib/shai/skill_scanner.rb
Constant Summary collapse
- SKILL_FILE =
"SKILL.md"- DISABLED_SUFFIX =
".disabled"- AGENTS =
[ {name: "claude", skill_dir: ".claude/skills"}, {name: "codex", skill_dir: ".agents/skills"} ].freeze
Instance Attribute Summary collapse
-
#global_base ⇒ Object
readonly
Returns the value of attribute global_base.
-
#local_base ⇒ Object
readonly
Returns the value of attribute local_base.
Instance Method Summary collapse
- #disable!(skill) ⇒ Object
- #enable!(skill) ⇒ Object
- #find(name, scope: nil, agent: nil) ⇒ Object
-
#initialize(local_base: Dir.pwd, global_base: Dir.home) ⇒ SkillScanner
constructor
A new instance of SkillScanner.
- #scan_all ⇒ Object
Constructor Details
#initialize(local_base: Dir.pwd, global_base: Dir.home) ⇒ SkillScanner
Returns a new instance of SkillScanner.
17 18 19 20 |
# File 'lib/shai/skill_scanner.rb', line 17 def initialize(local_base: Dir.pwd, global_base: Dir.home) @local_base = File.(local_base) @global_base = File.(global_base) end |
Instance Attribute Details
#global_base ⇒ Object (readonly)
Returns the value of attribute global_base.
15 16 17 |
# File 'lib/shai/skill_scanner.rb', line 15 def global_base @global_base end |
#local_base ⇒ Object (readonly)
Returns the value of attribute local_base.
15 16 17 |
# File 'lib/shai/skill_scanner.rb', line 15 def local_base @local_base end |
Instance Method Details
#disable!(skill) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/shai/skill_scanner.rb', line 47 def disable!(skill) return false unless skill.enabled enabled_path = skill.path disabled_path = "#{enabled_path}#{DISABLED_SUFFIX}" return false unless File.exist?(enabled_path) File.rename(enabled_path, disabled_path) true end |
#enable!(skill) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/shai/skill_scanner.rb', line 37 def enable!(skill) return false if skill.enabled disabled_path = skill.path enabled_path = disabled_path.sub(/#{Regexp.escape(DISABLED_SUFFIX)}$/o, "") return false unless File.exist?(disabled_path) File.rename(disabled_path, enabled_path) true end |
#find(name, scope: nil, agent: nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/shai/skill_scanner.rb', line 29 def find(name, scope: nil, agent: nil) skills = scan_all skills.select! { |s| s.name == name } skills.select! { |s| s.scope == scope } if scope skills.select! { |s| s.agent == agent } if agent skills end |
#scan_all ⇒ Object
22 23 24 25 26 27 |
# File 'lib/shai/skill_scanner.rb', line 22 def scan_all skills = [] skills.concat(scan_scope(:global)) skills.concat(scan_scope(:local)) skills end |