Skilletor/Briefing.pm

filter: Statementstmt 74.1% 63 / 85 Branchbran 28.9% 11 / 38 Conditioncond 19.4% 7 / 36 MC/DCmcdc 9.5% 2 / 21 Subroutinesub 92.8% 13 / 14 Podpod 100% 4 / 4 totaltotal 50.5% 100 / 198 CC 36 SCAR 36.4
CC
36
Cov
51%
declared_skills
79.0
missing_skills
43.9
skill_roots
40.5
CRAP 38.1
« Skilletor/Process.pm ↑ Summary Skilletor/Engine.pm »
1 package Skilletor::Briefing;
2 # ABSTRACT: Are an installed agent's briefing skills there? (spec §6.7)
3  
4 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 31 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 31 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 31 ▶use Skilletor::FSUtil qw( encode_text path_join read_text );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 31 ▶use Skilletor::Frontmatter qw( split_frontmatter );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 31 ▶use Skilletor::JSON qw( js_sort_keys js_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 31 our $VERSION = '0.001';
15  
16 31 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 31 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 3 ▶sub declared_skills {
Subroutine declared_skills: called CC=12 SCAR=43.7
Pod documented
23 3 my ( $harness, $text ) = @_;
24 3 ▶ if ( $harness eq 'codex' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($harness eq "codex") 0 3 3
25 0 for my $line ( split /\n/, $text, -1 ) {
26 0 ▶ last if $line =~ /\Adeveloper_instructions[ \t]*=/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\Adeveloper_instructions[ \t]*=/ 0 0 0
27 0 ▶ next unless $line =~ $COMMENT;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /$COMMENT/ 0 0 0
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 0 return [];
34 }
35 3 ▶ my $fm = eval { split_frontmatter($text) } or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $fm = eval { do { split_frontmatter($text) } } or return undef 3 0 3
36 3 my $briefing = $fm->{data}{briefing};
37 3 ▶ return [] unless js_type($briefing) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($briefing) eq "object" 3 0 3
38 0 my $skills = $briefing->{skills};
39 0 ▶ return [] unless js_type($skills) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($skills) eq "array" 0 0 0
40 0 ▶ return [ grep { !ref $_ && js_type($_) eq 'string' && length } @$skills ];
Condition0%0/6
!ref($_) && js_type($_) eq 'string' && length $_
!ll&&!rl&&r
000
not ref $_ and js_type($_) eq "string"
!ll&&!rl&&r
000
MC/DC0%0/3
!ref($_) && js_type($_) eq 'string' && length $_
not ref $_ js_type($_) eq "string" length $_
Truth table0%0/4
not(A) and B && C
A= not ref $_B= js_type($_) eq "string"C= length $_
ABCresult
0XX0
10X0
1100
1111
41 }
42  
43 5 ▶sub _subdirs {
Subroutine _subdirs: called CC=4 SCAR=13.9
44 5 my ( $dir ) = @_;
45 5 ▶ opendir( my $dh, encode_text($dir) ) or return ();
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, encode_text($dir) or return () 2 3 5
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 4 ▶sub _plugin_cache_roots {
Subroutine _plugin_cache_roots: called CC=3 SCAR=11.0
53 4 my ( $claude_dir ) = @_;
54 4 my $cache = path_join( $claude_dir, 'plugins', 'cache' );
55 4 my @out;
56 4 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 4 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 4 ▶sub skill_roots {
Subroutine skill_roots: called CC=11 SCAR=37.0
Pod documented
66 4 my ( $harness, $scope, $r ) = @_;
67 4 ▶ 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'} ? : 0 4 4
Condition33%2/6
$scope eq "project" and defined $r->{"project_dir"} and length $r->{"project_dir"}
!ll&&!rl&&r
400
$scope eq "project" and defined $r->{"project_dir"}
!ll&&!rl&&r
400
MC/DC0%0/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 table25%1/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 4 ▶ if ( $harness eq 'codex' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($harness eq "codex") 0 4 4
69 0 ▶ 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'} ? : 0 0 0
Condition0%0/3
defined $r->{"codex_home"} and length $r->{"codex_home"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $r->{"codex_home"} and length $r->{"codex_home"}
defined $r->{"codex_home"} length $r->{"codex_home"}
Truth table0%0/3
A and B
A= defined $r->{"codex_home"}B= length $r->{"codex_home"}
ABresult
0X0
100
111
70 0 my @user = ( path_join( $codex_home, 'skills' ), path_join( $r->{home}, '.agents', 'skills' ) );
71 0 ▶ return $project ? [ path_join( $project, '.agents', 'skills' ), path_join( $project, '.codex', 'skills' ), @user ] : \@user;
Branch: 1 branch
BranchTrueFalseTotal
$project ? : 0 0 0
72 }
73 4 ▶ 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'} ? : 4 0 4
Condition33%1/3
defined $r->{"claude_dir"} and length $r->{"claude_dir"}
!ll&&!rl&&r
004
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 4 ▶ return [ ( $project ? path_join( $project, '.claude', 'skills' ) : () ), path_join( $claude_dir, 'skills' ),
Branch: 1 branch
BranchTrueFalseTotal
$project ? : 0 4 4
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 3 ▶sub missing_skills {
Subroutine missing_skills: called CC=10 SCAR=37.8
Pod documented
81 3 my ( $harness, $file, $roots ) = @_;
82 3 my $text = eval { read_text($file) };
83 3 ▶ return undef unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 3 3
84 3 ▶ my $declared = declared_skills( $harness, $text ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $declared = declared_skills($harness, $text) or return undef 3 0 3
85 3 my @missing;
86 3 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 0 0
Condition0%0/3
index($name, ":") != -1 or grep {$_ eq $name;} @missing
l!l&&r!l&&!r
000
MC/DC0%0/2
index($name, ":") != -1 or grep {$_ eq $name;} @missing
index($name, ":") != -1 grep {$_ eq $name;} @missing
Truth table0%0/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 0 ▶ my $segment = $name !~ m{[\\/]} && $name ne '.' && $name ne '..';
Condition0%0/6
!($name =~ m[[\\/]]) && $name ne '.' && $name ne '..'
!ll&&!rl&&r
000
not $name =~ m[[\\/]] and $name ne "."
!ll&&!rl&&r
000
MC/DC0%0/3
!($name =~ m[[\\/]]) && $name ne '.' && $name ne '..'
not $name =~ m[[\\/]] $name ne "." $name ne '..'
Truth table0%0/4
not(A) and B && C
A= not $name =~ m[[\\/]]B= $name ne "."C= $name ne '..'
ABCresult
0XX0
10X0
1100
1111
90 0 ▶ 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 0 0 0
Condition0%0/3
$segment and grep {-e encode_text(path_join($_, $name, "SKILL.md"));} @$roots
!ll&&!rl&&r
000
MC/DC0%0/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 table0%0/3
A and B
A= $segmentB= grep {-e encode_text(path_join($_, $name, "SKILL.md"));} @$roots
ABresult
0X0
100
111
91 }
92 3 return \@missing;
93 }
94  
95 0 ▶sub briefing_warning {
Subroutine briefing_warning: not called CC=1 SCAR=6.9
Pod documented
96 0 my ( $name, $harness, $missing ) = @_;
97 0 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 31 1;
102  
103 __END__
« Skilletor/Process.pm ↑ Summary Skilletor/Engine.pm »