lib/Skilletor/Briefing.pm

filter: Statementstmt 94.1% 80 / 85 Branchbran 65.7% 25 / 38 Conditioncond 47.2% 17 / 36 MC/DCmcdc 19.0% 4 / 21 Subroutinesub 100% 14 / 14 Podpod 100% 4 / 4 totaltotal 72.7% 144 / 198 CC 36 SCAR 24.3
CC
36
Cov
77%
declared_skills
19.6
missing_skills
13.7
skill_roots
13.7
CRAP 11.4
« lib/Skilletor/Convert.pm ↑ Summary lib/Skilletor/Lock.pm »
1 package Skilletor::Briefing;
2 # ABSTRACT: Are an installed agent's briefing skills there? (spec §6.7)
3  
4 464 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 464 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 464 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 464 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 464 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 464 ▶use Skilletor::FSUtil qw( encode_text path_join read_text );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 464 ▶use Skilletor::Frontmatter qw( split_frontmatter );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 464 ▶use Skilletor::JSON qw( js_sort_keys js_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 464 our $VERSION = '0.008000';
15  
16 464 our @EXPORT_OK = qw( declared_skills skill_roots missing_skills briefing_warning );
17  
18 # briefing's own matcher for the Codex comment line (spec §14.7).
19 464 my $COMMENT = qr/\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/;
20  
21 # The skills an installed agent file declares; undef when it cannot be read.
22 302 ▶sub declared_skills {
Subroutine declared_skills: called CC=12 SCAR=29.8
Pod documented
23 302 my ( $harness, $text ) = @_;
24 302 ▶ if ( $harness eq 'codex' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($harness eq "codex") 15 287 302
25 15 for my $line ( split /\n/, $text, -1 ) {
26 45 ▶ last if $line =~ /\Adeveloper_instructions[ \t]*=/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\Adeveloper_instructions[ \t]*=/ 15 30 45
27 30 ▶ next unless $line =~ $COMMENT;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /$COMMENT/ 30 0 30
28 0 my $list = $1;
29 0 my @out;
30 0 ▶ push @out, defined $1 ? $1 : $2 while $list =~ /"([^"]*)"|'([^']*)'/g;
Branch: 2 branches
BranchTrueFalseTotal
$list =~ /"([^"]*)"|'([^']*)'/g and do { push @out, defined $1 ? $1 : $2 } 0 0 0
defined $1 ? : 0 0 0
31 0 return \@out;
32 }
33 15 return [];
34 }
35 287 ▶ my $fm = eval { split_frontmatter($text) } or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $fm = eval { do { split_frontmatter($text) } } or return undef 287 0 287
36 287 my $briefing = $fm->{data}{briefing};
37 287 ▶ return [] unless js_type($briefing) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($briefing) eq "object" 282 5 287
38 5 my $skills = $briefing->{skills};
39 5 ▶ return [] unless js_type($skills) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($skills) eq "array" 0 5 5
40 5 ▶ return [ grep { !ref $_ && js_type($_) eq 'string' && length } @$skills ];
Condition33%2/6
!ref($_) && js_type($_) eq 'string' && length $_
!ll&&!rl&&r
0010
not ref $_ and js_type($_) eq "string"
!ll&&!rl&&r
0010
MC/DC0%0/3
!ref($_) && js_type($_) eq 'string' && length $_
not ref $_ js_type($_) eq "string" length $_
Truth table25%1/4
not(A) and B && C
A= not ref $_B= js_type($_) eq "string"C= length $_
ABCresult
0XX0
10X0
1100
1111
41 }
42  
43 244 ▶sub _subdirs {
Subroutine _subdirs: called CC=4 SCAR=13.9
44 244 my ( $dir ) = @_;
45 244 ▶ opendir( my $dh, encode_text($dir) ) or return ();
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, encode_text($dir) or return () 2 242 244
46 2 ▶ my @names = grep { $_ ne '.' && $_ ne '..' } readdir $dh;
Condition100%3/3
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
222
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
47 2 closedir $dh;
48 2 ▶ return js_sort_keys( grep { my $p = encode_text( path_join( $dir, $_ ) ); !-l $p && -d $p } map { Encode::decode( 'UTF-8', $_ ) } @names );
Condition33%1/3
!(-l $p) && -d $p
!ll&&!rl&&r
002
MC/DC0%0/2
!(-l $p) && -d $p
!(-l $p) -d $p
Truth table33%1/3
not(A) && B
A= !(-l $p)B= -d $p
ABresult
0X0
100
111
49 }
50  
51 # <claude config dir>/plugins/cache/*/skills and …/cache/*/*/skills, as far as they exist.
52 243 ▶sub _plugin_cache_roots {
Subroutine _plugin_cache_roots: called CC=3 SCAR=11.0
53 243 my ( $claude_dir ) = @_;
54 243 my $cache = path_join( $claude_dir, 'plugins', 'cache' );
55 243 my @out;
56 243 for my $a ( _subdirs($cache) ) {
57 1 push @out, path_join( $cache, $a, 'skills' );
58 1 push @out, path_join( $cache, $a, $_, 'skills' ) for _subdirs( path_join( $cache, $a ) );
59 }
60 243 return @out;
61 }
62  
63 # The skill roots the harness's briefing lookup searches for an agent of this scope.
64 # $r: { home, claude_dir?, codex_home?, project_dir? }; claude_dir defaults to <home>/.claude.
65 258 ▶sub skill_roots {
Subroutine skill_roots: called CC=11 SCAR=26.2
Pod documented
66 258 my ( $harness, $scope, $r ) = @_;
67 258 ▶ my $project = ( $scope eq 'project' && defined $r->{project_dir} && length $r->{project_dir} ) ? $r->{project_dir} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'project' && defined $r->{'project_dir'} && length $r->{'project_dir'} ? : 56 202 258
Condition66%4/6
$scope eq "project" and defined $r->{"project_dir"} and length $r->{"project_dir"}
!ll&&!rl&&r
202056
$scope eq "project" and defined $r->{"project_dir"}
!ll&&!rl&&r
202056
MC/DC33%1/3
$scope eq "project" and defined $r->{"project_dir"} and length $r->{"project_dir"}
$scope eq "project" defined $r->{"project_dir"} length $r->{"project_dir"}
Truth table50%2/4
A and B and C
A= $scope eq "project"B= defined $r->{"project_dir"}C= length $r->{"project_dir"}
ABCresult
0XX0
10X0
1100
1111
68 258 ▶ if ( $harness eq 'codex' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($harness eq "codex") 15 243 258
69 15 ▶ my $codex_home = ( defined $r->{codex_home} && length $r->{codex_home} ) ? $r->{codex_home} : path_join( $r->{home}, '.codex' );
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'codex_home'} && length $r->{'codex_home'} ? : 15 0 15
Condition33%1/3
defined $r->{"codex_home"} and length $r->{"codex_home"}
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $r->{"codex_home"} and length $r->{"codex_home"}
defined $r->{"codex_home"} length $r->{"codex_home"}
Truth table33%1/3
A and B
A= defined $r->{"codex_home"}B= length $r->{"codex_home"}
ABresult
0X0
100
111
70 15 my @user = ( path_join( $codex_home, 'skills' ), path_join( $r->{home}, '.agents', 'skills' ) );
71 15 ▶ return $project ? [ path_join( $project, '.agents', 'skills' ), path_join( $project, '.codex', 'skills' ), @user ] : \@user;
Branch: 1 branch
BranchTrueFalseTotal
$project ? : 0 15 15
72 }
73 243 ▶ my $claude_dir = ( defined $r->{claude_dir} && length $r->{claude_dir} ) ? $r->{claude_dir} : path_join( $r->{home}, '.claude' );
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'claude_dir'} && length $r->{'claude_dir'} ? : 243 0 243
Condition33%1/3
defined $r->{"claude_dir"} and length $r->{"claude_dir"}
!ll&&!rl&&r
00243
MC/DC0%0/2
defined $r->{"claude_dir"} and length $r->{"claude_dir"}
defined $r->{"claude_dir"} length $r->{"claude_dir"}
Truth table33%1/3
A and B
A= defined $r->{"claude_dir"}B= length $r->{"claude_dir"}
ABresult
0X0
100
111
74 243 ▶ return [ ( $project ? path_join( $project, '.claude', 'skills' ) : () ), path_join( $claude_dir, 'skills' ),
Branch: 1 branch
BranchTrueFalseTotal
$project ? : 56 187 243
75 _plugin_cache_roots($claude_dir) ];
76 }
77  
78 # Bare declared skill names of the agent file that resolve in none of the roots; undef when the
79 # file cannot be read or parsed.
80 302 ▶sub missing_skills {
Subroutine missing_skills: called CC=10 SCAR=26.2
Pod documented
81 302 my ( $harness, $file, $roots ) = @_;
82 302 my $text = eval { read_text($file) };
83 302 ▶ return undef unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 302 302
84 302 ▶ my $declared = declared_skills( $harness, $text ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $declared = declared_skills($harness, $text) or return undef 302 0 302
85 302 my @missing;
86 302 for my $name (@$declared) {
87 0 ▶ next if index( $name, ':' ) >= 0 || grep { $_ eq $name } @missing;
Branch: 1 branch
BranchTrueFalseTotal
if index($name, ":") != -1 or grep {$_ eq $name;} @missing 0 10 10
Condition33%1/3
index($name, ":") != -1 or grep {$_ eq $name;} @missing
l!l&&r!l&&!r
0010
MC/DC0%0/2
index($name, ":") != -1 or grep {$_ eq $name;} @missing
index($name, ":") != -1 grep {$_ eq $name;} @missing
Truth table33%1/3
A or B
A= index($name, ":") != -1B= grep {$_ eq $name;} @missing
ABresult
1X1
011
000
88 # A name that is not one path segment resolves nowhere (and is never probed).
89 10 ▶ my $segment = $name !~ m{[\\/]} && $name ne '.' && $name ne '..';
Condition33%2/6
!($name =~ m[[\\/]]) && $name ne '.' && $name ne '..'
!ll&&!rl&&r
0010
not $name =~ m[[\\/]] and $name ne "."
!ll&&!rl&&r
0010
MC/DC0%0/3
!($name =~ m[[\\/]]) && $name ne '.' && $name ne '..'
not $name =~ m[[\\/]] $name ne "." $name ne '..'
Truth table25%1/4
not(A) and B && C
A= not $name =~ m[[\\/]]B= $name ne "."C= $name ne '..'
ABCresult
0XX0
10X0
1100
1111
90 10 ▶ push @missing, $name if !$segment || !grep { -e encode_text( path_join( $_, $name, 'SKILL.md' ) ) } @$roots;
Branch: 1 branch
BranchTrueFalseTotal
unless $segment and grep {-e encode_text(path_join($_, $name, "SKILL.md"));} @$roots 5 5 10
Condition66%2/3
$segment and grep {-e encode_text(path_join($_, $name, "SKILL.md"));} @$roots
!ll&&!rl&&r
055
MC/DC50%1/2
$segment and grep {-e encode_text(path_join($_, $name, "SKILL.md"));} @$roots
$segment grep {-e encode_text(path_join($_, $name, "SKILL.md"));} @$roots
Truth table66%2/3
A and B
A= $segmentB= grep {-e encode_text(path_join($_, $name, "SKILL.md"));} @$roots
ABresult
0X0
100
111
91 }
92 302 return \@missing;
93 }
94  
95 8 ▶sub briefing_warning {
Subroutine briefing_warning: called CC=1 SCAR=0.0
Pod documented
96 8 my ( $name, $harness, $missing ) = @_;
97 8 return 'agent '.$name.' ('.$harness.'): briefing skills not installed: '.join( ', ', @$missing ).' — '
98 .'install them, or ship the agent and its skills together as a bundle';
99 }
100  
101 464 1;
102  
103 __END__
« lib/Skilletor/Convert.pm ↑ Summary lib/Skilletor/Lock.pm »