Class: Clacky::ChannelSetup::LarkSkillsImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/default_skills/channel-setup/import_lark_skills.rb

Constant Summary collapse

DEFAULT_SOURCE_DIR =
File.join(Dir.home, '.agents', 'skills')
DEFAULT_TARGET_DIR =
File.join(Dir.home, '.clacky', 'skills', 'lark-imports')
SKILL_PREFIX =
'lark-'

Instance Method Summary collapse

Constructor Details

#initialize(source_dir: DEFAULT_SOURCE_DIR, target_dir: DEFAULT_TARGET_DIR) ⇒ LarkSkillsImporter

Returns a new instance of LarkSkillsImporter.

Parameters:

  • source_dir (String) (defaults to: DEFAULT_SOURCE_DIR)

    directory containing lark-cli installed skills

  • target_dir (String) (defaults to: DEFAULT_TARGET_DIR)

    destination under ~/.clacky/skills/



36
37
38
39
# File 'lib/clacky/default_skills/channel-setup/import_lark_skills.rb', line 36

def initialize(source_dir: DEFAULT_SOURCE_DIR, target_dir: DEFAULT_TARGET_DIR)
  @source_dir = Pathname.new(source_dir).expand_path
  @target_dir = Pathname.new(target_dir).expand_path
end

Instance Method Details

#runHash

Run the import. Returns a result hash; never raises on per-skill errors.

Returns:

  • (Hash)

    { copied: Integer, skipped: Integer, errors: Array<String> }



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/clacky/default_skills/channel-setup/import_lark_skills.rb', line 43

def run
  return { copied: 0, skipped: 0, errors: ["source not found: #{@source_dir}"] } unless @source_dir.directory?

  skill_dirs = discover_lark_skills
  return { copied: 0, skipped: 0, errors: [] } if skill_dirs.empty?

  FileUtils.mkdir_p(@target_dir)

  copied = 0
  errors = []
  skill_dirs.each do |src|
    begin
      copy_skill(src)
      copied += 1
    rescue StandardError => e
      errors << "#{src.basename}: #{e.message}"
    end
  end

  { copied: copied, skipped: 0, errors: errors }
end