lib/App/Briefing.pm

filter: Statementstmt 60.9% 521 / 855 Branchbran 45.0% 229 / 508 Conditioncond 34.7% 73 / 210 MC/DCmcdc 20.0% 26 / 130 Subroutinesub 66.9% 71 / 106 Podpod 77.7% 7 / 9 totaltotal 50.9% 927 / 1818 CC 537 SCAR 30.3
CC
537
Cov
52%
_toml_string_state
103.7
_toml_string_state
103.7
_resolve_codex_plugin_skill
72.0
CRAP 20.7
« lib/App/Briefing/Filesystem.pm ↑ Summary script/briefing »
1 package App::Briefing;
2 # ABSTRACT: Preload declared skills into Claude Code and Codex subagents at spawn time
3  
4 134 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 134 ▶use App::Briefing::Filesystem;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 134 ▶use B qw( SVf_POK SVp_POK svref_2object );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 134 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 134 ▶use Encode qw( encode_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 134 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 134 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 134 our $VERSION = '0.006000';
13  
14 134 ▶use constant BUDGET_BYTES => 64 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 134 has filesystem => ( is => 'lazy' );
17  
18  
19 134 has cwd => ( is => 'lazy' );
20  
21  
22 134 has home => ( is => 'lazy' );
23  
24  
25 134 has codex_home => ( is => 'lazy' );
26  
27  
28 134 has _json => ( is => 'lazy', init_arg => undef );
29  
30 120 ▶sub filesystem_class { 'App::Briefing::Filesystem' }
Subroutine filesystem_class: called CC=1 SCAR=0.0
Pod undocumented
31 1 ▶sub toml_parser_class { 'TOML::Tiny::Parser' }
Subroutine toml_parser_class: called CC=1 SCAR=0.0
Pod undocumented
32  
33 120 ▶sub _build_filesystem {
Subroutine _build_filesystem: called CC=1 SCAR=1.2
34 0 ▶ my ( $self ) = @_;
Subroutine _build_filesystem: not called CC=1 SCAR=1.2
35 0 return $self->filesystem_class->new;
36 }
37  
38 21 ▶sub _build_cwd {
Subroutine _build_cwd: called CC=2 SCAR=11.6
39 0 ▶ my ( $self ) = @_;
Subroutine _build_cwd: not called CC=2 SCAR=11.6
40 0 my $pwd = $self->filesystem->environment_value('PWD');
41 0 ▶ return $pwd if defined $pwd;
Branch: 2 branches
BranchTrueFalseTotal
if defined $pwd 21 0 21
if defined $pwd 0 0 0
42 0 return $self->filesystem->current_dir;
43 }
44  
45 113 ▶sub _build_home {
Subroutine _build_home: called CC=8 SCAR=34.4
46 0 ▶ my ( $self ) = @_;
Subroutine _build_home: not called CC=8 SCAR=34.4
47 0 my $value = $self->filesystem->environment_value('HOME');
48 0 ▶ return $value if defined $value;
Branch: 2 branches
BranchTrueFalseTotal
if defined $value 109 4 113
if defined $value 0 0 0
49  
50 0 ▶ if ($self->filesystem->is_windows) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->filesystem->is_windows) 4 0 4
if ($self->filesystem->is_windows) 0 0 0
51 0 $value = $self->filesystem->environment_value('USERPROFILE');
52 0 ▶ return $value if defined $value;
Branch: 2 branches
BranchTrueFalseTotal
if defined $value 3 1 4
if defined $value 0 0 0
53 0 my $drive = $self->filesystem->environment_value('HOMEDRIVE');
54 0 my $path = $self->filesystem->environment_value('HOMEPATH');
55 0 ▶ return $drive.$path if defined $drive && defined $path;
Branch: 2 branches
BranchTrueFalseTotal
if defined $drive and defined $path 1 0 1
if defined $drive and defined $path 0 0 0
Condition16%1/6
defined $drive and defined $path
!ll&&!rl&&r
001
defined $drive and defined $path
!ll&&!rl&&r
000
MC/DC0%0/2
defined $drive and defined $path
defined $drive defined $path
MC/DC0%0/2
defined $drive and defined $path
defined $drive defined $path
Truth table33%1/3
A and B
A= defined $driveB= defined $path
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $driveB= defined $path
ABresult
0X0
100
111
56 }
57  
58 0 my $home = (getpwuid $<)[7];
59 0 ▶ return $self->filesystem->decode_path($home) if defined $home && length $home;
Branch: 2 branches
BranchTrueFalseTotal
if defined $home and length $home 0 0 0
if defined $home and length $home 0 0 0
Condition0%0/6
defined $home and length $home
!ll&&!rl&&r
000
defined $home and length $home
!ll&&!rl&&r
000
MC/DC0%0/2
defined $home and length $home
defined $home length $home
MC/DC0%0/2
defined $home and length $home
defined $home length $home
Truth table0%0/3
A and B
A= defined $homeB= length $home
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $homeB= length $home
ABresult
0X0
100
111
60 0 return $self->filesystem->current_dir;
61 }
62  
63 89 ▶sub _build_codex_home {
Subroutine _build_codex_home: called CC=2 SCAR=11.6
64 0 ▶ my ( $self ) = @_;
Subroutine _build_codex_home: not called CC=2 SCAR=11.6
65 0 my $codex_home = $self->filesystem->environment_value('CODEX_HOME');
66 0 ▶ return $codex_home if defined $codex_home;
Branch: 2 branches
BranchTrueFalseTotal
if defined $codex_home 89 0 89
if defined $codex_home 0 0 0
67 0 return $self->filesystem->join_path( $self->home, '.codex' );
68 }
69  
70 20 ▶sub _build__json {
Subroutine _build__json: called CC=1 SCAR=1.2
71 0 ▶ my ( $self ) = @_;
Subroutine _build__json: not called CC=1 SCAR=1.2
72 0 return JSON::MaybeXS->new(
73 allow_nonref => 0,
74 canonical => 1,
75 convert_blessed => 1,
76 utf8 => 0,
77 );
78 }
79  
80 1248 ▶sub _is_string {
Subroutine _is_string: called CC=4 SCAR=19.9
81 0 ▶ my ( $self, $value ) = @_;
Subroutine _is_string: not called CC=4 SCAR=19.9
82 0 ▶ return 0 unless defined $value && !ref $value;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value and not ref $value 105 1143 1248
unless defined $value and not ref $value 0 0 0
Condition33%2/6
defined $value and not ref $value
!ll&&!rl&&r
10501143
defined $value and not ref $value
!ll&&!rl&&r
000
MC/DC50%1/2
defined $value and not ref $value
defined $value not ref $value
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table66%2/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
83 0 my $flags = svref_2object( \$value )->FLAGS;
84 0 ▶ return $flags & ( SVf_POK | SVp_POK ) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$flags & 17408 ? : 1143 0 1143
$flags & 17408 ? : 0 0 0
85 }
86  
87 632 ▶sub _nonempty_string {
Subroutine _nonempty_string: called CC=3 SCAR=15.4
88 0 ▶ my ( $self, $value ) = @_;
Subroutine _nonempty_string: not called CC=3 SCAR=15.4
89 0 ▶ return $self->_is_string($value) && length $value ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$self->_is_string($value) && length $value ? : 608 24 632
$self->_is_string($value) && length $value ? : 0 0 0
Condition33%2/6
$self->_is_string($value) and length $value
!ll&&!rl&&r
240608
$self->_is_string($value) and length $value
!ll&&!rl&&r
000
MC/DC50%1/2
$self->_is_string($value) and length $value
$self->_is_string($value) length $value
MC/DC0%0/2
$self->_is_string($value) and length $value
$self->_is_string($value) length $value
Truth table66%2/3
A and B
A= $self->_is_string($value)B= length $value
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->_is_string($value)B= length $value
ABresult
0X0
100
111
90 }
91  
92 891 ▶sub _trim {
Subroutine _trim: called CC=2 SCAR=10.1
93 0 ▶ my ( $self, $value ) = @_;
Subroutine _trim: not called CC=2 SCAR=10.1
94 0 ▶ $value = '' unless defined $value;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value 0 891 891
unless defined $value 0 0 0
95 0 $value =~ s/\A\s+//;
96 0 $value =~ s/\s+\z//;
97 0 return $value;
98 }
99  
100 894 ▶sub _split_frontmatter {
Subroutine _split_frontmatter: called CC=3 SCAR=15.1
101 0 ▶ my ( $self, $text ) = @_;
Subroutine _split_frontmatter: not called CC=3 SCAR=15.1
102 0 ▶ $text = '' unless defined $text;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $text 0 894 894
unless defined $text 0 0 0
103 0 $text =~ s/\A(?:\x{FEFF}|\xEF\xBB\xBF)//;
104 0 ▶ return ( $1, $2 )
Branch: 2 branches
BranchTrueFalseTotal
if $text =~ /\A---\r?\n(.*?)\r?\n---\r?\n(.*)\z/s 874 20 894
if $text =~ /\A---\r?\n(.*?)\r?\n---\r?\n(.*)\z/s 0 0 0
105 if $text =~ /\A---\r?\n(.*?)\r?\n---\r?\n(.*)\z/s;
106 0 return ( '', $text );
107 }
108  
109 359 ▶sub _dedent {
Subroutine _dedent: called CC=5 SCAR=23.0
110 0 ▶ my ( $self, $block ) = @_;
Subroutine _dedent: not called CC=5 SCAR=23.0
111 0 my @lines = split /\r?\n/, $block, -1;
112 my @indents = map {
113 0 my ( $indent ) = /\A([ \t]*)/;
114 0 length $indent;
115 0 } grep { /\S/ } @lines;
116 0 ▶ return $block unless @indents;
Branch: 2 branches
BranchTrueFalseTotal
unless @indents 0 359 359
unless @indents 0 0 0
117  
118 0 my $common = $indents[0];
119 0 for my $indent (@indents) {
120 0 ▶ $common = $indent if $indent < $common;
Branch: 2 branches
BranchTrueFalseTotal
if $indent < $common 0 725 725
if $indent < $common 0 0 0
121 }
122 0 ▶ return join( "\n", map { length($_) >= $common ? substr( $_, $common ) : $_ } @lines );
Branch: 2 branches
BranchTrueFalseTotal
length $_ >= $common ? : 725 0 725
length $_ >= $common ? : 0 0 0
123 }
124  
125 369 ▶sub _parse_skills_list {
Subroutine _parse_skills_list: called CC=10 SCAR=33.4
126 0 ▶ my ( $self, $frontmatter ) = @_;
Subroutine _parse_skills_list: not called CC=10 SCAR=33.4
127 0 ▶ return [] unless defined $frontmatter && length $frontmatter;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $frontmatter and length $frontmatter 0 369 369
unless defined $frontmatter and length $frontmatter 0 0 0
Condition16%1/6
defined $frontmatter and length $frontmatter
!ll&&!rl&&r
00369
defined $frontmatter and length $frontmatter
!ll&&!rl&&r
000
MC/DC0%0/2
defined $frontmatter and length $frontmatter
defined $frontmatter length $frontmatter
MC/DC0%0/2
defined $frontmatter and length $frontmatter
defined $frontmatter length $frontmatter
Truth table33%1/3
A and B
A= defined $frontmatterB= length $frontmatter
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $frontmatterB= length $frontmatter
ABresult
0X0
100
111
128 0 ▶ return [] unless $frontmatter =~ /^briefing:[ \t]*\r?\n((?:[ \t]+[^\r\n]*(?:\r?\n|$))+)/m;
Branch: 2 branches
BranchTrueFalseTotal
unless $frontmatter =~ /^briefing:[ \t]*\r?\n((?:[ \t]+[^\r\n]*(?:\r?\n|$))+)/m 10 359 369
unless $frontmatter =~ /^briefing:[ \t]*\r?\n((?:[ \t]+[^\r\n]*(?:\r?\n|$))+)/m 0 0 0
129  
130 0 my $block = $self->_dedent($1);
131 0 ▶ if ($block =~ /^skills:[ \t]*\r?\n((?:[ \t]*-[ \t]*[^\r\n]+\r?\n?)+)/m) {
Branch: 2 branches
BranchTrueFalseTotal
if ($block =~ /^skills:[ \t]*\r?\n((?:[ \t]*-[ \t]*[^\r\n]+\r?\n?)+)/m) 354 5 359
if ($block =~ /^skills:[ \t]*\r?\n((?:[ \t]*-[ \t]*[^\r\n]+\r?\n?)+)/m) 0 0 0
132 0 my $items = $1;
133 0 my @skills;
134 0 ▶ while ($items =~ /^[ \t]*-[ \t]*(["']?)([^"'\r\n]+)\1[ \t]*$/mg) {
Branch: 2 branches
BranchTrueFalseTotal
if ($items =~ /^[ \t]*-[ \t]*(["']?)([^"'\r\n]+)\1[ \t]*$/gm) 363 354 717
if ($items =~ /^[ \t]*-[ \t]*(["']?)([^"'\r\n]+)\1[ \t]*$/gm) 0 0 0
135 0 my $skill = $self->_trim($2);
136 0 ▶ push @skills, $skill if length $skill;
Branch: 2 branches
BranchTrueFalseTotal
if length $skill 363 0 363
if length $skill 0 0 0
137 }
138 0 return \@skills;
139 }
140  
141 0 ▶ if ($block =~ /^skills:[ \t]*\[([^\]\r\n]+)\]/m) {
Branch: 2 branches
BranchTrueFalseTotal
if ($block =~ /^skills:[ \t]*\[([^\]\r\n]+)\]/m) 2 3 5
if ($block =~ /^skills:[ \t]*\[([^\]\r\n]+)\]/m) 0 0 0
142 0 my @skills;
143 0 for my $item (split /,/, $1) {
144 0 $item = $self->_trim($item);
145 0 $item =~ s/\A["']//;
146 0 $item =~ s/["']\z//;
147 0 ▶ push @skills, $item if length $item;
Branch: 2 branches
BranchTrueFalseTotal
if length $item 4 0 4
if length $item 0 0 0
148 }
149 0 return \@skills;
150 }
151 0 return [];
152 }
153  
154 321 ▶sub _parse_frontmatter_name {
Subroutine _parse_frontmatter_name: called CC=3 SCAR=15.3
155 0 ▶ my ( $self, $frontmatter ) = @_;
Subroutine _parse_frontmatter_name: not called CC=3 SCAR=15.3
156 0 ▶ return unless defined $frontmatter;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $frontmatter 0 321 321
unless defined $frontmatter 0 0 0
157 0 ▶ return $self->_trim($2)
Branch: 2 branches
BranchTrueFalseTotal
if $frontmatter =~ /^name:[ \t]*(["']?)([^"'\r\n]+?)\1[ \t]*$/m 318 3 321
if $frontmatter =~ /^name:[ \t]*(["']?)([^"'\r\n]+?)\1[ \t]*$/m 0 0 0
158 if $frontmatter =~ /^name:[ \t]*(["']?)([^"'\r\n]+?)\1[ \t]*$/m;
159 0 return;
160 }
161  
162 297 ▶sub _find_first_readable {
Subroutine _find_first_readable: called CC=5 SCAR=24.1
163 0 ▶ my ( $self, @files ) = @_;
Subroutine _find_first_readable: not called CC=5 SCAR=24.1
164 0 for my $file (@files) {
165 0 ▶ next unless defined $file && length $file;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $file and length $file 0 297 297
unless defined $file and length $file 0 0 0
Condition16%1/6
defined $file and length $file
!ll&&!rl&&r
00297
defined $file and length $file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and length $file
defined $file length $file
MC/DC0%0/2
defined $file and length $file
defined $file length $file
Truth table33%1/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
166 0 ▶ return $file if $self->filesystem->is_readable_file($file);
Branch: 2 branches
BranchTrueFalseTotal
if $self->filesystem->is_readable_file($file) 294 3 297
if $self->filesystem->is_readable_file($file) 0 0 0
167 }
168 0 return;
169 }
170  
171 303 ▶sub _claude_agent_roots {
Subroutine _claude_agent_roots: called CC=1 SCAR=1.2
172 0 ▶ my ( $self ) = @_;
Subroutine _claude_agent_roots: not called CC=1 SCAR=1.2
173 return (
174 0 $self->filesystem->join_path( $self->cwd, '.claude', 'agents' ),
175 $self->filesystem->join_path( $self->home, '.claude', 'agents' ),
176 );
177 }
178  
179 321 ▶sub _claude_agent_name {
Subroutine _claude_agent_name: called CC=2 SCAR=9.2
180 0 ▶ my ( $self, $file ) = @_;
Subroutine _claude_agent_name: not called CC=2 SCAR=9.2
181 0 my ( $frontmatter ) = $self->_split_frontmatter(
182 $self->filesystem->slurp_utf8($file),
183 );
184 0 my $name = $self->_parse_frontmatter_name($frontmatter);
185 0 ▶ return $name if defined $name;
Branch: 2 branches
BranchTrueFalseTotal
if defined $name 318 3 321
if defined $name 0 0 0
186 0 my $basename = $self->filesystem->basename($file);
187 0 $basename =~ s/\.md\z//;
188 0 return $basename;
189 }
190  
191 296 ▶sub _find_claude_agent {
Subroutine _find_claude_agent: called CC=8 SCAR=27.7
192 0 ▶ my ( $self, $agent ) = @_;
Subroutine _find_claude_agent: not called CC=8 SCAR=27.7
193 0 for my $root ($self->_claude_agent_roots) {
194 0 ▶ next unless $self->filesystem->is_dir($root);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->filesystem->is_dir($root) 5 296 301
unless $self->filesystem->is_dir($root) 0 0 0
195 0 my $direct = $self->filesystem->join_path( $root, $agent.'.md' );
196 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_find_first_readable($direct) and $self->_claude_agent_name($direct) eq $agent) 289 7 296
if ($self->_find_first_readable($direct) and $self->_claude_agent_name($direct) eq $agent) 0 0 0
Condition50%3/6
$self->_find_first_readable($direct) and $self->_claude_agent_name($direct) eq $agent
!ll&&!rl&&r
34289
$self->_find_first_readable($direct) and $self->_claude_agent_name($direct) eq $agent
!ll&&!rl&&r
000
MC/DC100%2/2
$self->_find_first_readable($direct) and $self->_claude_agent_name($direct) eq $agent
$self->_find_first_readable($direct) $self->_claude_agent_name($direct) eq $agent
MC/DC0%0/2
$self->_find_first_readable($direct) and $self->_claude_agent_name($direct) eq $agent
$self->_find_first_readable($direct) $self->_claude_agent_name($direct) eq $agent
Truth table100%3/3
A and B
A= $self->_find_first_readable($direct)B= $self->_claude_agent_name($direct) eq $agent
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->_find_first_readable($direct)B= $self->_claude_agent_name($direct) eq $agent
ABresult
0X0
100
111
197 $self->_find_first_readable($direct)
198 && $self->_claude_agent_name($direct) eq $agent
199 ) {
200 0 return $direct;
201 }
202 0 for my $file (@{ $self->filesystem->walk_files( $root, '.md' ) }) {
203 0 ▶ next if $file eq $direct;
Branch: 2 branches
BranchTrueFalseTotal
if $file eq $direct 4 19 23
if $file eq $direct 0 0 0
204 0 ▶ return $file if $self->_claude_agent_name($file) eq $agent;
Branch: 2 branches
BranchTrueFalseTotal
if $self->_claude_agent_name($file) eq $agent 2 17 19
if $self->_claude_agent_name($file) eq $agent 0 0 0
205 }
206 }
207 0 return;
208 }
209  
210 7 ▶sub _list_claude_agents {
Subroutine _list_claude_agents: called CC=5 SCAR=21.9
211 0 ▶ my ( $self ) = @_;
Subroutine _list_claude_agents: not called CC=5 SCAR=21.9
212 0 my %agents;
213 0 for my $root ($self->_claude_agent_roots) {
214 0 ▶ next unless $self->filesystem->is_dir($root);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->filesystem->is_dir($root) 8 6 14
unless $self->filesystem->is_dir($root) 0 0 0
215 0 for my $file (@{ $self->filesystem->walk_files( $root, '.md' ) }) {
216 0 my $name = $self->_claude_agent_name($file);
217 0 ▶ $agents{$name} = $file unless exists $agents{$name};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $agents{$name} 9 0 9
unless exists $agents{$name} 0 0 0
218 }
219 }
220 0 return \%agents;
221 }
222  
223 111 ▶sub _load_json {
Subroutine _load_json: called CC=3 SCAR=15.1
224 0 ▶ my ( $self, $file ) = @_;
Subroutine _load_json: not called CC=3 SCAR=15.1
225 0 my $text = $self->filesystem->slurp_utf8($file);
226 0 ▶ my $data = eval { $self->_json->decode( length($text) ? $text : '{}' ) };
Branch: 2 branches
BranchTrueFalseTotal
length $text ? : 54 57 111
length $text ? : 0 0 0
227 0 ▶ return ref $data eq 'HASH' ? $data : {};
Branch: 2 branches
BranchTrueFalseTotal
ref $data eq 'HASH' ? : 111 0 111
ref $data eq 'HASH' ? : 0 0 0
228 }
229  
230 18 ▶sub _enabled_plugins {
Subroutine _enabled_plugins: called CC=6 SCAR=23.5
231 0 ▶ my ( $self ) = @_;
Subroutine _enabled_plugins: not called CC=6 SCAR=23.5
232 0 my %enabled;
233 0 for my $file (
234 $self->filesystem->join_path( $self->home, '.claude', 'settings.json' ),
235 $self->filesystem->join_path( $self->cwd, '.claude', 'settings.json' ),
236 $self->filesystem->join_path( $self->cwd, '.claude', 'settings.local.json' ),
237 ) {
238 0 my $values = $self->_load_json($file)->{enabledPlugins};
239 0 ▶ next unless ref $values eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $values eq "HASH" 18 36 54
unless ref $values eq "HASH" 0 0 0
240 0 for my $key (keys %{$values}) {
241 0 ▶ next unless JSON::MaybeXS::is_bool( $values->{$key} );
Branch: 2 branches
BranchTrueFalseTotal
unless JSON::MaybeXS::is_bool($values->{$key}) 3 51 54
unless JSON::MaybeXS::is_bool($values->{$key}) 0 0 0
242 0 ▶ $enabled{$key} = $values->{$key} ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$values->{$key} ? : 48 3 51
$values->{$key} ? : 0 0 0
243 }
244 }
245 0 return \%enabled;
246 }
247  
248 45 ▶sub _claude_plugins {
Subroutine _claude_plugins: called CC=14 SCAR=42.4
249 0 ▶ my ( $self ) = @_;
Subroutine _claude_plugins: not called CC=14 SCAR=42.4
250 my $registry = $self->_load_json(
251 $self->filesystem->join_path(
252 $self->home,
253 '.claude',
254 'plugins',
255 'installed_plugins.json',
256 ),
257 0 )->{plugins};
258 0 ▶ return [] unless ref $registry eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $registry eq "HASH" 27 18 45
unless ref $registry eq "HASH" 0 0 0
259  
260 0 my $enabled = $self->_enabled_plugins;
261 0 my @found;
262 0 for my $key (keys %{$registry}) {
263 0 ▶ next unless $enabled->{$key};
Branch: 2 branches
BranchTrueFalseTotal
unless $enabled->{$key} 6 12 18
unless $enabled->{$key} 0 0 0
264 0 my $entries = $registry->{$key};
265 0 ▶ next unless ref $entries eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $entries eq "ARRAY" 0 12 12
unless ref $entries eq "ARRAY" 0 0 0
266 0 for my $entry (@{$entries}) {
267 0 ▶ next unless ref $entry eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $entry eq "HASH" 0 12 12
unless ref $entry eq "HASH" 0 0 0
268 0 my $root = $entry->{installPath};
269 0 ▶ next unless $self->_nonempty_string($root);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_nonempty_string($root) 0 12 12
unless $self->_nonempty_string($root) 0 0 0
270 0 my $project = $entry->{projectPath};
271 0 ▶ if ($self->_nonempty_string($project)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_nonempty_string($project)) { } 0 12 12
if ($self->_nonempty_string($project)) { } 0 0 0
272 0 ▶ next unless $self->filesystem->within( $self->cwd, $project );
Branch: 2 branches
BranchTrueFalseTotal
unless $self->filesystem->within($self->cwd, $project) 0 0 0
unless $self->filesystem->within($self->cwd, $project) 0 0 0
273 0 push @found, [ -length($project), $key, $root ];
274 }
275 else {
276 0 push @found, [ 0, $key, $root ];
277 }
278 }
279 }
280  
281 0 my @plugins;
282 0 for my $item (sort {
283 0 ▶ $a->[0] <=> $b->[0]
Condition0%0/12
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] || $App::Briefing::a->[1] cmp $App::Briefing::b->[1] || $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
l!l&&r!l&&!r
000
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] or $App::Briefing::a->[1] cmp $App::Briefing::b->[1]
l!l&&r!l&&!r
000
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] || $App::Briefing::a->[1] cmp $App::Briefing::b->[1] || $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
l!l&&r!l&&!r
000
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] or $App::Briefing::a->[1] cmp $App::Briefing::b->[1]
l!l&&r!l&&!r
000
MC/DC0%0/3
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] || $App::Briefing::a->[1] cmp $App::Briefing::b->[1] || $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] $App::Briefing::a->[1] cmp $App::Briefing::b->[1] $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
MC/DC0%0/3
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] || $App::Briefing::a->[1] cmp $App::Briefing::b->[1] || $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
$App::Briefing::a->[0] <=> $App::Briefing::b->[0] $App::Briefing::a->[1] cmp $App::Briefing::b->[1] $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
Truth table0%0/4
A or B || C
A= $App::Briefing::a->[0] <=> $App::Briefing::b->[0]B= $App::Briefing::a->[1] cmp $App::Briefing::b->[1]C= $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B || C
A= $App::Briefing::a->[0] <=> $App::Briefing::b->[0]B= $App::Briefing::a->[1] cmp $App::Briefing::b->[1]C= $App::Briefing::a->[2] cmp $App::Briefing::b->[2]
ABCresult
1XX1
01X1
0011
0000
284 || $a->[1] cmp $b->[1]
285 || $a->[2] cmp $b->[2]
286 } @found) {
287 0 my ( undef, $key, $root ) = @{$item};
288 0 my $manifest = $self->_load_json(
289 $self->filesystem->join_path(
290 $root,
291 '.claude-plugin',
292 'plugin.json',
293 ),
294 );
295 my $name = $self->_nonempty_string( $manifest->{name} )
296 ? $manifest->{name}
297 0 ▶ : (split /\@/, $key, 2)[0];
Branch: 2 branches
BranchTrueFalseTotal
$self->_nonempty_string($manifest->{'name'}) ? : 0 12 12
$self->_nonempty_string($manifest->{'name'}) ? : 0 0 0
298 0 push @plugins, [ $name, $root, $manifest ];
299 }
300 0 return \@plugins;
301 }
302  
303 8 ▶sub _plugin_skill_dirs {
Subroutine _plugin_skill_dirs: called CC=9 SCAR=35.5
304 0 ▶ my ( $self, $root, $manifest ) = @_;
Subroutine _plugin_skill_dirs: not called CC=9 SCAR=35.5
305 0 my $extra = $manifest->{skills};
306 my @extra = $self->_is_string($extra)
307 ? ($extra)
308 : ref $extra eq 'ARRAY'
309 0 ▶ ? grep { $self->_is_string($_) } @{$extra}
Branch: 4 branches
BranchTrueFalseTotal
$self->_is_string($extra) ? : 0 8 8
ref $extra eq 'ARRAY' ? : 0 8 8
$self->_is_string($extra) ? : 0 0 0
ref $extra eq 'ARRAY' ? : 0 0 0
310 : ();
311 my @bases = (
312 $self->filesystem->join_path( $root, 'skills' ),
313 0 map { $self->filesystem->join_path( $root, $_ ) } @extra,
314 );
315  
316 0 my @directories;
317 0 for my $base (@bases) {
318 0 ▶ next unless $self->filesystem->within( $base, $root );
Branch: 2 branches
BranchTrueFalseTotal
unless $self->filesystem->within($base, $root) 0 8 8
unless $self->filesystem->within($base, $root) 0 0 0
319 0 ▶ if ($self->filesystem->is_file(
Branch: 2 branches
BranchTrueFalseTotal
if ($self->filesystem->is_file($self->filesystem->join_path($base, "SKILL.md"))) 0 8 8
if ($self->filesystem->is_file($self->filesystem->join_path($base, "SKILL.md"))) 0 0 0
320 $self->filesystem->join_path( $base, 'SKILL.md' ),
321 )) {
322 0 push @directories, $base;
323 0 next;
324 }
325 0 ▶ next unless $self->filesystem->is_dir($base);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->filesystem->is_dir($base) 0 8 8
unless $self->filesystem->is_dir($base) 0 0 0
326 0 for my $directory (@{ $self->filesystem->child_directories($base) }) {
327 0 ▶ push @directories, $directory
Branch: 2 branches
BranchTrueFalseTotal
if $self->filesystem->is_file($self->filesystem->join_path($directory, "SKILL.md")) 8 0 8
if $self->filesystem->is_file($self->filesystem->join_path($directory, "SKILL.md")) 0 0 0
328 if $self->filesystem->is_file(
329 $self->filesystem->join_path( $directory, 'SKILL.md' ),
330 );
331 }
332 }
333 0 return \@directories;
334 }
335  
336 41 ▶sub _resolve_plugin_skill {
Subroutine _resolve_plugin_skill: called CC=7 SCAR=26.4
337 0 ▶ my ( $self, $skill, $wanted_plugin ) = @_;
Subroutine _resolve_plugin_skill: not called CC=7 SCAR=26.4
338 0 for my $plugin (@{ $self->_claude_plugins }) {
339 0 my ( $name, $root, $manifest ) = @{$plugin};
340 0 ▶ next if defined $wanted_plugin && $name ne $wanted_plugin;
Branch: 2 branches
BranchTrueFalseTotal
if defined $wanted_plugin and $name ne $wanted_plugin 2 8 10
if defined $wanted_plugin and $name ne $wanted_plugin 0 0 0
Condition50%3/6
defined $wanted_plugin and $name ne $wanted_plugin
!ll&&!rl&&r
352
defined $wanted_plugin and $name ne $wanted_plugin
!ll&&!rl&&r
000
MC/DC100%2/2
defined $wanted_plugin and $name ne $wanted_plugin
defined $wanted_plugin $name ne $wanted_plugin
MC/DC0%0/2
defined $wanted_plugin and $name ne $wanted_plugin
defined $wanted_plugin $name ne $wanted_plugin
Truth table100%3/3
A and B
A= defined $wanted_pluginB= $name ne $wanted_plugin
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $wanted_pluginB= $name ne $wanted_plugin
ABresult
0X0
100
111
341 0 for my $directory (@{ $self->_plugin_skill_dirs( $root, $manifest ) }) {
342 0 ▶ next unless $self->filesystem->basename($directory) eq $skill;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->filesystem->basename($directory) eq $skill 2 6 8
unless $self->filesystem->basename($directory) eq $skill 0 0 0
343 0 my $file = $self->filesystem->join_path( $directory, 'SKILL.md' );
344 0 ▶ return $file if $self->filesystem->is_readable_file($file);
Branch: 2 branches
BranchTrueFalseTotal
if $self->filesystem->is_readable_file($file) 6 0 6
if $self->filesystem->is_readable_file($file) 0 0 0
345 }
346 }
347 0 return;
348 }
349  
350 304 ▶sub _resolve_skill_claude {
Subroutine _resolve_skill_claude: called CC=8 SCAR=31.8
351 0 ▶ my ( $self, $name ) = @_;
Subroutine _resolve_skill_claude: not called CC=8 SCAR=31.8
352 0 ▶ if ($name =~ /:/ && $name !~ /\A:/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /:/ and not $name =~ /\A:/) 11 293 304
if ($name =~ /:/ and not $name =~ /\A:/) 0 0 0
Condition33%2/6
$name =~ /:/ and not $name =~ /\A:/
!ll&&!rl&&r
293011
$name =~ /:/ and not $name =~ /\A:/
!ll&&!rl&&r
000
MC/DC50%1/2
$name =~ /:/ and not $name =~ /\A:/
$name =~ /:/ not $name =~ /\A:/
MC/DC0%0/2
$name =~ /:/ and not $name =~ /\A:/
$name =~ /:/ not $name =~ /\A:/
Truth table66%2/3
A and not(B)
A= $name =~ /:/B= not $name =~ /\A:/
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $name =~ /:/B= not $name =~ /\A:/
ABresult
0X0
100
111
353 0 my ( $plugin, $skill ) = split /:/, $name, 2;
354 0 ▶ return $self->_resolve_plugin_skill( $skill, $plugin )
Branch: 2 branches
BranchTrueFalseTotal
if length $plugin and length $skill and not $plugin =~ / / 11 0 11
if length $plugin and length $skill and not $plugin =~ / / 0 0 0
Condition16%2/12
length $plugin and length $skill and not $plugin =~ / /
!ll&&!rl&&r
0011
length $plugin and length $skill
!ll&&!rl&&r
0011
length $plugin and length $skill and not $plugin =~ / /
!ll&&!rl&&r
000
length $plugin and length $skill
!ll&&!rl&&r
000
MC/DC0%0/3
length $plugin and length $skill and not $plugin =~ / /
length $plugin length $skill not $plugin =~ / /
MC/DC0%0/3
length $plugin and length $skill and not $plugin =~ / /
length $plugin length $skill not $plugin =~ / /
Truth table25%1/4
A and B and not(C)
A= length $pluginB= length $skillC= not $plugin =~ / /
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and not(C)
A= length $pluginB= length $skillC= not $plugin =~ / /
ABCresult
0XX0
10X0
1100
1111
355 if length($plugin) && length($skill) && $plugin !~ / /;
356 }
357  
358 0 for my $base (
359 $self->filesystem->join_path( $self->cwd, '.claude', 'skills' ),
360 $self->filesystem->join_path( $self->home, '.claude', 'skills' ),
361 ) {
362 0 my $file = $self->filesystem->join_path( $base, $name, 'SKILL.md' );
363 0 ▶ return $file if $self->filesystem->is_readable_file($file);
Branch: 2 branches
BranchTrueFalseTotal
if $self->filesystem->is_readable_file($file) 263 63 326
if $self->filesystem->is_readable_file($file) 0 0 0
364 }
365 0 return $self->_resolve_plugin_skill($name);
366 }
367  
368 3 ▶sub _toml_string_state {
Subroutine _toml_string_state: called CC=15 SCAR=46.4
369 0 ▶ my ( $self, $line, $state ) = @_;
Subroutine _toml_string_state: not called CC=15 SCAR=46.4
370 0 my $index = 0;
371 0 my $length = length $line;
372 0 ▶ while ($index < $length) {
Branch: 2 branches
BranchTrueFalseTotal
if ($index < $length) 30 3 33
if ($index < $length) 0 0 0
373 0 ▶ if (!defined $state) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $state) 30 0 30
unless (defined $state) 0 0 0
374 0 my $character = substr( $line, $index, 1 );
375 0 ▶ last if $character eq '#';
Branch: 2 branches
BranchTrueFalseTotal
if $character eq "#" 0 30 30
if $character eq "#" 0 0 0
376 0 my $triple = substr( $line, $index, 3 );
377 0 ▶ if ($triple eq q{"""} || $triple eq q{'''}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($triple eq "\"\"\"" or $triple eq "'''") 0 30 30
if ($triple eq "\"\"\"" or $triple eq "'''") 0 0 0
Condition16%1/6
$triple eq "\"\"\"" or $triple eq "'''"
l!l&&r!l&&!r
0030
$triple eq "\"\"\"" or $triple eq "'''"
l!l&&r!l&&!r
000
MC/DC0%0/2
$triple eq "\"\"\"" or $triple eq "'''"
$triple eq "\"\"\"" $triple eq "'''"
MC/DC0%0/2
$triple eq "\"\"\"" or $triple eq "'''"
$triple eq "\"\"\"" $triple eq "'''"
Truth table33%1/3
A or B
A= $triple eq "\"\"\""B= $triple eq "'''"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $triple eq "\"\"\""B= $triple eq "'''"
ABresult
1X1
011
000
378 0 $state = $triple;
379 0 $index += 3;
380 0 next;
381 }
382 0 ▶ if ($character eq q{"} || $character eq q{'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($character eq "\"" or $character eq "'") 2 28 30
if ($character eq "\"" or $character eq "'") 0 0 0
Condition33%2/6
$character eq "\"" or $character eq "'"
l!l&&r!l&&!r
2028
$character eq "\"" or $character eq "'"
l!l&&r!l&&!r
000
MC/DC50%1/2
$character eq "\"" or $character eq "'"
$character eq "\"" $character eq "'"
MC/DC0%0/2
$character eq "\"" or $character eq "'"
$character eq "\"" $character eq "'"
Truth table66%2/3
A or B
A= $character eq "\""B= $character eq "'"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $character eq "\""B= $character eq "'"
ABresult
1X1
011
000
383 0 $index++;
384 0 ▶ while ($index < $length && substr( $line, $index, 1 ) ne $character) {
Branch: 2 branches
BranchTrueFalseTotal
if ($index < $length and substr($line, $index, 1) ne $character) 16 2 18
if ($index < $length and substr($line, $index, 1) ne $character) 0 0 0
Condition33%2/6
$index < $length and substr($line, $index, 1) ne $character
!ll&&!rl&&r
0216
$index < $length and substr($line, $index, 1) ne $character
!ll&&!rl&&r
000
MC/DC50%1/2
$index < $length and substr($line, $index, 1) ne $character
$index < $length substr($line, $index, 1) ne $character
MC/DC0%0/2
$index < $length and substr($line, $index, 1) ne $character
$index < $length substr($line, $index, 1) ne $character
Truth table66%2/3
A and B
A= $index < $lengthB= substr($line, $index, 1) ne $character
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $index < $lengthB= substr($line, $index, 1) ne $character
ABresult
0X0
100
111
385 0 ▶ $index += $character eq q{"}
Branch: 2 branches
BranchTrueFalseTotal
$character eq '"' && substr($line, $index, 1) eq '\\' ? : 0 16 16
$character eq '"' && substr($line, $index, 1) eq '\\' ? : 0 0 0
Condition16%1/6
$character eq "\"" and substr($line, $index, 1) eq "\\"
!ll&&!rl&&r
0160
$character eq "\"" and substr($line, $index, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$character eq "\"" and substr($line, $index, 1) eq "\\"
$character eq "\"" substr($line, $index, 1) eq "\\"
MC/DC0%0/2
$character eq "\"" and substr($line, $index, 1) eq "\\"
$character eq "\"" substr($line, $index, 1) eq "\\"
Truth table33%1/3
A and B
A= $character eq "\""B= substr($line, $index, 1) eq "\\"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $character eq "\""B= substr($line, $index, 1) eq "\\"
ABresult
0X0
100
111
386 && substr( $line, $index, 1 ) eq '\\'
387 ? 2
388 : 1;
389 }
390 }
391 0 $index++;
392 0 next;
393 }
394  
395 0 ▶ if ($state eq q{"""} && substr( $line, $index, 1 ) eq '\\') {
Branch: 2 branches
BranchTrueFalseTotal
if ($state eq "\"\"\"" and substr($line, $index, 1) eq "\\") 0 0 0
if ($state eq "\"\"\"" and substr($line, $index, 1) eq "\\") 0 0 0
Condition0%0/6
$state eq "\"\"\"" and substr($line, $index, 1) eq "\\"
!ll&&!rl&&r
000
$state eq "\"\"\"" and substr($line, $index, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$state eq "\"\"\"" and substr($line, $index, 1) eq "\\"
$state eq "\"\"\"" substr($line, $index, 1) eq "\\"
MC/DC0%0/2
$state eq "\"\"\"" and substr($line, $index, 1) eq "\\"
$state eq "\"\"\"" substr($line, $index, 1) eq "\\"
Truth table0%0/3
A and B
A= $state eq "\"\"\""B= substr($line, $index, 1) eq "\\"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $state eq "\"\"\""B= substr($line, $index, 1) eq "\\"
ABresult
0X0
100
111
396 0 $index += 2;
397 0 next;
398 }
399 0 ▶ if (substr( $line, $index, 3 ) eq $state) {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($line, $index, 3) eq $state) 0 0 0
if (substr($line, $index, 3) eq $state) 0 0 0
400 0 $state = undef;
401 0 $index += 3;
402 0 next;
403 }
404 0 $index++;
405 }
406 0 return $state;
407 }
408  
409 1 ▶sub _parse_skills_comment {
Subroutine _parse_skills_comment: called CC=7 SCAR=34.8
410 0 ▶ my ( $self, $text ) = @_;
Subroutine _parse_skills_comment: not called CC=7 SCAR=34.8
411 0 my $state;
412 0 ▶ for my $line (split /\r?\n/, defined $text ? $text : '') {
Branch: 2 branches
BranchTrueFalseTotal
defined $text ? : 1 0 1
defined $text ? : 0 0 0
413 0 ▶ if (!defined $state && $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $state and $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/) 0 3 3
if (not defined $state and $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/) 0 0 0
Condition16%1/6
not defined $state and $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
!ll&&!rl&&r
030
not defined $state and $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $state and $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
not defined $state $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
MC/DC0%0/2
not defined $state and $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
not defined $state $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
Truth table33%1/3
not(A) and B
A= not defined $stateB= $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not defined $stateB= $line =~ /\A[ \t]*#[ \t]*briefing:[ \t]*skills[ \t]*=[ \t]*\[([^\]\r\n]*)\]/
ABresult
0X0
100
111
414 0 my $items = $1;
415 0 my @skills;
416 0 ▶ while ($items =~ /["']([^"']+)["']/g) {
Branch: 2 branches
BranchTrueFalseTotal
if ($items =~ /["']([^"']+)["']/g) 0 0 0
if ($items =~ /["']([^"']+)["']/g) 0 0 0
417 0 my $skill = $self->_trim($1);
418 0 ▶ push @skills, $skill if length $skill;
Branch: 2 branches
BranchTrueFalseTotal
if length $skill 0 0 0
if length $skill 0 0 0
419 }
420 0 return \@skills;
421 }
422 0 $state = $self->_toml_string_state( $line, $state );
423 }
424 0 return [];
425 }
426  
427 1 ▶sub _toml_parser {
Subroutine _toml_parser: called CC=2 SCAR=10.0
428 0 ▶ my ( $self ) = @_;
Subroutine _toml_parser: not called CC=2 SCAR=10.0
429 0 my $parser_class = $self->toml_parser_class;
430 # Loaded on first use, not with this module: compiling TOML::Tiny::Parser is a large share
431 # of every start-up, and only Codex TOML files need it. This stays outside the parse eval,
432 # so a missing parser dies loudly instead of making every Codex agent declare nothing.
433 # A parser class that is already defined (an inline override) is used as it is.
434 0 ▶ unless ($parser_class->can('new')) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($parser_class->can("new")) 1 0 1
unless ($parser_class->can("new")) 0 0 0
435 0 ( my $file = $parser_class.'.pm' ) =~ s{::}{/}g;
436 0 require $file;
437 }
438 0 return $parser_class;
439 }
440  
441 17 ▶sub _parse_toml {
Subroutine _parse_toml: called CC=4 SCAR=20.9
442 0 ▶ my ( $self, $text ) = @_;
Subroutine _parse_toml: not called CC=4 SCAR=20.9
443 0 ▶ return {} unless defined $text && length $text;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $text and length $text 16 1 17
unless defined $text and length $text 0 0 0
Condition33%2/6
defined $text and length $text
!ll&&!rl&&r
0161
defined $text and length $text
!ll&&!rl&&r
000
MC/DC50%1/2
defined $text and length $text
defined $text length $text
MC/DC0%0/2
defined $text and length $text
defined $text length $text
Truth table66%2/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
444 0 my $parser_class = $self->_toml_parser;
445 0 my $document = eval {
446 $parser_class->new(
447 strict => 1,
448 0 ▶ inflate_boolean => sub { return [ boolean => $_[0] ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
449 0 ▶ inflate_datetime => sub { return [ datetime => $_[0] ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
450 0 ▶ inflate_float => sub { return [ float => $_[0] ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
451 0 ▶ inflate_integer => sub { return [ integer => $_[0] ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
452 0 )->parse( encode_utf8($text) );
453 };
454 0 ▶ return ref $document eq 'HASH' ? $document : {};
Branch: 2 branches
BranchTrueFalseTotal
ref $document eq 'HASH' ? : 1 0 1
ref $document eq 'HASH' ? : 0 0 0
455 }
456  
457 1 ▶sub _parse_skills_toml {
Subroutine _parse_skills_toml: called CC=4 SCAR=14.4
458 1 my ( $self, $text ) = @_;
459 1 my $document = $self->_parse_toml($text);
460 1 my $briefing = $document->{briefing};
461 1 ▶ return [] unless ref $briefing eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $briefing eq "HASH" 0 1 1
462 1 my $skills = $briefing->{skills};
463 1 ▶ return [] unless ref $skills eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $skills eq "ARRAY" 0 1 1
464 return [
465 1 map { $self->_trim($_) }
466 1 ▶ grep { $self->_is_string($_) && length $self->_trim($_) }
Condition33%1/3
$self->_is_string($_) && length $self->_trim($_)
!ll&&!rl&&r
001
MC/DC0%0/2
$self->_is_string($_) && length $self->_trim($_)
$self->_is_string($_) length $self->_trim($_)
Truth table33%1/3
A && B
A= $self->_is_string($_)B= length $self->_trim($_)
ABresult
0X0
100
111
467 1 @{$skills}
468 ];
469 }
470  
471 1 ▶sub _parse_toml_name {
Subroutine _parse_toml_name: called CC=7 SCAR=22.5
472 1 my ( $self, $text ) = @_;
473 1 my $state;
474 1 ▶ for my $line (split /\r?\n/, defined $text ? $text : '') {
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 1 0 1
475 1 ▶ if (!defined $state) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $state) 1 0 1
476 1 ▶ return if $line =~ /\A[ \t]*\[/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A[ \t]*\[/ 0 1 1
477 1 ▶ if ($line =~ /\A[ \t]*name[ \t]*=[ \t]*(?:"([^"\\]*)"|'([^']*)')/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A[ \t]*name[ \t]*=[ \t]*(?:"([^"\\]*)"|'([^']*)')/) 1 0 1
478 1 ▶ return defined $1 ? $1 : $2;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 1 0 1
479 }
480 }
481 0 $state = $self->_toml_string_state( $line, $state );
482 }
483 0 return;
484 }
485  
486 7 ▶sub _project_dirs {
Subroutine _project_dirs: called CC=3 SCAR=11.0
487 7 my ( $self ) = @_;
488 7 my $cwd = $self->filesystem->absolute( $self->cwd );
489 7 my @directories;
490 7 my $directory = $cwd;
491 7 while (1) {
492 28 push @directories, $directory;
493 return \@directories
494 28 ▶ if $self->filesystem->exists(
Branch: 1 branch
BranchTrueFalseTotal
if $self->filesystem->exists($self->filesystem->join_path($directory, ".git")) 0 28 28
495 $self->filesystem->join_path( $directory, '.git' ),
496 );
497 28 my $parent = $self->filesystem->parent($directory);
498 28 ▶ return [$cwd] if $parent eq $directory;
Branch: 1 branch
BranchTrueFalseTotal
if $parent eq $directory 7 21 28
499 21 $directory = $parent;
500 }
501 }
502  
503 6 ▶sub _codex_layers {
Subroutine _codex_layers: called CC=1 SCAR=0.0
504 6 my ( $self ) = @_;
505 return [
506 6 (map { $self->filesystem->join_path( $_, '.codex' ) }
507 6 @{ $self->_project_dirs }),
508 $self->codex_home,
509 $self->filesystem->join_path( '/', 'etc', 'codex' ),
510 ];
511 }
512  
513 0 ▶sub _expand_home {
Subroutine _expand_home: not called CC=3 SCAR=24.8
514 0 my ( $self, $file ) = @_;
515 0 ▶ return $self->home if $file eq '~';
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "~" 0 0 0
516 0 ▶ return $self->filesystem->join_path( $self->home, substr( $file, 2 ) )
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[\A~[\\/]] 0 0 0
517 if $file =~ /\A~[\\\/]/;
518 0 return $file;
519 }
520  
521 16 ▶sub _declared_roles {
Subroutine _declared_roles: called CC=6 SCAR=31.2
522 16 my ( $self, $layer ) = @_;
523 16 my $document = $self->_parse_toml(
524 $self->filesystem->slurp_utf8(
525 $self->filesystem->join_path( $layer, 'config.toml' ),
526 ),
527 );
528 16 my $agents = $document->{agents};
529 16 ▶ return {} unless ref $agents eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $agents eq "HASH" 16 0 16
530  
531 0 my %roles;
532 0 for my $name (keys %{$agents}) {
533 0 my $role = $agents->{$name};
534 0 ▶ next unless ref $role eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $role eq "HASH" 0 0 0
535 0 my $file = $role->{config_file};
536 0 ▶ next unless $self->_nonempty_string($file);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nonempty_string($file) 0 0 0
537 0 $file = $self->_expand_home($file);
538 0 ▶ $roles{$name} = $self->filesystem->is_absolute($file)
Branch: 1 branch
BranchTrueFalseTotal
$self->filesystem->is_absolute($file) ? : 0 0 0
539 ? $file
540 : $self->filesystem->join_path( $layer, $file );
541 }
542 0 return \%roles;
543 }
544  
545 2 ▶sub _find_codex_agent {
Subroutine _find_codex_agent: called CC=12 SCAR=34.5
546 2 my ( $self, $agent ) = @_;
547 2 for my $layer (@{ $self->_codex_layers }) {
548 4 my $declared = $self->_declared_roles($layer)->{$agent};
549 4 ▶ if ($declared && $self->_find_first_readable($declared)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($declared and $self->_find_first_readable($declared)) 0 4 4
Condition33%1/3
$declared and $self->_find_first_readable($declared)
!ll&&!rl&&r
400
MC/DC0%0/2
$declared and $self->_find_first_readable($declared)
$declared $self->_find_first_readable($declared)
Truth table33%1/3
A and B
A= $declaredB= $self->_find_first_readable($declared)
ABresult
0X0
100
111
550 0 return ( $declared, $self->filesystem->slurp_utf8($declared) );
551 }
552  
553 4 my $root = $self->filesystem->join_path( $layer, 'agents' );
554 4 ▶ next unless $self->filesystem->is_dir($root);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->filesystem->is_dir($root) 3 1 4
555 1 my $direct = $self->filesystem->join_path( $root, $agent.'.toml' );
556 1 ▶ if ($self->_find_first_readable($direct)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_find_first_readable($direct)) 1 0 1
557 1 my $text = $self->filesystem->slurp_utf8($direct);
558 1 my $name = $self->_parse_toml_name($text);
559 1 ▶ return ( $direct, $text ) if !defined $name || $name eq $agent;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or $name eq $agent 1 0 1
Condition33%1/3
not defined $name or $name eq $agent
l!l&&r!l&&!r
010
MC/DC0%0/2
not defined $name or $name eq $agent
not defined $name $name eq $agent
Truth table33%1/3
not(A) or B
A= not defined $nameB= $name eq $agent
ABresult
1X1
011
000
560 }
561 0 for my $file (@{ $self->filesystem->walk_files( $root, '.toml' ) }) {
562 0 ▶ next if $file eq $direct;
Branch: 1 branch
BranchTrueFalseTotal
if $file eq $direct 0 0 0
563 0 my $text = $self->filesystem->slurp_utf8($file);
564 0 my $name = $self->_parse_toml_name($text);
565 0 ▶ return ( $file, $text ) if defined $name && $name eq $agent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and $name eq $agent 0 0 0
Condition0%0/3
defined $name and $name eq $agent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and $name eq $agent
defined $name $name eq $agent
Truth table0%0/3
A and B
A= defined $nameB= $name eq $agent
ABresult
0X0
100
111
566 }
567 }
568 1 return;
569 }
570  
571 4 ▶sub _list_codex_agents {
Subroutine _list_codex_agents: called CC=10 SCAR=32.9
572 4 my ( $self ) = @_;
573 4 my %agents;
574 4 for my $layer (@{ $self->_codex_layers }) {
575 12 my %layer_agents;
576 12 my $declared = $self->_declared_roles($layer);
577 12 for my $name (keys %{$declared}) {
578 $layer_agents{$name} = $declared->{$name}
579 0 ▶ if $self->_find_first_readable( $declared->{$name} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_find_first_readable($declared->{$name}) 0 0 0
580 }
581  
582 12 my $root = $self->filesystem->join_path( $layer, 'agents' );
583 12 ▶ if ($self->filesystem->is_dir($root)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filesystem->is_dir($root)) 0 12 12
584 0 for my $file (@{ $self->filesystem->walk_files( $root, '.toml' ) }) {
585 0 my $name = $self->_parse_toml_name(
586 $self->filesystem->slurp_utf8($file),
587 );
588 $layer_agents{$name} = $file
589 0 ▶ if defined $name && !exists $layer_agents{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $name and not exists $layer_agents{$name} 0 0 0
Condition0%0/3
defined $name and not exists $layer_agents{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and not exists $layer_agents{$name}
defined $name not exists $layer_agents{$name}
Truth table0%0/3
A and not(B)
A= defined $nameB= not exists $layer_agents{$name}
ABresult
0X0
100
111
590 }
591 }
592  
593 12 for my $name (keys %layer_agents) {
594 0 ▶ $agents{$name} = $layer_agents{$name} unless exists $agents{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $agents{$name} 0 0 0
595 }
596 }
597 4 return \%agents;
598 }
599  
600 0 ▶sub _resolve_codex_plugin_skill {
Subroutine _resolve_codex_plugin_skill: not called CC=8 SCAR=42.8
601 0 my ( $self, $plugin, $skill ) = @_;
602 0 my $cache = $self->filesystem->join_path(
603 $self->codex_home,
604 'plugins',
605 'cache',
606 );
607  
608 0 for my $marketplace (@{ $self->filesystem->child_directories($cache) }) {
609 0 my $plugin_root = $self->filesystem->join_path( $marketplace, $plugin );
610 0 for my $version (@{ $self->filesystem->child_directories($plugin_root) }) {
611 0 my $file = $self->filesystem->join_path(
612 $version,
613 'skills',
614 $skill,
615 'SKILL.md',
616 );
617 0 ▶ return $file if $self->filesystem->is_readable_file($file);
Branch: 1 branch
BranchTrueFalseTotal
if $self->filesystem->is_readable_file($file) 0 0 0
618 }
619 }
620  
621 0 my $direct_root = $self->filesystem->join_path( $cache, $plugin );
622 0 for my $version (@{ $self->filesystem->child_directories($direct_root) }) {
623 0 my $file = $self->filesystem->join_path(
624 $version,
625 'skills',
626 $skill,
627 'SKILL.md',
628 );
629 0 ▶ return $file if $self->filesystem->is_readable_file($file);
Branch: 1 branch
BranchTrueFalseTotal
if $self->filesystem->is_readable_file($file) 0 0 0
630 }
631  
632 0 for my $marketplace (@{ $self->filesystem->child_directories($cache) }) {
633 0 my $file = $self->filesystem->join_path(
634 $marketplace,
635 $plugin,
636 'skills',
637 $skill,
638 'SKILL.md',
639 );
640 0 ▶ return $file if $self->filesystem->is_readable_file($file);
Branch: 1 branch
BranchTrueFalseTotal
if $self->filesystem->is_readable_file($file) 0 0 0
641 }
642 0 return;
643 }
644  
645 1 ▶sub _resolve_skill_codex {
Subroutine _resolve_skill_codex: called CC=9 SCAR=29.5
646 1 my ( $self, $name ) = @_;
647 1 ▶ if ($name =~ /:/ && $name !~ /\A:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /:/ and not $name =~ /\A:/) 0 1 1
Condition33%1/3
$name =~ /:/ and not $name =~ /\A:/
!ll&&!rl&&r
100
MC/DC0%0/2
$name =~ /:/ and not $name =~ /\A:/
$name =~ /:/ not $name =~ /\A:/
Truth table33%1/3
A and not(B)
A= $name =~ /:/B= not $name =~ /\A:/
ABresult
0X0
100
111
648 0 my ( $plugin, $skill ) = split /:/, $name, 2;
649 0 ▶ return $self->_resolve_codex_plugin_skill( $plugin, $skill )
Branch: 1 branch
BranchTrueFalseTotal
if length $plugin and length $skill and not $plugin =~ / / 0 0 0
Condition0%0/6
length $plugin and length $skill and not $plugin =~ / /
!ll&&!rl&&r
000
length $plugin and length $skill
!ll&&!rl&&r
000
MC/DC0%0/3
length $plugin and length $skill and not $plugin =~ / /
length $plugin length $skill not $plugin =~ / /
Truth table0%0/4
A and B and not(C)
A= length $pluginB= length $skillC= not $plugin =~ / /
ABCresult
0XX0
10X0
1100
1111
650 if length($plugin) && length($skill) && $plugin !~ / /;
651 }
652  
653 1 my @bases;
654 1 for my $directory (@{ $self->_project_dirs }) {
655 1 push @bases,
656 $self->filesystem->join_path( $directory, '.codex', 'skills' ),
657 $self->filesystem->join_path( $directory, '.agents', 'skills' );
658 }
659 1 push @bases,
660 $self->filesystem->join_path( $self->codex_home, 'skills' ),
661 $self->filesystem->join_path( $self->home, '.agents', 'skills' ),
662 $self->filesystem->join_path( $self->codex_home, 'skills', '.system' ),
663 $self->filesystem->join_path( '/', 'etc', 'codex', 'skills' );
664  
665 1 for my $base (@bases) {
666 2 my $file = $self->filesystem->join_path( $base, $name, 'SKILL.md' );
667 2 ▶ return $file if $self->filesystem->is_readable_file($file);
Branch: 1 branch
BranchTrueFalseTotal
if $self->filesystem->is_readable_file($file) 1 1 2
668 }
669 0 return;
670 }
671  
672 76 ▶sub resolve_skill {
Subroutine resolve_skill: called CC=6 SCAR=20.7
Pod documented
673 76 my ( $self, $name, %options ) = @_;
674 76 ▶ my $harness = defined $options{harness} ? $options{harness} : 'claude';
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'harness'} ? : 76 0 76
675 76 ▶ croak __PACKAGE__.'->resolve_skill requires harness claude or codex'
Branch: 1 branch
BranchTrueFalseTotal
unless $harness eq "claude" or $harness eq "codex" 0 76 76
Condition33%1/3
$harness eq "claude" or $harness eq "codex"
l!l&&r!l&&!r
7600
MC/DC0%0/2
$harness eq "claude" or $harness eq "codex"
$harness eq "claude" $harness eq "codex"
Truth table33%1/3
A or B
A= $harness eq "claude"B= $harness eq "codex"
ABresult
1X1
011
000
676 unless $harness eq 'claude' || $harness eq 'codex';
677 76 ▶ return unless $self->_nonempty_string($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nonempty_string($name) 0 76 76
678 76 ▶ return $harness eq 'claude'
Branch: 1 branch
BranchTrueFalseTotal
$harness eq 'claude' ? : 76 0 76
679 ? $self->_resolve_skill_claude($name)
680 : $self->_resolve_skill_codex($name);
681 }
682  
683  
684 14 ▶sub _usable_skill_name {
Subroutine _usable_skill_name: called CC=2 SCAR=6.9
685 14 my ( $self, $name ) = @_;
686 14 ▶ return $name =~ m{\A[^*?\[\]/\\]+\z} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ m(\A[^*?\[\]/\\]+\z) ? : 13 1 14
687 }
688  
689 76 ▶sub skill_problem {
Subroutine skill_problem: called CC=8 SCAR=21.1
Pod documented
690 76 my ( $self, $name ) = @_;
691 76 ▶ return unless $self->_nonempty_string($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nonempty_string($name) 0 76 76
692 76 ▶ return if $self->resolve_skill( $name, harness => 'claude' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->resolve_skill($name, "harness", "claude") 66 10 76
693  
694 10 ▶ if ($name =~ /:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /:/) 4 6 10
695 4 my ( $plugin, $skill ) = split /:/, $name, 2;
696 4 ▶ return 'not a usable skill name'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_usable_skill_name($plugin) and $self->_usable_skill_name($skill) 0 4 4
Condition33%1/3
$self->_usable_skill_name($plugin) and $self->_usable_skill_name($skill)
!ll&&!rl&&r
004
MC/DC0%0/2
$self->_usable_skill_name($plugin) and $self->_usable_skill_name($skill)
$self->_usable_skill_name($plugin) $self->_usable_skill_name($skill)
Truth table33%1/3
A and B
A= $self->_usable_skill_name($plugin)B= $self->_usable_skill_name($skill)
ABresult
0X0
100
111
697 unless $self->_usable_skill_name($plugin)
698 && $self->_usable_skill_name($skill);
699 return "plugin '".$plugin."' has no skill '".$skill."'"
700 4 ▶ if grep { $_->[0] eq $plugin } @{ $self->_claude_plugins };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->[0] eq $plugin;} @{$self->_claude_plugins;} 1 3 4
701 3 return "plugin '".$plugin."' is not installed and enabled";
702 }
703 6 ▶ return 'not a usable skill name' unless $self->_usable_skill_name($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_usable_skill_name($name) 1 5 6
704 5 return 'no such skill in .claude/skills, ~/.claude/skills or an installed and enabled plugin';
705 }
706  
707  
708 142 ▶sub claude_agent_skills {
Subroutine claude_agent_skills: called CC=1 SCAR=0.0
Pod documented
709 142 my ( $self, $file ) = @_;
710 142 my ( $skills ) = $self->_claude_declaration($file);
711 142 return $skills;
712 }
713  
714  
715 369 ▶sub _claude_declaration {
Subroutine _claude_declaration: called CC=1 SCAR=0.0
716 369 my ( $self, $file ) = @_;
717 369 my ( $frontmatter ) = $self->_split_frontmatter(
718 $self->filesystem->slurp_utf8($file),
719 );
720 369 return ( $self->_parse_skills_list($frontmatter), 0 );
721 }
722  
723 1 ▶sub _codex_declaration {
Subroutine _codex_declaration: called CC=3 SCAR=11.2
724 1 my ( $self, $text ) = @_;
725 1 my $legacy = $self->_parse_skills_toml($text);
726 1 my $comment = $self->_parse_skills_comment($text);
727 1 ▶ return ( @{$comment} ? $comment : $legacy, @{$legacy} ? 1 : 0 );
Branch: 2 branches
BranchTrueFalseTotal
@{$comment;} ? : 0 1 1
@{$legacy;} ? : 1 0 1
728 }
729  
730 220 ▶sub _briefing_result {
Subroutine _briefing_result: called CC=6 SCAR=17.9
731 220 my ( $self, $agent, $path, $skills, $harness, $legacy ) = @_;
732 220 my @missing;
733 my @blocks;
734 220 for my $name (@{$skills}) {
735 229 ▶ my $skill_file = $harness eq 'claude'
Branch: 1 branch
BranchTrueFalseTotal
$harness eq 'claude' ? : 228 1 229
736 ? $self->_resolve_skill_claude($name)
737 : $self->_resolve_skill_codex($name);
738 229 ▶ if (!$skill_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($skill_file) 25 204 229
739 25 push @missing, $name;
740 25 next;
741 }
742 204 my ( undef, $body ) = $self->_split_frontmatter(
743 $self->filesystem->slurp_utf8($skill_file),
744 );
745 204 my $directory = $self->filesystem->absolute(
746 $self->filesystem->parent($skill_file),
747 );
748 204 push @blocks,
749 '<skill name="'.$name.'" dir="'.$directory.'">'."\n"
750 .$self->_trim($body)."\n</skill>";
751 }
752  
753 220 my $resolved_text = join "\n\n", @blocks;
754 return {
755 agent => $agent,
756 path => $path,
757 harness => $harness,
758 220 ▶ skills => [ @{$skills} ],
Branch: 2 branches
BranchTrueFalseTotal
@missing ? : 25 195 220
$legacy ? : 1 219 220
759 missing => \@missing,
760 text => @missing ? '' : $resolved_text,
761 size => length encode_utf8($resolved_text),
762 legacy => $legacy ? 1 : 0,
763 };
764 }
765  
766 231 ▶sub _brief_agent_claude {
Subroutine _brief_agent_claude: called CC=3 SCAR=11.0
767 231 my ( $self, $agent ) = @_;
768 231 my $file = $self->_find_claude_agent($agent);
769 231 ▶ return unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 4 227 231
770 227 my ( $skills, $legacy ) = $self->_claude_declaration($file);
771 227 ▶ return unless @{$skills};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$skills;} 8 219 227
772 219 return $self->_briefing_result(
773 $agent,
774 $file,
775 $skills,
776 'claude',
777 $legacy,
778 );
779 }
780  
781 2 ▶sub _brief_agent_codex {
Subroutine _brief_agent_codex: called CC=3 SCAR=11.0
782 2 my ( $self, $agent ) = @_;
783 2 my ( $file, $text ) = $self->_find_codex_agent($agent);
784 2 ▶ return unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 1 1 2
785 1 my ( $skills, $legacy ) = $self->_codex_declaration($text);
786 1 ▶ return unless @{$skills};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$skills;} 0 1 1
787 1 return $self->_briefing_result(
788 $agent,
789 $file,
790 $skills,
791 'codex',
792 $legacy,
793 );
794 }
795  
796 224 ▶sub brief_agent {
Subroutine brief_agent: called CC=5 SCAR=17.2
Pod documented
797 224 my ( $self, $agent, %options ) = @_;
798 224 my $harness = $options{harness};
799 224 ▶ croak __PACKAGE__.'->brief_agent requires harness claude or codex'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $harness and $harness eq "claude" || $harness eq "codex" 0 224 224
Condition50%3/6
defined $harness and $harness eq "claude" || $harness eq "codex"
!ll&&!rl&&r
00224
$harness eq "claude" or $harness eq "codex"
l!l&&r!l&&!r
22220
MC/DC0%0/3
defined $harness and $harness eq "claude" || $harness eq "codex"
defined $harness $harness eq "claude" $harness eq "codex"
Truth table50%2/4
A and B or C
A= defined $harnessB= $harness eq "claude"C= $harness eq "codex"
ABCresult
0XX0
1000
11X1
1011
800 unless defined $harness && ($harness eq 'claude' || $harness eq 'codex');
801 224 ▶ return $harness eq 'claude'
Branch: 1 branch
BranchTrueFalseTotal
$harness eq 'claude' ? : 222 2 224
802 ? $self->_brief_agent_claude($agent)
803 : $self->_brief_agent_codex($agent);
804 }
805  
806  
807 10 ▶sub check_agents {
Subroutine check_agents: called CC=13 SCAR=26.6
Pod documented
808 10 my ( $self, %options ) = @_;
809 10 ▶ my $harness = defined $options{harness} ? $options{harness} : 'both';
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'harness'} ? : 10 0 10
810 10 ▶ croak __PACKAGE__.'->check_agents requires harness claude, codex, or both'
Branch: 1 branch
BranchTrueFalseTotal
unless $harness eq "claude" or $harness eq "codex" or $harness eq "both" 0 10 10
Condition83%5/6
$harness eq "claude" or $harness eq "codex" or $harness eq "both"
l!l&&r!l&&!r
910
$harness eq "claude" or $harness eq "codex"
l!l&&r!l&&!r
631
MC/DC0%0/3
$harness eq "claude" or $harness eq "codex" or $harness eq "both"
$harness eq "claude" $harness eq "codex" $harness eq "both"
Truth table75%3/4
A or B or C
A= $harness eq "claude"B= $harness eq "codex"C= $harness eq "both"
ABCresult
1XX1
01X1
0011
0000
811 unless $harness eq 'claude' || $harness eq 'codex' || $harness eq 'both';
812  
813 10 my @results;
814 10 ▶ if ($harness eq 'claude' || $harness eq 'both') {
Branch: 1 branch
BranchTrueFalseTotal
if ($harness eq "claude" or $harness eq "both") 7 3 10
Condition100%3/3
$harness eq "claude" or $harness eq "both"
l!l&&r!l&&!r
613
MC/DC100%2/2
$harness eq "claude" or $harness eq "both"
$harness eq "claude" $harness eq "both"
Truth table100%3/3
A or B
A= $harness eq "claude"B= $harness eq "both"
ABresult
1X1
011
000
815 7 my $agents = $self->_list_claude_agents;
816 7 for my $name (sort keys %{$agents}) {
817 9 my $result = $self->_brief_agent_claude($name);
818 9 ▶ push @results, $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 9 0 9
819 }
820 }
821 10 ▶ if ($harness eq 'codex' || $harness eq 'both') {
Branch: 1 branch
BranchTrueFalseTotal
if ($harness eq "codex" or $harness eq "both") 4 6 10
Condition100%3/3
$harness eq "codex" or $harness eq "both"
l!l&&r!l&&!r
316
MC/DC100%2/2
$harness eq "codex" or $harness eq "both"
$harness eq "codex" $harness eq "both"
Truth table100%3/3
A or B
A= $harness eq "codex"B= $harness eq "both"
ABresult
1X1
011
000
822 4 my $agents = $self->_list_codex_agents;
823 4 for my $name (sort keys %{$agents}) {
824 0 my $result = $self->_brief_agent_codex($name);
825 0 ▶ push @results, $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
826 }
827 }
828 10 return \@results;
829 }
830  
831  
832 226 ▶sub _for_payload {
Subroutine _for_payload: called CC=3 SCAR=11.0
833 226 my ( $self, $payload ) = @_;
834 226 my $cwd = $payload->{cwd};
835 226 ▶ return $self unless $self->_nonempty_string($cwd) && $cwd ne $self->cwd;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nonempty_string($cwd) and $cwd ne $self->cwd 205 21 226
Condition66%2/3
$self->_nonempty_string($cwd) and $cwd ne $self->cwd
!ll&&!rl&&r
020521
MC/DC50%1/2
$self->_nonempty_string($cwd) and $cwd ne $self->cwd
$self->_nonempty_string($cwd) $cwd ne $self->cwd
Truth table66%2/3
A and B
A= $self->_nonempty_string($cwd)B= $cwd ne $self->cwd
ABresult
0X0
100
111
836 21 return $self->new(
837 cwd => $cwd,
838 home => $self->home,
839 codex_home => $self->codex_home,
840 filesystem => $self->filesystem,
841 );
842 }
843  
844 76 ▶sub _harnesses_for_payload {
Subroutine _harnesses_for_payload: called CC=6 SCAR=18.7
845 76 my ( $self, $payload ) = @_;
846 76 my $transcript = $payload->{transcript_path};
847 76 ▶ $transcript = '' unless $self->_is_string($transcript);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_string($transcript) 68 8 76
848 76 $transcript =~ tr{\\}{/};
849 76 my $codex_home = $self->codex_home;
850 76 $codex_home =~ tr{\\}{/};
851 76 ▶ return ['codex']
Branch: 1 branch
BranchTrueFalseTotal
if index($transcript, "/.codex/") != -1 or length $codex_home and index($transcript, $codex_home . '/') == 0 0 76 76
Condition33%2/6
index($transcript, "/.codex/") != -1 or length $codex_home and index($transcript, $codex_home . '/') == 0
l!l&&r!l&&!r
0076
length $codex_home and index($transcript, $codex_home . '/') == 0
!ll&&!rl&&r
0760
MC/DC0%0/3
index($transcript, "/.codex/") != -1 or length $codex_home and index($transcript, $codex_home . '/') == 0
index($transcript, "/.codex/") != -1 length $codex_home index($transcript, $codex_home . '/') == 0
Truth table25%1/4
A or B and C
A= index($transcript, "/.codex/") != -1B= length $codex_homeC= index($transcript, $codex_home . '/') == 0
ABCresult
1XX1
0111
00X0
0100
852 if index( $transcript, '/.codex/' ) >= 0
853 || (length($codex_home) && index( $transcript, $codex_home.'/' ) == 0);
854 76 ▶ return ['claude'] if index( $transcript, '/.claude/' ) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($transcript, "/.claude/") != -1 8 68 76
855 68 return [qw( claude codex )];
856 }
857  
858 71 ▶sub _spawn_harness {
Subroutine _spawn_harness: called CC=4 SCAR=13.9
859 71 my ( $self, $payload, $agent ) = @_;
860 71 my $harnesses = $self->_harnesses_for_payload($payload);
861 71 ▶ return $harnesses->[0] if @{$harnesses} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$harnesses;} == 1 6 65 71
862 65 ▶ return 'codex' if exists $payload->{turn_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $payload->{"turn_id"} 0 65 65
863 65 ▶ return $self->_find_claude_agent($agent) ? 'claude' : 'codex';
Branch: 1 branch
BranchTrueFalseTotal
$self->_find_claude_agent($agent) ? : 64 1 65
864 }
865  
866 0 ▶sub _legacy_note {
Subroutine _legacy_note: not called CC=1 SCAR=6.9
867 0 my ( $self, $result ) = @_;
868 return 'briefing: '.$result->{path}
869 0 .' declares skills in a [briefing] table. Codex 0.153+ rejects that as an '
870 .'unknown field and ignores the whole agent. Replace the table with a '
871 .'comment line: # briefing: skills = [...]';
872 }
873  
874 18 ▶sub _missing_note {
Subroutine _missing_note: called CC=1 SCAR=0.0
875 18 my ( $self, $result ) = @_;
876 return "briefing: agent '".$result->{agent}."' references unknown skill(s): "
877 18 .join( ', ', @{ $result->{missing} } );
878 }
879  
880 0 ▶sub _size_note {
Subroutine _size_note: not called CC=1 SCAR=6.9
881 0 my ( $self, $result ) = @_;
882 return "briefing: agent '".$result->{agent}."' is briefed with "
883 0 .int( $result->{size} / 1024 ).' kB of skill text (over '
884 .int( BUDGET_BYTES / 1024 ).' kB) '."\x{2014}".' consider declaring fewer or smaller skills.';
885 }
886  
887 66 ▶sub _audit_line {
Subroutine _audit_line: called CC=6 SCAR=19.9
888 66 my ( $self, $result ) = @_;
889 66 my $kilobytes = 0;
890 66 ▶ if ($result->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"size"}) 66 0 66
891 66 my $whole = int( $result->{size} / 1024 );
892 66 my $remainder = $result->{size} % 1024;
893 66 ▶ $kilobytes = $whole
Branch: 1 branch
BranchTrueFalseTotal
$remainder > 512 || $remainder == 512 && $whole % 2 ? : 0 66 66
Condition33%2/6
$remainder > 512 or $remainder == 512 and $whole % 2
l!l&&r!l&&!r
0066
$remainder == 512 and $whole % 2
!ll&&!rl&&r
6600
MC/DC0%0/3
$remainder > 512 or $remainder == 512 and $whole % 2
$remainder > 512 $remainder == 512 $whole % 2
Truth table25%1/4
A or B and C
A= $remainder > 512B= $remainder == 512C= $whole % 2
ABCresult
1XX1
0111
00X0
0100
894 + ($remainder > 512 || ($remainder == 512 && $whole % 2) ? 1 : 0);
895 66 ▶ $kilobytes = 1 if $kilobytes < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $kilobytes < 1 66 0 66
896 }
897 return 'briefing: '.$result->{agent}.' '."\x{2190}".' '
898 66 .join( ', ', @{ $result->{skills} } ).' ('.$kilobytes.' kB)';
899 }
900  
901 7 ▶sub _problems {
Subroutine _problems: called CC=4 SCAR=14.0
902 7 my ( $self, $result ) = @_;
903 7 my ( @failures, @warnings );
904 3 push @failures, 'unknown skill(s): '.join( ', ', @{ $result->{missing} } )
905 7 ▶ if @{ $result->{missing} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$result->{"missing"};} 3 4 7
906 push @failures,
907 '[briefing] table '."\x{2014}".' Codex 0.153+ ignores this whole agent; use # briefing: skills = [...]'
908 7 ▶ if $result->{legacy};
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"legacy"} 0 7 7
909 push @warnings,
910 int( $result->{size} / 1024 ).' kB of skill text, over '
911 .int( BUDGET_BYTES / 1024 ).' kB'
912 7 ▶ if $result->{size} > BUDGET_BYTES;
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"size"} > 65536 0 7 7
913 7 return ( \@failures, \@warnings );
914 }
915  
916 66 ▶sub _spawn_header {
Subroutine _spawn_header: called CC=2 SCAR=7.1
917 66 my ( $self, $harness ) = @_;
918 66 ▶ my $dont = $harness eq 'claude'
Branch: 1 branch
BranchTrueFalseTotal
$harness eq 'claude' ? : 66 0 66
919 ? 'do NOT call the Skill tool for any of these names'
920 : 'do NOT go looking for their SKILL.md files';
921 66 return '# Briefing '."\x{2014}".' pre-loaded skills'."\n\n"
922 .'The skills below have been injected directly into your context by the'."\n"
923 .'briefing plugin, one <skill> element each. Treat them as already loaded '."\x{2014}\n"
924 .$dont.'; their content is already here. Only the SKILL.md body is'."\n"
925 .'included: paths a skill mentions (references/, scripts/, '."\x{2026}"
926 .') are relative to'."\n"
927 .'its element\'s dir, so read them from there when you need them.'."\n\n";
928 }
929  
930 1 ▶sub _abort_context {
Subroutine _abort_context: called CC=1 SCAR=0.0
931 1 my ( $self, $result ) = @_;
932 return '# Briefing '."\x{2014}".' FAILED'."\n\n"
933 .'The skills this agent declares could not be loaded: '
934 1 .join( ', ', @{ $result->{missing} } ).'.'."\n\n"
935 .'You are NOT briefed for this task. Do NOT attempt it and do NOT'."\n"
936 .'improvise a substitute. Report this exact failure to whoever'."\n"
937 .'delegated to you, and stop.'."\n";
938 }
939  
940 71 ▶sub _process_subagent_start {
Subroutine _process_subagent_start: called CC=7 SCAR=19.7
941 71 my ( $self, $payload ) = @_;
942 71 my $agent = $payload->{agent_type};
943 71 ▶ return ( undef, '' ) unless $self->_nonempty_string($agent);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nonempty_string($agent) 0 71 71
944  
945 71 my $harness = $self->_spawn_harness( $payload, $agent );
946 71 my $result = $self->brief_agent( $agent, harness => $harness );
947 71 ▶ return ( undef, '' ) unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 4 67 71
948  
949 67 ▶ my @notes = $result->{legacy} ? ($self->_legacy_note($result)) : ();
Branch: 1 branch
BranchTrueFalseTotal
$result->{'legacy'} ? : 0 67 67
950 67 ▶ if (@{ $result->{missing} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$result->{"missing"};}) 1 66 67
951 1 my $message = $self->_missing_note($result);
952 return (
953 {
954 1 systemMessage => join( "\n", $message, @notes ),
955 hookSpecificOutput => {
956 hookEventName => 'SubagentStart',
957 additionalContext => $self->_abort_context($result),
958 },
959 },
960 $message."\n",
961 );
962 }
963  
964 push @notes, $self->_size_note($result)
965 66 ▶ if $result->{size} > BUDGET_BYTES;
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"size"} > 65536 0 66 66
966 66 ▶ my $stderr = @notes ? join( "\n", @notes )."\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
@notes ? : 0 66 66
967 return (
968 {
969 systemMessage => join( "\n", $self->_audit_line($result), @notes ),
970 hookSpecificOutput => {
971 hookEventName => 'SubagentStart',
972 additionalContext => $self->_spawn_header($harness).$result->{text},
973 },
974 },
975 66 $stderr,
976 );
977 }
978  
979 147 ▶sub _process_guard {
Subroutine _process_guard: called CC=5 SCAR=16.2
980 147 my ( $self, $payload ) = @_;
981 147 my $tool_input = $payload->{tool_input};
982 147 ▶ return ( undef, '' ) unless ref $tool_input eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tool_input eq "HASH" 0 147 147
983 147 my $agent = $tool_input->{subagent_type};
984 147 ▶ return ( undef, '' ) unless $self->_nonempty_string($agent);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_nonempty_string($agent) 0 147 147
985  
986 147 my $result = $self->brief_agent( $agent, harness => 'claude' );
987 147 ▶ return ( undef, '' ) unless $result && @{ $result->{missing} };
Branch: 1 branch
BranchTrueFalseTotal
unless $result and @{$result->{"missing"};} 130 17 147
Condition100%3/3
$result and @{$result->{"missing"};}
!ll&&!rl&&r
912117
MC/DC100%2/2
$result and @{$result->{"missing"};}
$result @{$result->{"missing"};}
Truth table100%3/3
A and B
A= $resultB= @{$result->{"missing"};}
ABresult
0X0
100
111
988 17 my $message = $self->_missing_note($result);
989 return (
990 {
991 17 hookSpecificOutput => {
992 hookEventName => 'PreToolUse',
993 permissionDecision => 'deny',
994 permissionDecisionReason => $message,
995 },
996 },
997 $message."\n",
998 );
999 }
1000  
1001 3 ▶sub _harness_label {
Subroutine _harness_label: called CC=2 SCAR=7.2
1002 3 my ( $self, $harness ) = @_;
1003 3 ▶ return $harness eq 'claude' ? 'Claude Code' : 'Codex';
Branch: 1 branch
BranchTrueFalseTotal
$harness eq 'claude' ? : 3 0 3
1004 }
1005  
1006 5 ▶sub _process_session_start {
Subroutine _process_session_start: called CC=9 SCAR=22.7
1007 5 my ( $self, $payload ) = @_;
1008 5 my $source = $payload->{source};
1009 5 ▶ return ( undef, '' )
Branch: 1 branch
BranchTrueFalseTotal
if defined $source and ($source ne "startup" and $source ne "resume") 0 5 5
Condition50%3/6
defined $source and ($source ne "startup" and $source ne "resume")
!ll&&!rl&&r
140
$source ne "startup" and $source ne "resume"
!ll&&!rl&&r
400
MC/DC0%0/3
defined $source and ($source ne "startup" and $source ne "resume")
defined $source $source ne "startup" $source ne "resume"
Truth table50%2/4
A and B and C
A= defined $sourceB= $source ne "startup"C= $source ne "resume"
ABCresult
0XX0
10X0
1100
1111
1010 if defined $source && ($source ne 'startup' && $source ne 'resume');
1011  
1012 5 my @lines;
1013 5 for my $harness (@{ $self->_harnesses_for_payload($payload) }) {
1014 8 for my $result (@{ $self->check_agents( harness => $harness ) }) {
1015 7 my ( $failures ) = $self->_problems($result);
1016 push @lines, map {
1017 ' '.$self->_harness_label($harness)." agent '"
1018 3 .$result->{agent}."': ".$_
1019 7 } @{$failures};
1020 }
1021 }
1022 5 ▶ return ( undef, '' ) unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 2 3 5
1023  
1024 3 ▶ my @shown = @lines > 8 ? @lines[0 .. 7] : @lines;
Branch: 1 branch
BranchTrueFalseTotal
@lines > 8 ? : 0 3 3
1025 3 ▶ push @shown, ' '."\x{2026}".' and '.(@lines - @shown).' more'
Branch: 1 branch
BranchTrueFalseTotal
if @lines > @shown 0 3 3
1026 if @lines > @shown;
1027 return (
1028 {
1029 3 systemMessage => 'briefing: declared skills that will not work '."\x{2014}"
1030 .' run briefing-doctor for details'."\n".join( "\n", @shown ),
1031 },
1032 '',
1033 );
1034 }
1035  
1036 226 ▶sub process_hook {
Subroutine process_hook: called CC=10 SCAR=23.1
Pod documented
1037 226 my ( $self, $payload, %options ) = @_;
1038 226 my $empty = { output => undef, stderr => '', exit_code => 0 };
1039 226 ▶ return $empty unless ref $payload eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload eq "HASH" 0 226 226
1040  
1041 226 my $context = $self->_for_payload($payload);
1042 226 my ( $output, $stderr );
1043 my $event = defined $options{event}
1044 ? $options{event}
1045 226 ▶ : $payload->{hook_event_name};
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'event'} ? : 15 211 226
1046 226 ▶ if ($context->_is_string($event) && $event eq 'SubagentStart') {
Branch: 3 branches
BranchTrueFalseTotal
if ($context->_is_string($event) and $event eq 'SubagentStart') { } 71 155 226
elsif ($context->_is_string($event) and $event eq 'SessionStart') { } 5 150 155
elsif ($context->_is_string($payload->{'tool_name'}) and $payload->{'tool_name'} eq 'Agent') { } 147 3 150
Condition100%3/3
$context->_is_string($event) and $event eq "SubagentStart"
!ll&&!rl&&r
115471
MC/DC100%2/2
$context->_is_string($event) and $event eq "SubagentStart"
$context->_is_string($event) $event eq "SubagentStart"
Truth table100%3/3
A and B
A= $context->_is_string($event)B= $event eq "SubagentStart"
ABresult
0X0
100
111
1047 71 ( $output, $stderr ) = $context->_process_subagent_start($payload);
1048 }
1049 ▶ elsif ($context->_is_string($event) && $event eq 'SessionStart') {
Condition100%3/3
$context->_is_string($event) and $event eq "SessionStart"
!ll&&!rl&&r
11495
MC/DC100%2/2
$context->_is_string($event) and $event eq "SessionStart"
$context->_is_string($event) $event eq "SessionStart"
Truth table100%3/3
A and B
A= $context->_is_string($event)B= $event eq "SessionStart"
ABresult
0X0
100
111
1050 5 ( $output, $stderr ) = $context->_process_session_start($payload);
1051 }
1052 ▶ elsif (
Condition66%2/3
$context->_is_string($payload->{"tool_name"}) and $payload->{"tool_name"} eq "Agent"
!ll&&!rl&&r
30147
MC/DC50%1/2
$context->_is_string($payload->{"tool_name"}) and $payload->{"tool_name"} eq "Agent"
$context->_is_string($payload->{"tool_name"}) $payload->{"tool_name"} eq "Agent"
Truth table66%2/3
A and B
A= $context->_is_string($payload->{"tool_name"})B= $payload->{"tool_name"} eq "Agent"
ABresult
0X0
100
111
1053 $context->_is_string( $payload->{tool_name} )
1054 && $payload->{tool_name} eq 'Agent'
1055 ) {
1056 147 ( $output, $stderr ) = $context->_process_guard($payload);
1057 }
1058 else {
1059 3 return $empty;
1060 }
1061  
1062 return {
1063 223 ▶ output => $output,
Branch: 1 branch
BranchTrueFalseTotal
defined $stderr ? : 223 0 223
1064 stderr => defined $stderr ? $stderr : '',
1065 exit_code => 0,
1066 };
1067 }
1068  
1069  
1070 28 ▶sub _installed_marketplace {
Subroutine _installed_marketplace: called CC=13 SCAR=25.8
1071 28 my ( $self ) = @_;
1072 28 my $root = $self->filesystem->environment_value('CLAUDE_PLUGIN_ROOT');
1073 28 ▶ return unless defined $root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root 2 26 28
1074 # The components os.path.normpath gives hooks/briefing-marketplace-notice: "\" separates
1075 # only on Windows, "." is dropped and ".." folded lexically, so both stay silent alike.
1076 26 ▶ $root =~ tr{\\}{/} if $self->filesystem->is_windows;
Branch: 1 branch
BranchTrueFalseTotal
if $self->filesystem->is_windows 0 26 26
1077 26 ▶ my $absolute = $root =~ m{\A/} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$root =~ m[\A/] ? : 24 2 26
1078 26 my @parts;
1079 26 for my $part (split m{/+}, $root) {
1080 228 ▶ next if $part eq '' || $part eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $part eq "" or $part eq "." 24 204 228
Condition66%2/3
$part eq "" or $part eq "."
l!l&&r!l&&!r
240204
MC/DC50%1/2
$part eq "" or $part eq "."
$part eq "" $part eq "."
Truth table66%2/3
A or B
A= $part eq ""B= $part eq "."
ABresult
1X1
011
000
1081 204 ▶ if ($part eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($part eq "..") 8 196 204
1082 8 ▶ if (@parts && $parts[-1] ne '..') {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts and $parts[-1] ne "..") 6 2 8
Condition66%2/3
@parts and $parts[-1] ne ".."
!ll&&!rl&&r
206
MC/DC50%1/2
@parts and $parts[-1] ne ".."
@parts $parts[-1] ne ".."
Truth table66%2/3
A and B
A= @partsB= $parts[-1] ne ".."
ABresult
0X0
100
111
1083 6 pop @parts;
1084 6 next;
1085 }
1086 2 ▶ next if $absolute;
Branch: 1 branch
BranchTrueFalseTotal
if $absolute 2 0 2
1087 }
1088 196 push @parts, $part;
1089 }
1090 26 for my $index (0 .. $#parts - 1) {
1091 128 ▶ return $parts[$index + 1] if $parts[$index] eq 'cache';
Branch: 1 branch
BranchTrueFalseTotal
if $parts[$index] eq "cache" 18 110 128
1092 }
1093 8 return;
1094 }
1095  
1096 28 ▶sub process_notice {
Subroutine process_notice: called CC=4 SCAR=13.9
Pod documented
1097 28 my ( $self, $payload ) = @_;
1098 28 my $result = { output => undef, stderr => '', exit_code => 0 };
1099 28 my $marketplace = $self->_installed_marketplace;
1100 28 ▶ return $result unless defined $marketplace && $marketplace ne 'getty';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $marketplace and $marketplace ne "getty" 14 14 28
Condition100%3/3
defined $marketplace and $marketplace ne "getty"
!ll&&!rl&&r
10414
MC/DC100%2/2
defined $marketplace and $marketplace ne "getty"
defined $marketplace $marketplace ne "getty"
Truth table100%3/3
A and B
A= defined $marketplaceB= $marketplace ne "getty"
ABresult
0X0
100
111
1101  
1102 14 my $state = $self->filesystem->join_path(
1103 $self->home,
1104 '.claude',
1105 '.briefing-marketplace-notice',
1106 );
1107 14 ▶ return $result if $self->filesystem->exists($state);
Branch: 1 branch
BranchTrueFalseTotal
if $self->filesystem->exists($state) 3 11 14
1108  
1109 11 my $parent = $self->filesystem->parent($state);
1110 11 $self->filesystem->make_path($parent);
1111 11 $self->filesystem->spew_utf8( $state, $marketplace."\n" );
1112  
1113 $result->{output} = {
1114 11 systemMessage => 'briefing is now also in the shared Getty marketplace, '
1115 .'alongside the other plugins: /plugin marketplace add Getty/marketplace '
1116 ."\x{2014}".' then /plugin install briefing@getty. Your install from Getty/briefing '
1117 .'keeps working and stays maintained, so there is nothing you have to do.',
1118 };
1119 11 return $result;
1120 }
1121  
1122  
1123  
1124 134 1;
1125  
1126 __END__
« lib/App/Briefing/Filesystem.pm ↑ Summary script/briefing »