Class: ExternalSkillsImportRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/default_skills/onboard/scripts/import_external_skills.rb

Overview


Coordinator - runs all enabled importers and prints a combined report


Constant Summary collapse

IMPORTERS =

Register new importer classes here to add support for more sources.

[OpenClawImporter].freeze
SOURCES =
IMPORTERS.map { |klass| klass::SOURCE_NAME }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(sources: nil, target_skills_dir: File.join(Dir.home, '.clacky', 'skills'), dry_run: false, yes: false) ⇒ ExternalSkillsImportRunner

Returns a new instance of ExternalSkillsImportRunner.

Parameters:

  • sources (Array<String>) (defaults to: nil)

    subset of SOURCES to run; nil means all

  • target_skills_dir (String) (defaults to: File.join(Dir.home, '.clacky', 'skills'))
  • dry_run (Boolean) (defaults to: false)

    when true, only preview without making changes

  • yes (Boolean) (defaults to: false)

    when true, skip confirmation prompt



226
227
228
229
230
231
232
233
234
# File 'lib/clacky/default_skills/onboard/scripts/import_external_skills.rb', line 226

def initialize(sources: nil,
               target_skills_dir: File.join(Dir.home, '.clacky', 'skills'),
               dry_run: false,
               yes: false)
  @sources           = (sources || SOURCES) & SOURCES
  @target_skills_dir = Pathname.new(target_skills_dir).expand_path
  @dry_run           = dry_run
  @yes               = yes
end

Instance Method Details

#runObject



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/clacky/default_skills/onboard/scripts/import_external_skills.rb', line 236

def run
  # In dry-run mode: collect plan and print preview only
  if @dry_run
    importers = build_importers(dry_run: true)
    all_imported = []
    importers.each { |i| i.run; all_imported.concat(i.imported) }
    print_preview(all_imported, dry_run: true)
    return all_imported.size
  end

  # Normal mode: collect plan first, show preview, then confirm
  preview_importers = build_importers(dry_run: true)
  all_preview = []
  preview_importers.each { |i| i.run; all_preview.concat(i.imported) }

  if all_preview.empty?
    puts 'Nothing to import.'
    return 0
  end

  print_preview(all_preview, dry_run: false)

  unless @yes || confirm?
    puts 'Import cancelled.'
    return 0
  end

  # Execute the actual import
  importers = build_importers(dry_run: false)
  all_imported = []
  all_errors   = []

  importers.each do |importer|
    importer.run
    all_imported.concat(importer.imported)
    all_errors.concat(importer.errors)
  end

  print_summary(all_imported, all_errors)
  all_imported.size
end