Class: Agent::Lock::Skill

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/lock/skill.rb

Overview

The skill this gem ships: a SKILL.md that teaches an agent how to claim files with alock, copied into whichever skills directory the agent reads.

It lives inside the gem rather than in a repository of its own so that the instructions an agent follows can never describe a different version of the tool than the one it runs.

Examples:

Agent::Lock::Skill.new(into: "~/.claude/skills").install.status  # => :installed

Defined Under Namespace

Classes: Result

Constant Summary collapse

NAME =

The skill's directory name, which is also the name it answers to.

"agent-lock"
AGENT_DIRS =

The home-relative directory each agent keeps its skills under. Any agent not named here reads the shared ~/.agents.

{ "claude" => ".claude" }.freeze
ROOT =

Where the gem keeps its skills, one directory each.

File.expand_path("../../../skills", __dir__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(into: self.class.default_into, source: self.class.source) ⇒ Skill

Returns a new instance of Skill.

Parameters:

  • into (String) (defaults to: self.class.default_into) —

    a skills directory, such as ~/.claude/skills

  • source (String) (defaults to: self.class.source) —

    the skill to copy, the bundled one by default



55
56
57
58
# File 'lib/agent/lock/skill.rb', line 55

def initialize(into: self.class.default_into, source: self.class.source)
  @into = File.expand_path(into)
  @source = source
end

Instance Attribute Details

#into ⇒ String (readonly)

Returns the skills directory being installed into.

Returns:

  • (String) —

    the skills directory being installed into



48
49
50
# File 'lib/agent/lock/skill.rb', line 48

def into
  @into
end

#source ⇒ String (readonly)

Returns the skill directory being copied.

Returns:

  • (String) —

    the skill directory being copied



51
52
53
# File 'lib/agent/lock/skill.rb', line 51

def source
  @source
end

Class Method Details

.bundled ⇒ Array<String>

Returns the name of every skill the gem ships, so help text can say what install puts on disk.

Returns:

  • (Array<String>) —

    the name of every skill the gem ships, so help text can say what install puts on disk



39
# File 'lib/agent/lock/skill.rb', line 39

def bundled = Dir.children(ROOT).select { |name| File.directory?(File.join(ROOT, name)) }.sort

.default_into(agent = nil) ⇒ String

Returns the skills directory that agent reads: ~/.claude/skills for Claude Code, and the shared ~/.agents/skills for any other or none.

Parameters:

  • agent (String, nil) (defaults to: nil) —

    the agent the skill is for, e.g. claude

Returns:

  • (String) —

    the skills directory that agent reads: ~/.claude/skills for Claude Code, and the shared ~/.agents/skills for any other or none



44
# File 'lib/agent/lock/skill.rb', line 44

def default_into(agent = nil) = File.join(Dir.home, AGENT_DIRS.fetch(agent.to_s, ".agents"), "skills")

.source ⇒ String

Returns the bundled skill's directory.

Returns:

  • (String) —

    the bundled skill's directory



35
# File 'lib/agent/lock/skill.rb', line 35

def source = File.join(ROOT, NAME)

Instance Method Details

#install(overwrite: false) ⇒ Result

Copy the skill in, unless something is already there that this would destroy. A copy that differs may be one somebody edited on purpose, and a symlink is another installer's, such as a dotfiles repository that links every skill it manages; replacing either without being asked is the silent last-writer-wins this gem exists to prevent.

Parameters:

  • overwrite (Boolean) (defaults to: false) —

    replace a copy that differs; never a symlink

Returns:

  • (Result) —

    :installed, :current, :differs or :linked



71
72
73
74
75
76
77
78
79
# File 'lib/agent/lock/skill.rb', line 71

def install(overwrite: false)
  refused = refusal(overwrite)
  return refused if refused

  FileUtils.rm_rf(target)
  FileUtils.mkdir_p(into)
  FileUtils.cp_r(source, target)
  result(:installed)
end

#target ⇒ String

Returns the directory the skill ends up in.

Returns:

  • (String) —

    the directory the skill ends up in



61
# File 'lib/agent/lock/skill.rb', line 61

def target = File.join(into, NAME)