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"
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



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

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



40
41
42
# File 'lib/agent/lock/skill.rb', line 40

def into
  @into
end

#source ⇒ String (readonly)

Returns the skill directory being copied.

Returns:

  • (String) —

    the skill directory being copied



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

def source
  @source
end

Class Method Details

.default_into ⇒ String

Returns where most agents other than Claude Code look for a user's own skills; the CLI's --for claude points at ~/.claude/skills instead.

Returns:

  • (String) —

    where most agents other than Claude Code look for a user's own skills; the CLI's --for claude points at ~/.claude/skills instead



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

def default_into = File.join(Dir.home, ".agents", "skills")

.source ⇒ String

Returns the bundled skill's directory.

Returns:

  • (String) —

    the bundled skill's directory



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

def source = File.join(ROOT, NAME)

Instance Method Details

#install(force: 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:

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

    replace a copy that differs; never a symlink

Returns:

  • (Result) —

    :installed, :current, :differs or :linked



63
64
65
66
67
68
69
70
71
# File 'lib/agent/lock/skill.rb', line 63

def install(force: false)
  refused = refusal(force)
  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



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

def target = File.join(into, NAME)