Class: BundlerSkills::Synchronizer

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler_skills/synchronizer.rb

Overview

Orchestrates discovery -> linking across the resolved agents. The entry point for the bundle exec skills command.

Discovery runs once (agent-independent); linking runs once per distinct output directory (.claude/skills and/or .agents/skills), then the .gitignore is updated.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(root: Bundler.root, config: Config.load, logger: Bundler.ui, specs: nil) ⇒ Synchronizer

Returns a new instance of Synchronizer.



13
14
15
16
17
18
# File 'lib/bundler_skills/synchronizer.rb', line 13

def initialize(root: Bundler.root, config: Config.load, logger: Bundler.ui, specs: nil)
  @root = root
  @config = config
  @logger = logger
  @specs = specs
end

Instance Method Details

#cleanObject

Remove every gem--- symlink we own across all known output dirs. Used by bundle exec skills clean. Returns { subdir => [removed names] }.



53
54
55
56
57
58
59
# File 'lib/bundler_skills/synchronizer.rb', line 53

def clean
  AgentRegistry.all.map(&:skills_subdir).uniq.to_h do |subdir|
    skills_dir = File.join(@root.to_s, subdir)
    linker = Linker.new(skills_dir: skills_dir, config: @config, logger: @logger)
    [subdir, linker.clean_all]
  end
end

#planObject

Discover skills and the agents/dirs that would receive them, without touching the filesystem. Used by bundle exec skills list.



42
43
44
45
46
47
48
49
# File 'lib/bundler_skills/synchronizer.rb', line 42

def plan
  skills = Discoverer.new(specs: @specs, config: @config, logger: @logger).discover
  agents = AgentRegistry.resolve(@root, @config)
  Result.new(
    discovered: skills, agents: agents,
    links_by_dir: {}, gitignore_changed: false
  )
end

#syncObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bundler_skills/synchronizer.rb', line 20

def sync
  skills = Discoverer.new(specs: @specs, config: @config, logger: @logger).discover
  agents = AgentRegistry.resolve(@root, @config)
  subdirs = AgentRegistry.output_subdirs(agents)

  links_by_dir = subdirs.to_h do |subdir|
    skills_dir = File.join(@root.to_s, subdir)
    linker = Linker.new(skills_dir: skills_dir, config: @config, logger: @logger)
    [subdir, linker.link(skills, prune_scope: :all)]
  end

  gitignore_changed = update_gitignore(subdirs)

  log_summary(skills, agents, links_by_dir)
  Result.new(
    discovered: skills, agents: agents,
    links_by_dir: links_by_dir, gitignore_changed: gitignore_changed
  )
end