App-karr
view release on metacpan or search on metacpan
lib/App/karr/Cmd/Skill.pm view on Meta::CPAN
if ($self->json) {
$self->print_json(\@results);
}
}
sub _check {
my ($self) = @_;
my @agents = $self->_target_agents;
my $current = $self->_skill_content;
my @results;
my $outdated = 0;
for my $agent (@agents) {
my $file = $self->_skill_dir($agent)->child('SKILL.md');
unless ($file->exists) {
push @results, { agent => $agent, status => 'not installed' };
printf "%-12s not installed\n", $agent unless $self->json;
next;
}
my $installed = $file->slurp_utf8;
if ($installed eq $current) {
push @results, { agent => $agent, status => 'current' };
printf "%-12s current\n", $agent unless $self->json;
} else {
push @results, { agent => $agent, status => 'outdated' };
printf "%-12s outdated\n", $agent unless $self->json;
$outdated++;
}
}
if ($self->json) {
$self->print_json(\@results);
}
exit(1) if $outdated;
}
sub _update {
my ($self) = @_;
my @agents = $self->_target_agents;
my $content = $self->_skill_content;
my @results;
for my $agent (@agents) {
my $file = $self->_skill_dir($agent)->child('SKILL.md');
unless ($file->exists) {
push @results, { agent => $agent, status => 'not installed' };
printf "%-12s not installed (run 'karr skill install' first)\n", $agent unless $self->json;
next;
}
my $installed = $file->slurp_utf8;
if ($installed eq $content) {
push @results, { agent => $agent, status => 'current' };
printf "%-12s already current\n", $agent unless $self->json;
} else {
$file->spew_utf8($content);
push @results, { agent => $agent, status => 'updated' };
printf "%-12s updated\n", $agent unless $self->json;
}
}
if ($self->json) {
$self->print_json(\@results);
}
}
sub _target_agents {
my ($self) = @_;
if ($self->agent) {
my @names = split /,/, $self->agent;
for my $name (@names) {
die "Unknown agent: $name (known: " . join(', ', sort keys %AGENTS) . ")\n"
unless $AGENTS{$name};
}
return @names;
}
# Auto-detect: return agents whose directories exist, or all if none found
my @detected;
for my $name (sort keys %AGENTS) {
my $dir = $self->_skill_dir($name)->parent;
push @detected, $name if $dir->exists;
}
return @detected ? @detected : sort keys %AGENTS;
}
sub _skill_dir {
my ($self, $agent) = @_;
my $spec = $AGENTS{$agent} or die "Unknown agent: $agent\n";
my $base = $self->global
? path($ENV{HOME})->child($spec->{global})
: path('.')->child($spec->{project});
return $base->child('karr');
}
sub _skill_content {
my ($self) = @_;
# Try File::ShareDir (installed dist)
my $installed = eval {
require File::ShareDir;
my $dir = File::ShareDir::dist_dir('App-karr');
my $file = path($dir)->child('claude-skill.md');
$file->slurp_utf8 if $file->exists;
};
return $installed if defined $installed && length $installed;
# Fallback: relative to module location (development)
my $module_path = $INC{'App/karr/Cmd/Skill.pm'};
if ($module_path) {
my $share = path($module_path)->parent(5)->child('share/claude-skill.md');
return $share->slurp_utf8 if $share->exists;
}
die "Could not find claude-skill.md. Is App::karr properly installed?\n";
}
1;
( run in 0.317 second using v1.01-cache-2.11-cpan-bbe5e583499 )