| 1 | # ABSTRACT: Install, check, and update bundled agent skills | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package App::karr::Cmd::Skill; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | our $VERSION = '0.602'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use MooX::Cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use MooX::Options ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | usage_string => 'USAGE: karr skill [install|check|update|show [NAME]] [--agent NAME] [--global] [--force]', | |||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use App::karr::Role::Output; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use App::karr::Role::CliArgs; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use App::karr::Role::ExitCodes; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use App::karr::Role::SkillFile; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use App::karr::Error qw( user_error clean_error ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # ExitCodes: unknown option / bad option value exits 2, not 1 (ADR 0002). Skill | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # is board-less, so it does not inherit ExitCodes via BoardDiscovery -- and for | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # the same reason it declares no --dir and refuses the root form of it in | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # _reject_root_dir below (#226). | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # SkillFile: which skills ship (_skill_names, _retired_skill_names), | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # _skill_files, _skill_content, the two writers and the removal of a retired | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # skill directory, shared with `karr init --claude-skill`, which writes the | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # same directories this command writes for the claude-code agent (tickets | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # #145, #146, #285). | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | with 'App::karr::Role::Output', 'App::karr::Role::CliArgs', | |||||||||||||||||||||||||||||||||||||||||
| 27 | 'App::karr::Role::ExitCodes', 'App::karr::Role::SkillFile'; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | option agent => ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | format => 's', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | doc => 'Target agent (claude-code, codex, cursor)', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | option global => ( | |||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 38 | doc => 'Install/check globally (~/) instead of project-level', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | option force => ( | |||||||||||||||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | doc => 'Force reinstall even if current', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | my %AGENTS = ( | |||||||||||||||||||||||||||||||||||||||||
| 47 | 'claude-code' => { project => '.claude/skills', global => '.claude/skills' }, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 'codex' => { project => '.agents/skills', global => '.codex/skills' }, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'cursor' => { project => '.cursor/skills', global => '.cursor/skills' }, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ($self, $args_ref, $chain_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $self->_reject_root_dir($chain_ref); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my @pos = $self->positional_args($args_ref); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $action = $pos[0] // 'install'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$pos[0] // "install"
MC/DC0%0/1
$pos[0] // "install"
$pos[0]
Truth table0%0/2
A
A= $pos[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | # Only the action is a positional -- and for show, the skill name after it. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $self->check_positional_args( $args_ref, $action eq 'show' ? 2 : 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($action eq 'install') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->_install; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } elsif ($action eq 'check') { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $self->_check; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } elsif ($action eq 'update') { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $self->_update; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } elsif ($action eq 'show') { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->_show( $pos[1] ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # Leading "Usage:" is what bin/karr's handler keys on to exit 2 rather than | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # 1 (ADR 0002: an invalid value is a usage error). Becomes a one-line swap | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # to Role::ExitCodes' usage_error once that lands (ticket #76). | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | user_error( "Usage: karr skill [install|check|update|show]\n", | |||||||||||||||||||||||||||||||||||||||||
| 73 | "Unknown action: $action (use install, check, update, or show)" ); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # One SKILL.md when a name is given, all of them in _skill_names order when | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # not. All of them is the default because that is what "the bundled skill" | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # meant before the split: `karr skill show` still shows everything an agent | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # would be briefed with. A name picks one file out, which is what a shell | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # redirect into a single SKILL.md needs. The JSON shape is the same array | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # either way, so a consumer does not have to know which form was asked for. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub _show { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my @names = $self->_skill_names; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | # An invalid positional value is a usage error (ADR 0002), exit 2. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | user_error( "Usage: karr skill show [NAME]\n", | ||||||||||||||||||||||||||||||||||||||||||
| 90 | "Unknown skill: $name (known: ", join( ', ', @names ), ")" ) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | unless grep { $_ eq $name } @names; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | @names = ($name); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my @shown = map { { skill => $_, content => $self->_skill_content($_) } } @names; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ($self->json) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | # Characters in, characters out, exactly like the plain branch below: | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # print_json goes through App::karr::Encoding::json_encode, which is the | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # character-level codec, and STDOUT's :encoding(UTF-8) layer does the one | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # and only encode. _skill_content is already decoded (slurp_utf8), so it | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # goes in untouched. | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $self->print_json( \@shown ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | # Ticket #33 encoded here, because back then the rest of the CLI handed raw | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # octets to print and a layer on STDOUT would have double-encoded them. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # Ticket #53 removed that premise: STDOUT now carries :encoding(UTF-8) and | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # every command prints characters, so _skill_content goes out as-is. | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # Encoding it again here would be the very double encode #33 was avoiding. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | print join "\n", map { $_->{content} } @shown; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub _install { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my @agents = $self->_target_agents; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my %shipped = map { ( $_ => { $self->_skill_files($_) } ) } $self->_skill_names; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | for my $agent (@agents) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $base = $self->_skills_base($agent); | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | for my $skill ($self->_skill_names) { | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $dir = $base->child($skill); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $file = $dir->child('SKILL.md'); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # "Installed" is keyed on SKILL.md alone: it is the file an agent loads, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # so a target that has it is a target someone installed into. A missing | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # reference beside it is what `update` is for, not a reason to overwrite. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($file->exists && !$self->force) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file->exists and not $self->force
MC/DC0%0/2
$file->exists and not $self->force
$file->exists
not $self->force
Truth table0%0/3
A and not(B)
A= $file->existsB= not $self->force
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->_report( \@results, $agent, $skill, 'exists', "$file", | |||||||||||||||||||||||||||||||||||||||||
| 133 | 'already installed (use --force to reinstall)' ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->_write_skill_files( $dir, $shipped{$skill} ); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->_report( \@results, $agent, $skill, 'installed', "$file", "installed to $file" ); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | # After the new skills are in place, not before: a failed write leaves the | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # old skill where it was rather than an agent with no skill at all. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->_report_removed( \@results, $agent, $self->_remove_retired_skills($base) ); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $self->print_json(\@results) if $self->json; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub _check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my @agents = $self->_target_agents; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my %shipped = map { ( $_ => { $self->_skill_files($_) } ) } $self->_skill_names; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $failing = 0; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | for my $agent (@agents) { | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $base = $self->_skills_base($agent); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $installed = $self->_agent_installed($base); | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | for my $skill ($self->_skill_names) { | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $dir = $base->child($skill); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $file = $dir->child('SKILL.md'); | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if (!$file->exists && !$installed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$file->exists || $installed
MC/DC0%0/2
$file->exists || $installed
$file->exists
$installed
Truth table0%0/3
A || B
A= $file->existsB= $installed
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $self->_report( \@results, $agent, $skill, 'not installed', undef, 'not installed' ); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | } elsif ( $file->exists && !%{ $self->_stale_files( $dir, $shipped{$skill} ) } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$file->exists and not %{$self->_stale_files($dir, $shipped{$skill});}
MC/DC0%0/2
$file->exists and not %{$self->_stale_files($dir, $shipped{$skill});}
$file->exists
not %{$self->_stale_files($dir, $shipped{$skill});}
Truth table0%0/3
A and not(B)
A= $file->existsB= not %{$self->_stale_files($dir, $shipped{$skill});}
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->_report( \@results, $agent, $skill, 'current', undef, 'current' ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | # Differs, or missing while the rest of the set is there: either way | ||||||||||||||||||||||||||||||||||||||||||
| 170 | # `update` has something to write. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->_report( \@results, $agent, $skill, 'outdated', undef, 'outdated' ); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $failing++; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | for my $dir ( $self->_retired_skill_dirs($base) ) { | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $self->_report( \@results, $agent, $dir->basename, 'stale', "$dir", | |||||||||||||||||||||||||||||||||||||||||
| 178 | "stale: retired skill, 'karr skill update' removes $dir" ); | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $failing++; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $self->print_json(\@results) if $self->json; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | # A check that found work for `update` is a runtime failure, exit 1 (ADR | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # 0002) -- outdated and stale alike. Nothing installed is not. | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | exit(1) if $failing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub _update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my @agents = $self->_target_agents; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my %shipped = map { ( $_ => { $self->_skill_files($_) } ) } $self->_skill_names; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my @results; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | for my $agent (@agents) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $base = $self->_skills_base($agent); | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | unless ( $self->_agent_installed($base) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | $self->_report( \@results, $agent, $_, 'not installed', undef, | ||||||||||||||||||||||||||||||||||||||||||
| 201 | "not installed (run 'karr skill install' first)" ) | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | for $self->_skill_names; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | for my $skill ($self->_skill_names) { | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $dir = $base->child($skill); | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $file = $dir->child('SKILL.md'); | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # Only what is missing or differs gets written: a file that already | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # matches is not rewritten (nothing to gain, and one fewer chance for the | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # read-only fallback in _write_skill to have to say anything), and a file | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # in the target that is not shipped is nobody's to remove from here. A | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # skill missing entirely is all stale, so it is written whole -- which is | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # how an install of the retired single skill becomes the pair. | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $stale = $self->_stale_files( $dir, $shipped{$skill} ); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (%$stale) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $self->_write_skill_files( $dir, $stale ); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $self->_report( \@results, $agent, $skill, 'updated', "$file", 'updated' ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->_report( \@results, $agent, $skill, 'current', undef, 'already current' ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $self->_report_removed( \@results, $agent, $self->_remove_retired_skills($base) ); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $self->print_json(\@results) if $self->json; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # Whether an agent's target counts as having the karr skills at all: either | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # skill of the set, or the retired single skill it replaces. Decides whether | ||||||||||||||||||||||||||||||||||||||||||
| 233 | # update touches the agent and whether check calls a missing member outdated | ||||||||||||||||||||||||||||||||||||||||||
| 234 | # rather than not installed. | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub _agent_installed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_agent_installed: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my ($self, $base) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | return 1 if grep { $base->child( $_, 'SKILL.md' )->exists } $self->_skill_names; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return $self->_retired_skill_dirs($base) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | # One result: a JSON entry, or a plain line naming agent and skill. $path is | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # left out of the entry when there is none, as the statuses without one always | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # were. | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub _report { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my ($self, $results, $agent, $skill, $status, $path, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | push @$results, { agent => $agent, skill => $skill, status => $status, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | defined $path ? ( path => $path ) : () }; | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | printf "%-12s %-32s %s\n", $agent, $skill, $text unless $self->json; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub _report_removed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_removed: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my ($self, $results, $agent, @removed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 254 | $self->_report( $results, $agent, $_->basename, 'removed', "$_", | ||||||||||||||||||||||||||||||||||||||||||
| 255 | "removed $_ (retired, replaced by " | ||||||||||||||||||||||||||||||||||||||||||
| 256 | . join( ' and ', $self->_skill_names ) . ')' ) | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | for @removed; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # The shipped files whose copy under $dir is missing or differs, as the same | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # (relative path => content) pairs _skill_files hands out -- i.e. exactly what | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # _write_skill_files has to write to bring the target current. Empty means | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # current. Compared as characters on both sides (slurp_utf8 against | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # slurp_utf8), so a byte-level difference in encoding shows up as a | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # difference rather than being hidden by a decode on one side only. | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub _stale_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stale_files: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my ($self, $dir, $shipped) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my %stale; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | for my $rel (sort keys %$shipped) { | |||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $file = $dir->child($rel); | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | next if $file->exists && $self->_read_skill($file) eq $shipped->{$rel}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file->exists and $self->_read_skill($file) eq $shipped->{$rel}
MC/DC0%0/2
$file->exists and $self->_read_skill($file) eq $shipped->{$rel}
$file->exists
$self->_read_skill($file) eq $shipped->{$rel}
Truth table0%0/3
A and B
A= $file->existsB= $self->_read_skill($file) eq $shipped->{$rel}
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $stale{$rel} = $shipped->{$rel}; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | return \%stale; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | # Path::Tiny raises Path::Tiny::Error objects that stringify with the call site | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # appended ("mkpath failed for ...: Permission denied at .../Cmd/Skill.pm line | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # NNN."), so an unwritable skill directory used to report a karr source | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # location at the user. App::karr::Error reduces it to the one line that is | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # actually about them (ticket #77). | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub _read_skill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_skill: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $content = eval { $file->slurp_utf8 }; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | defined $content | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | or user_error( "Could not read $file: ", clean_error($@) ); | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | # _write_skill and _write_skill_files -- the in-place write, and why it has to | ||||||||||||||||||||||||||||||||||||||||||
| 292 | # be one -- live in App::karr::Role::SkillFile, composed above: `karr init | ||||||||||||||||||||||||||||||||||||||||||
| 293 | # --claude-skill` writes the very same directories under .claude/skills/, and | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # kept its own spew_utf8 copy of this rule until ticket #145 because the rule | ||||||||||||||||||||||||||||||||||||||||||
| 295 | # lived here (#142). _skill_content, which finds the bundled skill in the | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # first place, followed it there in #146 -- it was duplicated in Cmd::Init down | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # to the last line but one -- and _skill_files, the whole directory rather than | ||||||||||||||||||||||||||||||||||||||||||
| 298 | # its SKILL.md, joined it in #285. The list of skills and the removal of the | ||||||||||||||||||||||||||||||||||||||||||
| 299 | # retired one live there for the same reason. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | # `karr skill install --dir PATH` was always rejected by MooX::Options -- this | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # command declares no such option -- but `karr --dir PATH skill install` was | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # not: --dir is declared on App::karr::Role::BoardDiscovery, the root command | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # composes it via App::karr::Role::BoardAccess, and MooX::Cmd leaves the parsed | ||||||||||||||||||||||||||||||||||||||||||
| 305 | # value on the root instance in the command chain, where nothing here ever | ||||||||||||||||||||||||||||||||||||||||||
| 306 | # looked. So the option went in without a word and the install ran on the | ||||||||||||||||||||||||||||||||||||||||||
| 307 | # current directory instead -- putting a file into a tree the caller had not | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # named, under a message that read like the named one (#226). `dashboard` had | ||||||||||||||||||||||||||||||||||||||||||
| 309 | # the same leak (#225) and only ever read; this one writes. | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # Refused rather than adopted as a synonym, because --dir is not what this | ||||||||||||||||||||||||||||||||||||||||||
| 312 | # command's target is. --dir seeds a walk UPWARD to one repository's root | ||||||||||||||||||||||||||||||||||||||||||
| 313 | # (App::karr::Role::BoardDiscovery/_build_git_root, which is why it may name | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # any directory inside that repository), while the project-local target here is | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # the current directory itself, repository or not: `karr skill` is board-less | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # and installing into a plain directory is a supported use, pinned by t/226. | ||||||||||||||||||||||||||||||||||||||||||
| 317 | # Honouring --dir would have meant either refusing those installs or giving one | ||||||||||||||||||||||||||||||||||||||||||
| 318 | # option two meanings that answer about different directories. `cd` is how you | ||||||||||||||||||||||||||||||||||||||||||
| 319 | # install into another tree, and `karr init --claude-skill` is the command that | ||||||||||||||||||||||||||||||||||||||||||
| 320 | # writes these same directories through git_root. | ||||||||||||||||||||||||||||||||||||||||||
| 321 | # | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # The root is read from $chain_ref the way App::karr::Cmd::Dashboard reads it | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # for its own refusal and App::karr::Cmd::GetRefs reads it to honour the | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # option; a directly constructed instance (no MooX::Cmd dispatch, hence an | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # empty chain) has no root option to reject. | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub _reject_root_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reject_root_dir: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my ($self, $chain_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | return unless $chain_ref && @$chain_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$chain_ref and @$chain_ref
MC/DC0%0/2
$chain_ref and @$chain_ref
$chain_ref
@$chain_ref
Truth table0%0/3
A and B
A= $chain_refB= @$chain_ref
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $root = $chain_ref->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return unless $root && $root->can('has_dir') && $root->has_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$root and $root->can("has_dir") and $root->has_dir
$root and $root->can("has_dir")
MC/DC0%0/3
$root and $root->can("has_dir") and $root->has_dir
$root
$root->can("has_dir")
$root->has_dir
Truth table0%0/4
A and B and C
A= $rootB= $root->can("has_dir")C= $root->has_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | # Wrapped to stay inside 80 columns with usage_error's own "Usage error: " | ||||||||||||||||||||||||||||||||||||||||||
| 332 | # prefix on the first line: what to type comes first, the reason after it. | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $self->usage_error( | |||||||||||||||||||||||||||||||||||||||||
| 334 | "skill does not take --dir; its target is the current directory:\n" | ||||||||||||||||||||||||||||||||||||||||||
| 335 | . "cd PATH && karr skill install\n" | ||||||||||||||||||||||||||||||||||||||||||
| 336 | . "(--dir seeds a search upward for one repository's root, while skill is\n" | ||||||||||||||||||||||||||||||||||||||||||
| 337 | . "board-less and works where it is run -- or under \$HOME with --global.)" | ||||||||||||||||||||||||||||||||||||||||||
| 338 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub _target_agents { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_target_agents: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if ($self->agent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my @names = split /,/, $self->agent; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 346 | # --agent is a value MooX::Options cannot validate, so the usage error is | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # raised here; see the note on the unknown-action branch in execute. | ||||||||||||||||||||||||||||||||||||||||||
| 348 | user_error( "Usage: karr skill --agent NAME[,NAME,...]\n", | ||||||||||||||||||||||||||||||||||||||||||
| 349 | "Unknown agent: $name (known: ", join( ', ', sort keys %AGENTS ), ")" ) | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | unless $AGENTS{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return @names; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # Auto-detect: return agents whose skills directories exist, or all if none | ||||||||||||||||||||||||||||||||||||||||||
| 355 | # found | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my @detected; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | for my $name (sort keys %AGENTS) { | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | push @detected, $name if $self->_skills_base($name)->exists; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | return @detected ? @detected : sort keys %AGENTS; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | # The directory an agent keeps its skills in -- .claude/skills and the like -- | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # under which every skill of the set, and any retired one, is a directory of | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # its own name. | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | sub _skills_base { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_skills_base: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my ($self, $agent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | my $spec = $AGENTS{$agent} or die "Unknown agent: $agent\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | # Absolute, because the paths under it are printed back at the caller and | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # handed to --json consumers: `installed to .claude/skills/...` named no tree | ||||||||||||||||||||||||||||||||||||||||||
| 371 | # in particular and was as true of the directory the file went into as of the | ||||||||||||||||||||||||||||||||||||||||||
| 372 | # one the caller meant (#226, point 3). ->absolute prepends the current | ||||||||||||||||||||||||||||||||||||||||||
| 373 | # directory without resolving symlinks, so what comes back is the path the | ||||||||||||||||||||||||||||||||||||||||||
| 374 | # caller would have typed rather than a realpath they may not recognize. The | ||||||||||||||||||||||||||||||||||||||||||
| 375 | # global branch is absolute already: $HOME is. | ||||||||||||||||||||||||||||||||||||||||||
| 376 | return $self->global | ||||||||||||||||||||||||||||||||||||||||||
| 377 | ? path($ENV{HOME})->child($spec->{global}) | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | : path('.')->absolute->child($spec->{project}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | __END__ | ||||||||||||||||||||||||||||||||||||||||||