Class: Harnex::Skills

Inherits:
Object
  • Object
show all
Defined in:
lib/harnex/commands/skills.rb

Constant Summary collapse

SKILLS_ROOT =
File.expand_path("../../../../skills", __FILE__)
INSTALL_SKILLS =
%w[harnex-dispatch harnex-chain harnex-buddy].freeze
DEPRECATED_SKILLS =
%w[harnex dispatch chain-implement].freeze
SKILL_ALIASES =
{
  "harnex" => "harnex-dispatch",
  "dispatch" => "harnex-dispatch",
  "chain-implement" => "harnex-chain"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Skills

Returns a new instance of Skills.



36
37
38
# File 'lib/harnex/commands/skills.rb', line 36

def initialize(argv)
  @argv = argv.dup
end

Class Method Details

.usageObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/harnex/commands/skills.rb', line 14

def self.usage
  <<~TEXT
    Usage: harnex skills <subcommand> [SKILL...] [--local]

    Subcommands:
      install     Install bundled skills (globally by default; optional skill names)
      uninstall   Remove installed skills (globally by default)

    Options:
      --local     Target the current repo instead of global ~/.claude/

    Installs: #{INSTALL_SKILLS.join(', ')}
    Aliases: harnex|dispatch -> harnex-dispatch, chain-implement -> harnex-chain

    By default, copies each skill to ~/.claude/skills/<skill>/
    and symlinks ~/.codex/skills/<skill> to it.

    With --local, copies each skill to .claude/skills/<skill>/
    in the current repo and symlinks .codex/skills/<skill> to it.
  TEXT
end

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/harnex/commands/skills.rb', line 40

def run
  subcommand = @argv.shift
  case subcommand
  when "install"
    local, help, requested_skills = parse_args(@argv, allow_positional: true)
    return (puts self.class.usage; 0) if help

    remove_deprecated(local)
    install_skills = requested_skills.empty? ? INSTALL_SKILLS : canonical_skill_names(requested_skills)

    install_skills.each do |skill_name|
      skill_source = resolve_skill_source(skill_name)
      unless skill_source
        return missing_skill(skill_name)
      end

      result = local ? install_local(skill_name, skill_source) : install_global(skill_name, skill_source)
      return result unless result == 0
    end
    0
  when "uninstall"
    local, help, = parse_args(@argv)
    return (puts self.class.usage; 0) if help

    (INSTALL_SKILLS + DEPRECATED_SKILLS).each do |skill_name|
      local ? uninstall_local(skill_name) : uninstall_global(skill_name)
    end
    0
  when "-h", "--help", nil
    puts self.class.usage
    0
  else
    warn("harnex skills: unknown subcommand #{subcommand.inspect}")
    puts self.class.usage
    1
  end
end