Class: Agent::Lock::Skill
- Inherits:
-
Object
- Object
- Agent::Lock::Skill
- 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.
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.("../../../skills", __dir__)
Instance Attribute Summary collapse
-
#into ⇒ String
readonly
The skills directory being installed into.
-
#source ⇒ String
readonly
The skill directory being copied.
Class Method Summary collapse
-
.bundled ⇒ Array<String>
The name of every skill the gem ships, so help text can say what
installputs on disk. -
.default_into(agent = nil) ⇒ String
The skills directory that agent reads:
~/.claude/skillsfor Claude Code, and the shared~/.agents/skillsfor any other or none. -
.source ⇒ String
The bundled skill's directory.
Instance Method Summary collapse
-
#initialize(into: self.class.default_into, source: self.class.source) ⇒ Skill
constructor
A new instance of Skill.
-
#install(overwrite: false) ⇒ Result
Copy the skill in, unless something is already there that this would destroy.
-
#target ⇒ String
The directory the skill ends up in.
Constructor Details
#initialize(into: self.class.default_into, source: self.class.source) ⇒ Skill
Returns a new instance of Skill.
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.(into) @source = source end |
Instance Attribute Details
#into ⇒ String (readonly)
Returns 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.
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.
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.
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") |
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.
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.
61 |
# File 'lib/agent/lock/skill.rb', line 61 def target = File.join(into, NAME) |