blib/lib/Langertha/Raider/Config.pm

filter: Statementstmt 99.2% 410 / 413 Branchbran 93.2% 233 / 250 Conditioncond 85.4% 106 / 124 MC/DCmcdc 74.2% 49 / 66 Subroutinesub 100% 67 / 67 Podpod 93.1% 27 / 29 totaltotal 93.9% 892 / 949 CC 188 SCAR 20.4
CC
188
Cov
95%
normalize_detect
20.1
_resolve_file
17.0
_load
15.0
CRAP 7.7
« blib/lib/Langertha/Raider/Hall/Protocol.pm ↑ Summary blib/lib/Langertha/Raider/Plugin/Trace.pm »
1 package Langertha::Raider::Config;
2 # ABSTRACT: Internal resolver and writer for the project config file
3 79 our $VERSION = '0.503';
4 79 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 79 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 79 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 79 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 79 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 79 ▶use YAML::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 79 ▶use Langertha::Raider::Detect;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 79 ▶use Langertha::Raider::Home;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 # Keys that configure raider itself and never reach the engine constructor.
15 79 my %APP_KEY = map { $_ => 1 } qw( detect engine no_detect packs perl preferred_lib_target project_tools skills );
16  
17 79 my %PROFILE_KEYWORD = (
18 claude => 'claude',
19 openai => 'openai',
20 codex => 'openai',
21 agents => 'openai',
22 );
23  
24  
25 79 has root => (
26 is => 'ro',
27 isa => 'Str',
28 required => 1,
29 );
30  
31  
32 79 has file => (
33 is => 'ro',
34 isa => 'Path::Tiny',
35 lazy_build => 1,
36 );
37  
38 541 ▶sub _build_file {
Subroutine _build_file: called CC=2 SCAR=6.9
39 541 my ( $self ) = @_;
40 541 ▶ return -f $self->native_file ? $self->native_file : $self->legacy_file;
Branch: 1 branch
BranchTrueFalseTotal
-f $self->native_file ? : 61 480 541
41 }
42  
43 2092 ▶sub home_class { 'Langertha::Raider::Home' }
Subroutine home_class: called CC=1 SCAR=0.0
Pod undocumented
44  
45  
46 79 has home_file => (
47 is => 'ro',
48 isa => 'Maybe[Path::Tiny]',
49 lazy_build => 1,
50 );
51  
52 496 ▶sub _build_home_file {
Subroutine _build_home_file: called CC=2 SCAR=6.9
53 496 my ( $self ) = @_;
54 496 my $base = $self->home_class->home_base;
55 496 ▶ return defined $base ? $base->child('config.yml') : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 494 2 496
56 }
57  
58  
59 79 has uses_home => (
60 is => 'ro',
61 isa => 'Bool',
62 lazy_build => 1,
63 );
64  
65 489 ▶sub _build_uses_home {
Subroutine _build_uses_home: called CC=4 SCAR=13.9
66 489 my ( $self ) = @_;
67 489 my $home = $self->home_file;
68 489 ▶ return 0 unless defined $home && -f $home;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $home and -f $home 417 72 489
Condition100%3/3
defined $home and -f $home
!ll&&!rl&&r
141672
MC/DC100%2/2
defined $home and -f $home
defined $home -f $home
Truth table100%3/3
A and B
A= defined $homeB= -f $home
ABresult
0X0
100
111
69 72 ▶ return $self->_is_home_file ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_home_file ? : 6 66 72
70 }
71  
72 # True when the file in use is the home file itself (raider runs in the
73 # home directory), compared by real path.
74 293 ▶sub _is_home_file {
Subroutine _is_home_file: called CC=5 SCAR=16.1
75 293 my ( $self ) = @_;
76 293 my $home = $self->home_file;
77 293 ▶ return 0 unless defined $home && -f $home && -f $self->file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $home and -f $home and -f $self->file 236 57 293
Condition83%5/6
defined $home and -f $home and -f $self->file
!ll&&!rl&&r
2033357
defined $home and -f $home
!ll&&!rl&&r
020390
MC/DC66%2/3
defined $home and -f $home and -f $self->file
defined $home -f $home -f $self->file
Truth table75%3/4
A and B and C
A= defined $homeB= -f $homeC= -f $self->file
ABCresult
0XX0
10X0
1100
1111
78 57 ▶ return $home->realpath eq $self->file->realpath ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$home->realpath eq $self->file->realpath ? : 12 45 57
79 }
80  
81  
82 408 ▶sub home_label { 'home' }
Subroutine home_label: called CC=1 SCAR=0.0
Pod documented
83  
84  
85 1450 ▶sub native_file { $_[0]->home_class->project_base($_[0]->root)->child('config.yml') }
Subroutine native_file: called CC=1 SCAR=0.0
Pod documented
86  
87 583 ▶sub legacy_file { path($_[0]->root)->child('.raider.yml') }
Subroutine legacy_file: called CC=1 SCAR=0.0
Pod documented
88  
89 833 ▶sub is_native { $_[0]->file eq $_[0]->native_file ? 1 : 0 }
Subroutine is_native: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->file eq $_[0]->native_file ? : 169 664 833
90  
91 579 ▶sub label { $_[0]->is_native ? $_[0]->home_class->dir_name.'/config.yml' : '.raider.yml' }
Subroutine label: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_native ? : 122 457 579
92  
93  
94 251 ▶sub ignored_files {
Subroutine ignored_files: called CC=3 SCAR=11.0
Pod documented
95 251 my ( $self ) = @_;
96 251 ▶ return unless $self->is_native && -f $self->legacy_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_native and -f $self->legacy_file 245 6 251
Condition100%3/3
$self->is_native and -f $self->legacy_file
!ll&&!rl&&r
206396
MC/DC100%2/2
$self->is_native and -f $self->legacy_file
$self->is_native -f $self->legacy_file
Truth table100%3/3
A and B
A= $self->is_nativeB= -f $self->legacy_file
ABresult
0X0
100
111
97 return {
98 6 file => $self->legacy_file->absolute->stringify,
99 reason => 'both .raider.yml and '.$self->label.' exist; only '.$self->label.' is loaded',
100 };
101 }
102  
103  
104 79 has data => (
105 is => 'ro',
106 isa => 'HashRef',
107 lazy_build => 1,
108 );
109  
110  
111 79 has home_data => (
112 is => 'ro',
113 isa => 'HashRef',
114 lazy_build => 1,
115 );
116  
117 197 ▶sub _build_home_data {
Subroutine _build_home_data: called CC=2 SCAR=6.9
118 197 my ( $self ) = @_;
119 197 ▶ return $self->uses_home ? $self->_load($self->home_file) : {};
Branch: 1 branch
BranchTrueFalseTotal
$self->uses_home ? : 65 132 197
120 }
121  
122 # A YAML::PP error as one line. Its detailed report ("Line : 2",
123 # "Column : 3", "Expected : ..." or "Message : ...") is summed up as
124 # "line 2, column 3: expected EOL, got COLON"; a short error keeps its
125 # first line. Either way without YAML::PP's source location.
126 16 ▶sub _parse_error {
Subroutine _parse_error: called CC=6 SCAR=18.3
127 16 my ( $self, $error ) = @_;
128 16 my %f = $error =~ /^(Line|Column|Message|Expected|Got)\s*: (.*)$/mg;
129 16 ▶ if (defined $f{Line}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $f{"Line"}) 3 13 16
130 my $reason = defined $f{Message} ? $f{Message}
131 3 ▶ : defined $f{Expected} ? 'expected '.$f{Expected}.', got '.( $f{Got} // '?' )
Branch: 2 branches
BranchTrueFalseTotal
defined $f{'Message'} ? : 2 1 3
defined $f{'Expected'} ? : 1 0 1
Condition50%1/2
$f{"Got"} // "?"
l!l
10
MC/DC0%0/1
$f{"Got"} // "?"
$f{"Got"}
Truth table50%1/2
A
A= $f{"Got"}
Aresult
11
00
132 : 'syntax error';
133 3 ▶ return 'line '.$f{Line}.( defined $f{Column} ? ', column '.$f{Column} : '' ).': '.$reason;
Branch: 1 branch
BranchTrueFalseTotal
defined $f{'Column'} ? : 3 0 3
134 }
135 13 return ( split /\n/, $error )[0] =~ s/ at (?:(?! at ).)+ line \d+\.\z//r;
136 }
137  
138 535 ▶sub _build_data {
Subroutine _build_data: called CC=1 SCAR=0.0
139 535 my ( $self ) = @_;
140 535 return $self->_load($self->file);
141 }
142  
143 626 ▶sub _load {
Subroutine _load: called CC=15 SCAR=27.1
144 626 my ( $self, $file ) = @_;
145 626 ▶ return {} unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 326 300 626
146 300 my $data;
147 300 ▶ eval { $data = YAML::PP->new->load_string($file->slurp_utf8); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $data = "YAML::PP"->new->load_string($file->slurp_utf8); 1 } } or croak('Cannot parse ' . $file . ': ' . $self->_parse_error($@)) 284 16 300
148 or croak 'Cannot parse '.$file.': '.$self->_parse_error($@);
149 284 ▶ return {} unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 2 282 284
150 282 ▶ croak 'Cannot use '.$file.': the top level must be a mapping' unless ref $data eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 5 277 282
151 277 for my $key (sort keys %$data) {
152 573 ▶ next unless $APP_KEY{$key} && !$self->_may_be_mapping($key) && ref $data->{$key} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $APP_KEY{$key} and not $self->_may_be_mapping($key) and ref $$data{$key} eq "HASH" 566 7 573
Condition100%6/6
$APP_KEY{$key} and not $self->_may_be_mapping($key) and ref $$data{$key} eq "HASH"
!ll&&!rl&&r
4631037
$APP_KEY{$key} and not $self->_may_be_mapping($key)
!ll&&!rl&&r
351112110
MC/DC100%3/3
$APP_KEY{$key} and not $self->_may_be_mapping($key) and ref $$data{$key} eq "HASH"
$APP_KEY{$key} not $self->_may_be_mapping($key) ref $$data{$key} eq "HASH"
Truth table100%4/4
A and not(B) and C
A= $APP_KEY{$key}B= not $self->_may_be_mapping($key)C= ref $$data{$key} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
153 7 croak 'Cannot use '.$file.': '.$key.': configures raider, not an engine section; must not be a mapping';
154 }
155 # Every section, the inactive ones too: the file is valid or not whichever
156 # engine runs.
157 270 ▶ for my $section (sort grep { ref $data->{$_} eq 'HASH' && !$APP_KEY{$_} } keys %$data) {
Condition100%3/3
ref $$data{$_} eq 'HASH' && !$APP_KEY{$_}
!ll&&!rl&&r
33445187
MC/DC100%2/2
ref $$data{$_} eq 'HASH' && !$APP_KEY{$_}
ref $$data{$_} eq 'HASH' !$APP_KEY{$_}
Truth table100%3/3
A && not(B)
A= ref $$data{$_} eq 'HASH'B= !$APP_KEY{$_}
ABresult
0X0
100
111
158 187 for my $key (sort keys %{ $data->{$section} }) {
159 234 ▶ next unless $APP_KEY{$key} && !$self->_may_be_mapping($key) && ref $data->{$section}{$key} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless $APP_KEY{$key} and not $self->_may_be_mapping($key) and ref $$data{$section}{$key} eq "HASH" 218 16 234
Condition100%6/6
$APP_KEY{$key} and not $self->_may_be_mapping($key) and ref $$data{$section}{$key} eq "HASH"
!ll&&!rl&&r
213516
$APP_KEY{$key} and not $self->_may_be_mapping($key)
!ll&&!rl&&r
1981521
MC/DC100%3/3
$APP_KEY{$key} and not $self->_may_be_mapping($key) and ref $$data{$section}{$key} eq "HASH"
$APP_KEY{$key} not $self->_may_be_mapping($key) ref $$data{$section}{$key} eq "HASH"
Truth table100%4/4
A and not(B) and C
A= $APP_KEY{$key}B= not $self->_may_be_mapping($key)C= ref $$data{$section}{$key} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
160 16 croak 'Cannot use '.$file.': '.$section.'.'.$key.': configures raider; must not be a mapping';
161 }
162 }
163 254 return $data;
164 }
165  
166  
167 140 ▶sub file_exists { -f $_[0]->file ? 1 : 0 }
Subroutine file_exists: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
-f $_[0]->file ? : 64 76 140
168  
169 # The raider keys whose value may be a mapping; any other top-level mapping
170 # is an engine section.
171 8651 ▶sub _may_be_mapping {
Subroutine _may_be_mapping: called CC=3 SCAR=11.0
172 8651 my ( $self, $key ) = @_;
173 8651 ▶ return $key eq 'skills' || $key eq 'detect' || $key eq 'project_tools';
Condition100%6/6
$key eq 'skills' || $key eq 'detect' || $key eq 'project_tools'
l!l&&r!l&&!r
5871937871
$key eq "skills" or $key eq "detect"
l!l&&r!l&&!r
3682198064
MC/DC100%3/3
$key eq 'skills' || $key eq 'detect' || $key eq 'project_tools'
$key eq "skills" $key eq "detect" $key eq 'project_tools'
Truth table100%4/4
A or B || C
A= $key eq "skills"B= $key eq "detect"C= $key eq 'project_tools'
ABCresult
1XX1
01X1
0011
0000
174 }
175  
176 8393 ▶sub _is_section {
Subroutine _is_section: called CC=2 SCAR=6.9
177 8393 my ( $self, $data, $key ) = @_;
178 8393 ▶ return !$self->_may_be_mapping($key) && ref $data->{$key} eq 'HASH';
Condition100%3/3
!$self->_may_be_mapping($key) && ref $$data{$key} eq 'HASH'
!ll&&!rl&&r
65363451395
MC/DC100%2/2
!$self->_may_be_mapping($key) && ref $$data{$key} eq 'HASH'
!$self->_may_be_mapping($key) ref $$data{$key} eq 'HASH'
Truth table100%3/3
not(A) && B
A= !$self->_may_be_mapping($key)B= ref $$data{$key} eq 'HASH'
ABresult
0X0
100
111
179 }
180  
181 # The layers of one file, named top, default and the engine; with a
182 # $prefix (the home file: 'home ') in front of each name.
183 2477 ▶sub _layers {
Subroutine _layers: called CC=5 SCAR=16.1
184 2477 my ( $self, $engine, $data, $prefix ) = @_;
185 2477 my @layers = ( [ $prefix.'top' => { map { $_ => $data->{$_} } grep { !$self->_is_section($data, $_) } keys %$data } ] );
186 2477 ▶ push @layers, [ $prefix.'default' => $data->{default} ] if $self->_is_section($data, 'default');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_section($data, "default") 189 2288 2477
187 2477 ▶ push @layers, [ $prefix.$engine => $data->{$engine} ]
Branch: 1 branch
BranchTrueFalseTotal
if defined $engine and $engine ne "default" and $self->_is_section($data, $engine) 140 2337 2477
Condition83%5/6
defined $engine and $engine ne "default" and $self->_is_section($data, $engine)
!ll&&!rl&&r
152322140
defined $engine and $engine ne "default"
!ll&&!rl&&r
1502462
MC/DC66%2/3
defined $engine and $engine ne "default" and $self->_is_section($data, $engine)
defined $engine $engine ne "default" $self->_is_section($data, $engine)
Truth table75%3/4
A and B and C
A= defined $engineB= $engine ne "default"C= $self->_is_section($data, $engine)
ABCresult
0XX0
10X0
1100
1111
188 if defined $engine && $engine ne 'default' && $self->_is_section($data, $engine);
189 2477 return @layers;
190 }
191  
192 # Effective value and source per key, the shadowed sources, the skills of
193 # every layer, and what was ignored: the project file over the home file,
194 # merged per key as DESCRIPTION says. merged_with names the home layer a
195 # merged key took values from; project is the project file on its own.
196 2234 ▶sub _resolve {
Subroutine _resolve: called CC=8 SCAR=20.8
197 2234 my ( $self, $engine ) = @_;
198 2234 my $project = $self->_resolve_file($engine, $self->data, '');
199 2232 ▶ return $project unless $self->uses_home;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->uses_home 1984 248 2232
200 248 my $home = $self->_resolve_file($engine, $self->home_data, $self->home_label.' ');
201  
202 245 my %value = %{ $home->{value} };
203 245 my %source = %{ $home->{source} };
204 245 my %shadowed = map { $_ => [ @{ $home->{shadowed}{$_} } ] } keys %{ $home->{shadowed} };
205 245 my %merged_with;
206 245 for my $key (sort keys %{ $project->{value} }) {
207 122 my $value = $project->{value}{$key};
208 122 ▶ my @before = @{ $project->{shadowed}{$key} // [] };
Condition50%1/2
$$project{"shadowed"}{$key} // []
l!l
0122
MC/DC0%0/1
$$project{"shadowed"}{$key} // []
$$project{"shadowed"}{$key}
Truth table50%1/2
A
A= $$project{"shadowed"}{$key}
Aresult
11
00
209 122 ▶ if (exists $value{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $value{$key}) 120 2 122
210 120 ▶ if (my $merged = $self->_merge_home($key, $value{$key}, $value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $merged = $self->_merge_home($key, $value{$key}, $value)) { } 44 76 120
211 44 $value = $merged->[0];
212 44 $merged_with{$key} = [ $source{$key} ];
213 }
214 else {
215 76 unshift @before, $source{$key};
216 }
217 120 ▶ unshift @before, @{ $shadowed{$key} // [] };
Condition50%1/2
$shadowed{$key} // []
l!l
0120
MC/DC0%0/1
$shadowed{$key} // []
$shadowed{$key}
Truth table50%1/2
A
A= $shadowed{$key}
Aresult
11
00
218 }
219 122 $value{$key} = $value;
220 122 $source{$key} = $project->{source}{$key};
221 122 ▶ if (@before) { $shadowed{$key} = \@before } else { delete $shadowed{$key} }
Branch: 1 branch
BranchTrueFalseTotal
if (@before) { } 76 46 122
222 }
223 return {
224 value => \%value,
225 source => \%source,
226 shadowed => \%shadowed,
227 merged_with => \%merged_with,
228 245 skills => [ @{ $home->{skills} }, @{ $project->{skills} } ],
229 245 ignored => [ @{ $home->{ignored} }, @{ $project->{ignored} } ],
230 project => $project,
231 };
232 }
233  
234 # A key set in both files: [ merged value ] for the keys that merge
235 # (no_detect: union; detect: per pack when both are maps), else nothing,
236 # and the project value replaces the home one.
237 120 ▶sub _merge_home {
Subroutine _merge_home: called CC=6 SCAR=17.9
238 120 my ( $self, $key, $home, $project ) = @_;
239 120 ▶ if ($key eq 'no_detect') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "no_detect") 29 91 120
240 29 my %seen;
241 29 ▶ return [ [ grep { ref || !$seen{$_}++ } map { $self->_name_list($_) } $home, $project ] ];
Condition100%3/3
ref $_ || !$seen{$_}++
l!l&&r!l&&!r
18528
MC/DC100%2/2
ref $_ || !$seen{$_}++
ref $_ !$seen{$_}++
Truth table100%3/3
A || not(B)
A= ref $_B= !$seen{$_}++
ABresult
1X1
011
000
242 }
243 91 ▶ return [ { %$home, %$project } ] if $key eq 'detect' && ref $home eq 'HASH' && ref $project eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "detect" and ref $home eq "HASH" and ref $project eq "HASH" 15 76 91
Condition100%6/6
$key eq "detect" and ref $home eq "HASH" and ref $project eq "HASH"
!ll&&!rl&&r
651115
$key eq "detect" and ref $home eq "HASH"
!ll&&!rl&&r
64126
MC/DC100%3/3
$key eq "detect" and ref $home eq "HASH" and ref $project eq "HASH"
$key eq "detect" ref $home eq "HASH" ref $project eq "HASH"
Truth table100%4/4
A and B and C
A= $key eq "detect"B= ref $home eq "HASH"C= ref $project eq "HASH"
ABCresult
0XX0
10X0
1100
1111
244 76 return;
245 }
246  
247 # A no_detect value as a list: its items, or a string split on commas. A
248 # value of any other shape stays one item, for normalize_detect to reject.
249 58 ▶sub _name_list {
Subroutine _name_list: called CC=4 SCAR=14.1
250 58 my ( $self, $value ) = @_;
251 58 ▶ return () unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 58 58
252 58 ▶ return @$value if ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 30 28 58
253 28 ▶ return $value if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 28 28
254 28 return split /\s*,\s*/, $value;
255 }
256  
257 # One pass over the layers of one file: effective value and source per
258 # key, the shadowed sources, the skills of every layer, and what was
259 # ignored.
260 2477 ▶sub _resolve_file {
Subroutine _resolve_file: called CC=17 SCAR=28.3
261 2477 my ( $self, $engine, $data, $prefix ) = @_;
262 2477 my ( %value, %source, %shadowed, @skills, @ignored );
263 2477 for my $layer ($self->_layers($engine, $data, $prefix)) {
264 2806 my ( $name, $hash ) = @$layer;
265 2806 for my $key (sort keys %$hash) {
266 1594 ▶ if ($key eq 'skills') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "skills") 152 1442 1594
267 152 push @skills, { source => $name, value => $hash->{$key} };
268 152 next;
269 }
270 1442 ▶ if ($key eq 'project_tools') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "project_tools") 100 1342 1442
271 # Read on its own (project_tools), never layered; anywhere else
272 # than the top level of the home file it is reported, not used.
273 100 my $top = $name eq $prefix.'top';
274 100 ▶ push @ignored, $self->_ignored_project_tools($name, $top)
Branch: 1 branch
BranchTrueFalseTotal
unless $top and length $prefix || $self->_is_home_file 32 68 100
Condition100%6/6
$top and length $prefix || $self->_is_home_file
!ll&&!rl&&r
201268
length $prefix or $self->_is_home_file
l!l&&r!l&&!r
67112
MC/DC100%3/3
$top and length $prefix || $self->_is_home_file
$top length $prefix $self->_is_home_file
Truth table100%4/4
A and B or C
A= $topB= length $prefixC= $self->_is_home_file
ABCresult
0XX0
1000
11X1
1011
275 unless $top && ( length $prefix || $self->_is_home_file );
276 100 next;
277 }
278 1342 ▶ if ($key eq 'engine' && $name ne $prefix.'top' && $name ne $prefix.'default') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "engine" and $name ne $prefix . 'top' and $name ne $prefix . 'default') 1 1341 1342
Condition100%6/6
$key eq "engine" and $name ne $prefix . 'top' and $name ne $prefix . 'default'
!ll&&!rl&&r
134011
$key eq "engine" and $name ne $prefix . 'top'
!ll&&!rl&&r
1296442
MC/DC100%3/3
$key eq "engine" and $name ne $prefix . 'top' and $name ne $prefix . 'default'
$key eq "engine" $name ne $prefix . 'top' $name ne $prefix . 'default'
Truth table100%4/4
A and B and C
A= $key eq "engine"B= $name ne $prefix . 'top'C= $name ne $prefix . 'default'
ABCresult
0XX0
10X0
1100
1111
279 1 push @ignored, { key => $name.'.engine', reason => 'engine: inside an engine section' };
280 1 next;
281 }
282 1341 ▶ push @{ $shadowed{$key} }, $source{$key} if exists $source{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $source{$key} 114 1227 1341
283 1341 $value{$key} = $hash->{$key};
284 1341 $source{$key} = $name;
285 }
286 }
287 2477 for my $key (sort keys %$data) {
288 1688 ▶ next unless $self->_is_section($data, $key);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_section($data, $key) 1175 513 1688
289 513 ▶ next if $key eq 'default' || (defined $engine && $key eq $engine);
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "default" or defined $engine and $key eq $engine 329 184 513
Condition100%6/6
$key eq "default" or defined $engine and $key eq $engine
l!l&&r!l&&!r
189140184
defined $engine and $key eq $engine
!ll&&!rl&&r
3181140
MC/DC100%3/3
$key eq "default" or defined $engine and $key eq $engine
$key eq "default" defined $engine $key eq $engine
Truth table100%4/4
A or B and C
A= $key eq "default"B= defined $engineC= $key eq $engine
ABCresult
1XX1
0111
00X0
0100
290 184 push @ignored, { key => $prefix.$key, reason => 'section of an inactive engine' };
291 }
292 return {
293 2477 value => \%value,
294 source => \%source,
295 shadowed => \%shadowed,
296 skills => \@skills,
297 ignored => \@ignored,
298 };
299 }
300  
301  
302 103 ▶sub layer_label {
Subroutine layer_label: called CC=3 SCAR=11.0
Pod documented
303 103 my ( $self, $layer ) = @_;
304 103 my $file = $self->label;
305 103 my $prefix = $self->home_label.' ';
306 103 ▶ if (index($layer, $prefix) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($layer, $prefix) == 0) 23 80 103
307 23 $file = $self->home_label;
308 23 $layer = substr $layer, length $prefix;
309 }
310 103 ▶ return $layer eq 'top' ? $file : $file.' '.$layer.':';
Branch: 1 branch
BranchTrueFalseTotal
$layer eq 'top' ? : 79 24 103
311 }
312  
313  
314 338 ▶sub value_label {
Subroutine value_label: called CC=3 SCAR=11.0
Pod documented
315 338 my ( $self, $engine, $key ) = @_;
316 338 ▶ return $self->label unless $self->uses_home;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->uses_home 312 26 338
317 26 ▶ return exists $self->_resolve($engine)->{project}{value}{$key} ? $self->label : $self->home_label;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->_resolve($engine)->{'project'}{'value'}{$key} ? : 2 24 26
318 }
319  
320 8 ▶sub detect_rule_label {
Subroutine detect_rule_label: called CC=4 SCAR=13.9
Pod documented
321 8 my ( $self, $engine, $pack ) = @_;
322 8 ▶ return $self->label.' detect:' unless $self->uses_home;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->uses_home 3 5 8
323 5 my $project = $self->_resolve($engine)->{project}{value}{detect};
324 5 ▶ my $from_project = ref $project eq 'HASH' ? exists $project->{$pack} : defined $project;
Branch: 1 branch
BranchTrueFalseTotal
ref $project eq 'HASH' ? : 4 1 5
325 5 ▶ return ( $from_project ? $self->label : $self->home_label ).' detect:';
Branch: 1 branch
BranchTrueFalseTotal
$from_project ? : 2 3 5
326 }
327  
328  
329 13 ▶sub engine {
Subroutine engine: called CC=4 SCAR=13.9
Pod documented
330 13 my ( $self ) = @_;
331 13 my $engine = $self->_resolve(undef)->{value}{engine};
332 13 ▶ return defined $engine && !ref $engine && length $engine ? $engine : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $engine && !ref($engine) && length $engine ? : 7 6 13
Condition83%5/6
defined $engine and not ref $engine and length $engine
!ll&&!rl&&r
607
defined $engine and not ref $engine
!ll&&!rl&&r
517
MC/DC66%2/3
defined $engine and not ref $engine and length $engine
defined $engine not ref $engine length $engine
Truth table75%3/4
A and not(B) and C
A= defined $engineB= not ref $engineC= length $engine
ABCresult
0XX0
10X0
1100
1111
333 }
334  
335  
336 1839 ▶sub options {
Subroutine options: called CC=1 SCAR=0.0
Pod documented
337 1839 my ( $self, $engine ) = @_;
338 1839 return { %{ $self->_resolve($engine)->{value} } };
339 }
340  
341  
342 295 ▶sub engine_options {
Subroutine engine_options: called CC=1 SCAR=0.0
Pod documented
343 295 my ( $self, $engine ) = @_;
344 295 my $opts = $self->options($engine);
345 295 delete @$opts{keys %APP_KEY};
346 295 return $opts;
347 }
348  
349  
350 373 ▶sub is_app_key {
Subroutine is_app_key: called CC=2 SCAR=6.9
Pod documented
351 373 my ( $self, $key ) = @_;
352 373 ▶ return $APP_KEY{$key} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$APP_KEY{$key} ? : 178 195 373
353 }
354  
355 19 ▶sub detect_class { 'Langertha::Raider::Detect' }
Subroutine detect_class: called CC=1 SCAR=0.0
Pod undocumented
356  
357  
358 11 ▶sub detect_settings {
Subroutine detect_settings: called CC=1 SCAR=0.0
Pod documented
359 11 my ( $self, $engine ) = @_;
360 11 my $opts = $self->options($engine);
361 11 return $self->normalize_detect($opts->{detect}, $opts->{no_detect});
362 }
363  
364  
365 747 ▶sub normalize_detect {
Subroutine normalize_detect: called CC=19 SCAR=30.0
Pod documented
366 747 my ( $self, $detect, $no_detect ) = @_;
367 747 my %settings = ( enabled => 1, rules => {}, off => {} );
368 747 ▶ if (defined $detect) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $detect) 31 716 747
369 31 ▶ if (ref $detect eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $detect eq 'HASH') { } 17 14 31
elsif (ref $detect) { } 2 12 14
370 17 for my $name (sort keys %$detect) {
371 26 my $rule = $detect->{$name};
372 26 ▶ if (ref $rule eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $rule eq 'HASH') { } 19 7 26
elsif (ref $rule or not defined $rule or $rule and $rule ne '1') { } 1 6 7
elsif (not $rule) { } 6 0 6
373 19 $self->detect_class->validate_rule($rule, 'detect.'.$name);
374 17 $settings{rules}{$name} = $rule;
375 }
376 ▶ elsif (ref $rule || !defined $rule || ($rule && $rule ne '1')) {
Condition55%5/9
ref $rule or not defined $rule or $rule and $rule ne 1
l!l&&r!l&&!r
016
ref $rule or not defined $rule
l!l&&r!l&&!r
007
$rule and $rule ne 1
!ll&&!rl&&r
601
MC/DC25%1/4
ref $rule or not defined $rule or $rule and $rule ne 1
ref $rule not defined $rule $rule $rule ne 1
Truth table40%2/5
A or not(B) or C and D
A= ref $ruleB= not defined $ruleC= $ruleD= $rule ne 1
ABCDresult
1XXX1
01XX1
00111
000X0
00100
377 1 croak 'Invalid detect setting detect.'.$name.': must be a rule or false';
378 }
379 elsif (!$rule) {
380 6 $settings{off}{$name} = 'detect: '.$name.': false';
381 }
382 }
383 }
384 elsif (ref $detect) {
385 2 croak 'Invalid detect setting detect: must be a map of pack name to rule, or false';
386 }
387 else {
388 12 ▶ $settings{enabled} = $detect ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$detect ? : 0 12 12
389 }
390 }
391 742 ▶ if (defined $no_detect) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $no_detect) 24 718 742
392 24 ▶ my @names = ref $no_detect eq 'ARRAY' ? @$no_detect
Branch: 2 branches
BranchTrueFalseTotal
ref $no_detect eq 'ARRAY' ? : 17 7 24
ref $no_detect ? : 1 6 7
393 : ref $no_detect ? croak 'Invalid detect setting no_detect: must be a list of pack names'
394 : split /\s*,\s*/, $no_detect;
395 23 for my $name (@names) {
396 38 ▶ croak 'Invalid detect setting no_detect: must be a list of pack names' if ref $name || !length($name // '');
Branch: 1 branch
BranchTrueFalseTotal
if ref $name or not length($name // "") 2 36 38
Condition60%3/5
ref $name or not length($name // "")
l!l&&r!l&&!r
2036
$name // ""
l!l
360
MC/DC50%1/2
ref $name or not length($name // "")
ref $name $name
Truth table66%2/3
A or not(B)
A= ref $nameB= $name
ABresult
1X1
001
010
397 36 $settings{off}{$name} = 'no_detect';
398 }
399 }
400 739 return \%settings;
401 }
402  
403  
404 79 has project_tools => (
405 is => 'ro',
406 isa => 'ArrayRef',
407 lazy_build => 1,
408 );
409  
410 159 ▶sub _build_project_tools {
Subroutine _build_project_tools: called CC=1 SCAR=0.0
411 159 my ( $self ) = @_;
412 159 return $self->normalize_project_tools($self->_project_tools_data->{project_tools});
413 }
414  
415 # The file whose top-level project_tools grants: the home layer, or the
416 # file in use when it is the home file; empty otherwise.
417 270 ▶sub _project_tools_data {
Subroutine _project_tools_data: called CC=3 SCAR=11.0
418 270 my ( $self ) = @_;
419 270 ▶ return $self->uses_home ? $self->home_data : $self->_is_home_file ? $self->data : {};
Branch: 2 branches
BranchTrueFalseTotal
$self->uses_home ? : 62 208 270
$self->_is_home_file ? : 5 203 208
420 }
421  
422  
423 159 ▶sub normalize_project_tools {
Subroutine normalize_project_tools: called CC=11 SCAR=24.0
Pod documented
424 159 my ( $self, $value ) = @_;
425 159 ▶ return [] unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 135 24 159
426 24 ▶ croak 'Invalid project_tools setting project_tools: must be a map of workspace selector to a list of tool names'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 2 22 24
427 unless ref $value eq 'HASH';
428 22 my @entries;
429 22 for my $selector (sort keys %$value) {
430 55 my $label = 'project_tools.'.$selector;
431 55 my $names = $value->{$selector};
432 55 ▶ my @tools = !defined $names ? ()
Branch: 3 branches
BranchTrueFalseTotal
!defined($names) ? : 0 55 55
ref $names eq 'ARRAY' ? : 52 3 55
ref $names ? : 2 1 3
433 : ref $names eq 'ARRAY' ? @$names
434 : ref $names ? croak 'Invalid project_tools setting '.$label.': must be a list of tool names'
435 : split /\s*,\s*/, $names;
436 53 for my $name (@tools) {
437 61 ▶ croak 'Invalid project_tools setting '.$label.': must be a list of tool names'
Branch: 1 branch
BranchTrueFalseTotal
if ref $name or not length($name // "") 2 59 61
Condition80%4/5
ref $name or not length($name // "")
l!l&&r!l&&!r
1159
$name // ""
l!l
600
MC/DC50%1/2
ref $name or not length($name // "")
ref $name $name
Truth table66%2/3
A or not(B)
A= ref $nameB= $name
ABresult
1X1
001
010
438 if ref $name || !length($name // '');
439 }
440 51 push @entries, { selector => $selector, kind => $self->_selector_kind($selector, $label), tools => \@tools };
441 }
442 15 return \@entries;
443 }
444  
445 51 ▶sub _selector_kind {
Subroutine _selector_kind: called CC=7 SCAR=19.5
446 51 my ( $self, $selector, $label ) = @_;
447 51 ▶ my $fail = sub { croak 'Invalid project_tools setting '.$label.': '.$_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
448 51 ▶ $fail->('empty workspace selector') unless length $selector;
Branch: 1 branch
BranchTrueFalseTotal
unless length $selector 0 51 51
449 51 ▶ return 'all' if $selector eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $selector eq "*" 11 40 51
450 40 ▶ return 'path' if $selector =~ m{\A(?:/|~(?:/|\z))};
Branch: 1 branch
BranchTrueFalseTotal
if $selector =~ m[\A(?:/|~(?:/|\z))] 34 6 40
451 6 ▶ $fail->('~user is not supported; start a path glob with / or ~/') if $selector =~ /\A~/;
Branch: 1 branch
BranchTrueFalseTotal
if $selector =~ /\A~/ 1 5 6
452 5 ▶ $fail->('a path glob must be absolute or start with ~/') if $selector =~ m{/};
Branch: 1 branch
BranchTrueFalseTotal
if $selector =~ m[/] 1 4 5
453 4 ▶ $fail->('a workspace name cannot hold * or ?; a path glob must be absolute or start with ~/') if $selector =~ /[*?]/;
Branch: 1 branch
BranchTrueFalseTotal
if $selector =~ /[*?]/ 1 3 4
454 3 return 'workspace';
455 }
456  
457  
458 17 ▶sub project_tools_matches {
Subroutine project_tools_matches: called CC=2 SCAR=7.0
Pod documented
459 17 my ( $self ) = @_;
460 17 my $root = path($self->root)->absolute;
461 17 ▶ $root = $root->realpath if -e $root;
Branch: 1 branch
BranchTrueFalseTotal
if -e $root 17 0 17
462 17 return [ map { { %$_, $self->_match_selector($_, "$root") } } @{ $self->project_tools } ];
463 }
464  
465 50 ▶sub _match_selector {
Subroutine _match_selector: called CC=5 SCAR=16.1
466 50 my ( $self, $entry, $root ) = @_;
467 50 ▶ return ( matched => 1, reason => '* matches every project' ) if $entry->{kind} eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $$entry{"kind"} eq "all" 13 37 50
468 37 ▶ return ( matched => 0, reason => 'workspace names are not supported yet' ) if $entry->{kind} eq 'workspace';
Branch: 1 branch
BranchTrueFalseTotal
if $$entry{"kind"} eq "workspace" 3 34 37
469 34 my $glob = $self->_selector_glob($entry->{selector});
470 34 ▶ return ( matched => 0, reason => 'no home directory for ~' ) unless defined $glob;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $glob 0 34 34
471 34 ▶ return $root =~ $self->_glob_regex($glob)
Branch: 1 branch
BranchTrueFalseTotal
$root =~ $self->_glob_regex($glob) ? : 17 17 34
472 ? ( matched => 1, reason => 'matches '.$root )
473 : ( matched => 0, reason => $glob.' does not match '.$root );
474 }
475  
476 # A path selector as an absolute glob: ~ expanded, trailing slashes
477 # dropped, the leading directories without a wildcard by their real path.
478 34 ▶sub _selector_glob {
Subroutine _selector_glob: called CC=9 SCAR=22.0
479 34 my ( $self, $selector ) = @_;
480 34 my $glob = $selector;
481 34 ▶ if ($glob =~ /\A~/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($glob =~ /\A~/) 28 6 34
482 28 my $home = $self->home_class->home_dir;
483 28 ▶ return unless defined $home;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $home 0 28 28
484 28 $glob = $home.substr($glob, 1);
485 }
486 34 $glob =~ s{(?<=.)/+\z}{};
487 34 my @parts = split m{/}, $glob, -1;
488 34 my $n = 0;
489 34 ▶ $n++ while $n < @parts && $parts[$n] !~ /[*?]/;
Branch: 1 branch
BranchTrueFalseTotal
$n < @parts and not $parts[$n] =~ /[*?]/ and do { ++$n } 130 34 164
Condition100%3/3
$n < @parts and not $parts[$n] =~ /[*?]/
!ll&&!rl&&r
925130
MC/DC100%2/2
$n < @parts and not $parts[$n] =~ /[*?]/
$n < @parts not $parts[$n] =~ /[*?]/
Truth table100%3/3
A and not(B)
A= $n < @partsB= not $parts[$n] =~ /[*?]/
ABresult
0X0
100
111
490 34 my $literal = join '/', @parts[0 .. $n - 1];
491 34 ▶ if (length $literal && -e $literal) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $literal and -e $literal) 24 10 34
Condition100%3/3
length $literal and -e $literal
!ll&&!rl&&r
3724
MC/DC100%2/2
length $literal and -e $literal
length $literal -e $literal
Truth table100%3/3
A and B
A= length $literalB= -e $literal
ABresult
0X0
100
111
492 24 my $real = path($literal)->realpath->stringify;
493 24 ▶ $glob = $n < @parts ? join('/', $real eq '/' ? '' : $real, @parts[$n .. $#parts]) : $real;
Branch: 2 branches
BranchTrueFalseTotal
$n < @parts ? : 18 6 24
$real eq '/' ? : 0 18 18
494 }
495 34 return $glob;
496 }
497  
498 # A glob as an anchored regex: ** any characters, * and ? without /,
499 # everything else literal.
500 34 ▶sub _glob_regex {
Subroutine _glob_regex: called CC=4 SCAR=13.9
501 34 my ( $self, $glob ) = @_;
502 my $re = join '', map {
503 34 ▶ $_ eq '**' ? '.*' : $_ eq '*' ? '[^/]*' : $_ eq '?' ? '[^/]' : quotemeta
Branch: 3 branches
BranchTrueFalseTotal
$_ eq '**' ? : 10 52 62
$_ eq '*' ? : 12 40 52
$_ eq '?' ? : 3 37 40
504 } split /(\*\*|\*|\?)/, $glob;
505 34 return qr/\A$re\z/;
506 }
507  
508 # How explain lists a project_tools that is not read: at the top of a
509 # project file (only the home file grants), or inside a section of either
510 # file.
511 32 ▶sub _ignored_project_tools {
Subroutine _ignored_project_tools: called CC=2 SCAR=6.9
512 32 my ( $self, $layer, $top ) = @_;
513 32 ▶ return { key => 'project_tools', reason => 'only ~/.raider/config.yml grants tools to projects; a project file cannot' }
Branch: 1 branch
BranchTrueFalseTotal
if $top 12 20 32
514 if $top;
515 20 return { key => $layer.'.project_tools', reason => 'read only at the top level of ~/.raider/config.yml' };
516 }
517  
518  
519 28 ▶sub normalize_skill_spec {
Subroutine normalize_skill_spec: called CC=5 SCAR=16.2
Pod documented
520 28 my ( $self, $spec ) = @_;
521 28 ▶ if (!ref $spec) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $spec) 17 11 28
522 return (
523 17 ▶ { type => 'file', path => 'CLAUDE.md' },
Branch: 1 branch
BranchTrueFalseTotal
if $spec eq "claude" 8 9 17
524 { type => 'claude', path => '.claude/skills' },
525 ) if $spec eq 'claude';
526 9 ▶ return { type => 'file', path => 'AGENTS.md' } if $PROFILE_KEYWORD{$spec};
Branch: 1 branch
BranchTrueFalseTotal
if $PROFILE_KEYWORD{$spec} 6 3 9
527 3 return { type => 'dir', path => $spec };
528 }
529 11 ▶ return $spec if ref $spec eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec eq "HASH" 11 0 11
530 0 return;
531 }
532  
533 239 ▶sub _skill_items {
Subroutine _skill_items: called CC=4 SCAR=13.9
534 239 my ( $self, $engine ) = @_;
535 239 my @items;
536 239 for my $layer (@{ $self->_resolve($engine)->{skills} }) {
537 20 my $raw = $layer->{value};
538 20 ▶ next unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 0 20 20
539 20 ▶ push @items, ref $raw eq 'ARRAY' ? @$raw : ($raw);
Branch: 1 branch
BranchTrueFalseTotal
ref $raw eq 'ARRAY' ? : 19 1 20
540 }
541 239 return @items;
542 }
543  
544 40 ▶sub _spec_key {
Subroutine _spec_key: called CC=2 SCAR=6.9
545 40 my ( $self, $spec ) = @_;
546 40 ▶ return join "\0", map { $spec->{$_} // '' } qw( type path glob );
Condition100%2/2
$$spec{$_} // ""
l!l
8040
MC/DC100%1/1
$$spec{$_} // ""
$$spec{$_}
Truth table100%2/2
A
A= $$spec{$_}
Aresult
11
00
547 }
548  
549  
550 210 ▶sub skill_specs {
Subroutine skill_specs: called CC=3 SCAR=11.0
Pod documented
551 210 my ( $self, $engine, @cli ) = @_;
552 210 my ( %seen, @specs );
553 210 for my $spec (map { $self->normalize_skill_spec($_) } $self->_skill_items($engine), @cli) {
554 36 ▶ push @specs, $spec unless $seen{ $self->_spec_key($spec) }++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$self->_spec_key($spec)}++ 32 4 36
555 }
556 210 return @specs;
557 }
558  
559  
560 29 ▶sub profiles {
Subroutine profiles: called CC=5 SCAR=16.1
Pod documented
561 29 my ( $self, $engine ) = @_;
562 29 my ( %seen, @profiles );
563 29 for my $item ($self->_skill_items($engine)) {
564 7 ▶ next if ref $item;
Branch: 1 branch
BranchTrueFalseTotal
if ref $item 0 7 7
565 7 ▶ my $profile = $PROFILE_KEYWORD{$item} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $profile = $PROFILE_KEYWORD{$item} or next 4 3 7
566 4 ▶ push @profiles, $profile unless $seen{$profile}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$profile}++ 3 1 4
567 }
568 29 return @profiles;
569 }
570  
571  
572 112 ▶sub explain {
Subroutine explain: called CC=9 SCAR=22.0
Pod documented
573 112 my ( $self, $engine ) = @_;
574 112 my $r = $self->_resolve($engine);
575 my @values = map {
576 116 my $key = $_;
577 {
578 key => $key,
579 value => $r->{value}{$key},
580 source => $r->{source}{$key},
581 shadowed => $r->{shadowed}{$key} // [],
582 applies_to => $APP_KEY{$key} ? 'raider' : 'engine',
583 116 ▶ ( $r->{merged_with} && $r->{merged_with}{$key} ? ( merged_with => $r->{merged_with}{$key} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
$APP_KEY{$key} ? : 37 79 116
$$r{'merged_with'} && $$r{'merged_with'}{$key} ? : 5 111 116
Condition100%5/5
$$r{"shadowed"}{$key} // []
l!l
1799
$$r{"merged_with"} and $$r{"merged_with"}{$key}
!ll&&!rl&&r
88235
MC/DC100%1/1
$$r{"shadowed"}{$key} // []
$$r{"shadowed"}{$key}
MC/DC100%2/2
$$r{"merged_with"} and $$r{"merged_with"}{$key}
$$r{"merged_with"} $$r{"merged_with"}{$key}
Truth table100%2/2
A
A= $$r{"shadowed"}{$key}
Aresult
11
00
Truth table100%3/3
A and B
A= $$r{"merged_with"}B= $$r{"merged_with"}{$key}
ABresult
0X0
100
111
584 }
585 111 } sort keys %{ $r->{value} };
586 push @values, map {
587 17 { key => 'skills', value => $_->{value}, source => $_->{source}, merged => 1, applies_to => 'raider' }
588 111 } @{ $r->{skills} };
589 return {
590 file => $self->file->stringify,
591 exists => $self->file_exists,
592 label => $self->label,
593 ignored_files => [ $self->ignored_files ],
594 ( $self->uses_home ? ( home_file => $self->home_file->stringify ) : () ),
595 engine => $engine,
596 values => \@values,
597 ignored => $r->{ignored},
598 111 ▶ ( defined $self->_project_tools_data->{project_tools} ? ( project_tools => {
Branch: 4 branches
BranchTrueFalseTotal
$self->uses_home ? : 34 77 111
defined $self->_project_tools_data->{'project_tools'} ? : 11 100 111
$self->uses_home ? : 10 1 11
$self->uses_home ? : 10 1 11
599 file => ( $self->uses_home ? $self->home_file : $self->file )->stringify,
600 label => $self->uses_home ? $self->home_label : $self->label,
601 selectors => $self->project_tools_matches,
602 } ) : () ),
603 };
604 }
605  
606 # The one writer: mutate the parsed data, write it back when the callback
607 # returns true, then re-read. Refuses (croaks) on a file that does not parse.
608 133 ▶sub _update {
Subroutine _update: called CC=2 SCAR=6.9
609 133 my ( $self, $code ) = @_;
610 133 my $data = $self->data;
611 131 ▶ return unless $code->($data);
Branch: 1 branch
BranchTrueFalseTotal
unless &$code($data) 107 24 131
612 24 $self->file->spew_utf8($self->_dump($data));
613 24 $self->clear_data;
614 24 return 1;
615 }
616  
617 # The one YAML dump, for the project writers and update_home alike.
618 32 ▶sub _dump { YAML::PP->new->dump_string($_[1]) }
Subroutine _dump: called CC=1 SCAR=0.0
619  
620  
621 10 ▶sub update_home {
Subroutine update_home: called CC=5 SCAR=16.1
Pod documented
622 10 my ( $self, $code ) = @_;
623 10 my $file = $self->home_file;
624 10 ▶ croak __PACKAGE__.'->update_home: there is no home directory' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 1 9 10
625 9 my $data = $self->_load($file);
626 7 ▶ return unless $code->($data);
Branch: 1 branch
BranchTrueFalseTotal
unless &$code($data) 1 6 7
627 6 my $yaml = $self->_dump($data);
628 5 my $dir = $file->parent;
629 5 ▶ unless ( -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 1 4 5
630 1 $dir->mkpath( { mode => 0700 } );
631 1 chmod 0700, $dir;
632 }
633 5 my $tmp = $dir->tempfile('.config.yml.XXXXXX');
634 5 $tmp->spew_utf8($yaml);
635 5 chmod 0600, $tmp;
636 5 ▶ if ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 4 1 5
637 4 my $bak = $dir->child('config.yml.bak');
638 4 $file->copy($bak);
639 4 chmod 0600, $bak;
640 }
641 5 $tmp->move($file);
642 5 $self->clear_data;
643 5 $self->clear_home_data;
644 5 $self->clear_uses_home;
645 5 $self->clear_project_tools;
646 5 return 1;
647 }
648  
649  
650 122 ▶sub add_skills {
Subroutine add_skills: called CC=1 SCAR=0.0
Pod documented
651 122 my ( $self, @items ) = @_;
652 122 my @added;
653 121 ▶ $self->_update(sub {
Subroutine __ANON__: called CC=10 SCAR=23.0
654 121 my ( $data ) = @_;
655 121 my @have;
656 # copy the values: a foreach alias would autovivify default: { skills: ~ }
657 121 ▶ my @raw = ( $data->{skills}, ( ref $data->{default} eq 'HASH' ? $data->{default}{skills} : () ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $$data{'default'} eq 'HASH' ? : 9 112 121
658 121 for my $raw (@raw) {
659 130 ▶ next unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 118 12 130
660 12 ▶ push @have, ref $raw eq 'ARRAY' ? @$raw : ($raw);
Branch: 1 branch
BranchTrueFalseTotal
ref $raw eq 'ARRAY' ? : 11 1 12
661 }
662 121 my %have = map { $self->_item_key($_) => 1 } @have;
663 my @list = !defined $data->{skills} ? ()
664 6 : ref $data->{skills} eq 'ARRAY' ? @{ $data->{skills} }
665 121 ▶ : ($data->{skills});
Branch: 2 branches
BranchTrueFalseTotal
!defined($$data{'skills'}) ? : 114 7 121
ref $$data{'skills'} eq 'ARRAY' ? : 6 1 7
666 121 for my $item (@items) {
667 23 ▶ next if $have{ $self->_item_key($item) }++;
Branch: 1 branch
BranchTrueFalseTotal
if $have{$self->_item_key($item)}++ 7 16 23
668 16 push @list, $item;
669 16 push @added, $item;
670 }
671 121 ▶ return 0 unless @added;
Branch: 1 branch
BranchTrueFalseTotal
unless @added 107 14 121
672 14 $data->{skills} = \@list;
673 14 return 1;
674 122 });
675 121 return @added;
676 }
677  
678 41 ▶sub _item_key {
Subroutine _item_key: called CC=3 SCAR=11.1
679 41 my ( $self, $item ) = @_;
680 41 ▶ return ref $item eq 'HASH' ? $self->_spec_key($item) : 'item:'.($item // '');
Branch: 1 branch
BranchTrueFalseTotal
ref $item eq 'HASH' ? : 4 37 41
Condition50%1/2
$item // ""
l!l
370
MC/DC0%0/1
$item // ""
$item
Truth table50%1/2
A
A= $item
Aresult
11
00
681 }
682  
683  
684 11 ▶sub set_model {
Subroutine set_model: called CC=1 SCAR=0.0
Pod documented
685 11 my ( $self, $model ) = @_;
686 10 ▶ $self->_update(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
687 10 my ( $data ) = @_;
688 10 ▶ $data->{default} = {} unless ref $data->{default} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $$data{"default"} eq "HASH" 9 1 10
689 10 $data->{default}{model} = $model;
690 10 return 1;
691 11 });
692 10 return;
693 }
694  
695  
696 16 ▶sub remove_api_keys {
Subroutine remove_api_keys: called CC=5 SCAR=16.1
Pod documented
697 16 my ( $self, $data ) = @_;
698 16 my @where;
699 16 ▶ push @where, 'top' if exists $data->{api_key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$data{"api_key"} 2 14 16
700 16 delete $data->{api_key};
701 33 ▶ my @sections = sort { ( $a ne 'default' ) <=> ( $b ne 'default' ) || $a cmp $b }
Condition66%2/3
($a ne 'default') <=> ($b ne 'default') || $a cmp $b
l!l&&r!l&&!r
22110
MC/DC0%0/2
($a ne 'default') <=> ($b ne 'default') || $a cmp $b
($a ne 'default') <=> ($b ne 'default') $a cmp $b
Truth table66%2/3
A || B
A= ($a ne 'default') <=> ($b ne 'default')B= $a cmp $b
ABresult
1X1
011
000
702 16 grep { $self->_is_section($data, $_) } keys %$data;
703 16 for my $section (@sections) {
704 40 ▶ next unless exists $data->{$section}{api_key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$section}{"api_key"} 33 7 40
705 7 delete $data->{$section}{api_key};
706 7 push @where, $section;
707 }
708 16 return @where;
709 }
710  
711  
712 17 ▶sub migration_content {
Subroutine migration_content: called CC=9 SCAR=22.2
Pod documented
713 17 my ( $self ) = @_;
714 17 my $file = $self->legacy_file;
715 17 my $want = $self->_load($file);
716 16 ▶ my $text = -f $file ? $file->slurp_utf8 : '';
Branch: 1 branch
BranchTrueFalseTotal
-f $file ? : 16 0 16
717 16 my @where = $self->remove_api_keys($want);
718 16 ▶ return { text => $text, api_keys => [], removed_lines => [], rewritten => 0 } unless @where;
Branch: 1 branch
BranchTrueFalseTotal
unless @where 11 5 16
719 5 my @lines = split /^/m, $text;
720 5 my ( @kept, @removed );
721 5 for my $n (0 .. $#lines) {
722 27 ▶ if ($lines[$n] =~ /\A[ \t]*api_key[ \t]*:(?:[ \t].*)?\r?\n?\z/) { push @removed, $n + 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[$n] =~ /\A[ \t]*api_key[ \t]*:(?:[ \t].*)?\r?\n?\z/) { } 7 20 27
723 20 else { push @kept, $lines[$n] }
724 }
725 5 my $stripped = join '', @kept;
726 5 my $got = eval { YAML::PP->new->load_string($stripped) };
727 5 ▶ $got = {} if !$@ && !defined $got;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ or defined $got 0 5 5
Condition33%1/3
$@ or defined $got
l!l&&r!l&&!r
050
MC/DC0%0/2
$@ or defined $got
$@ defined $got
Truth table33%1/3
A or B
A= $@B= defined $got
ABresult
1X1
011
000
728 5 my $json = JSON::MaybeXS->new(canonical => 1, allow_nonref => 1, allow_blessed => 1, convert_blessed => 1);
729 5 ▶ return { text => $stripped, api_keys => \@where, removed_lines => \@removed, rewritten => 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ref $got eq "HASH" and $json->encode($got) eq $json->encode($want) 2 3 5
Condition66%2/3
ref $got eq "HASH" and $json->encode($got) eq $json->encode($want)
!ll&&!rl&&r
032
MC/DC50%1/2
ref $got eq "HASH" and $json->encode($got) eq $json->encode($want)
ref $got eq "HASH" $json->encode($got) eq $json->encode($want)
Truth table66%2/3
A and B
A= ref $got eq "HASH"B= $json->encode($got) eq $json->encode($want)
ABresult
0X0
100
111
730 if ref $got eq 'HASH' && $json->encode($got) eq $json->encode($want);
731 3 return { text => $self->_dump($want), api_keys => \@where, removed_lines => [], rewritten => 1 };
732 }
733  
734 79 __PACKAGE__->meta->make_immutable;
735  
736 79 1;
737  
738 __END__
739  
740 =pod
741  
742 =encoding UTF-8
743  
744 =head1 NAME
745  
746 Langertha::Raider::Config - Internal resolver and writer for the project config file
747  
748 =head1 VERSION
749  
750 version 0.503
751  
752 =head1 SYNOPSIS
753  
754 # Internal to Langertha-Raider -- no API promise.
755 my $config = Langertha::Raider::Config->new( root => $dir );
756  
757 my $engine = $config->engine; # engine: from the file, or undef
758 my $options = $config->engine_options('openai'); # for the engine constructor
759 my @specs = $config->skill_specs('openai');
760 my $report = $config->explain('openai'); # which value came from where
761  
762 my @added = $config->add_skills('claude'); # the one writer
763 $config->set_model('gpt-4o');
764  
765 =head1 DESCRIPTION
766  
767 B<Internal module.> Its interface may change without notice; use
768 L<Langertha::Raider::CLI> instead.
769  
770 The one place that reads and writes the project config of L</root>. The
771 file in use (L</file>) is F<.raider/config.yml> (ADR 0011) when it exists,
772 else the legacy F<.raider.yml>; both take the same keys. When both exist,
773 only F<.raider/config.yml> is loaded: the legacy file is not read and is
774 reported by L</ignored_files>.
775  
776 Under the project file lies the home file F<~/.raider/config.yml> (ADR
777 0011; L</home_file>), with the same keys: default E<lt> home E<lt>
778 project E<lt> command line. Each file is read in three layers, later ones
779 winning:
780  
781 =over
782  
783 =item C<top> -- every top-level key whose value is not a hash (plus
784 C<skills>, C<detect> and C<project_tools>, which may be one)
785  
786 =item C<default> -- the C<default:> section
787  
788 =item the engine section -- the section named after the active engine
789 (C<openai:>, C<anthropic:>, ...)
790  
791 =back
792  
793 Every other top-level hash is the section of an engine that is not active.
794 C<skills> is merged across the layers instead of replaced. C<engine> is read
795 from C<top> and C<default> only, as it picks the engine section.
796  
797 Then the project file's values are laid over the home file's, per key:
798  
799 =over
800  
801 =item C<skills> -- both files' lists, home first, duplicates dropped
802  
803 =item C<no_detect> -- both files' pack names, home first, duplicates
804 dropped
805  
806 =item C<detect> -- when both are maps, per pack: the project's entry for a
807 pack replaces the home's (ADR 0012); otherwise the project's value
808 replaces the home's
809  
810 =item everything else, C<packs> and C<api_key> included -- the project's
811 value replaces the home's
812  
813 =back
814  
815 C<project_tools> is not layered at all: only the top level of the home
816 file grants tools to projects (L</project_tools>).
817  
818 The project writers never touch the home file (L</update_home> is the only
819 one, with no caller yet). When the home file is the file in
820 use -- raider runs in the home directory itself -- it is read once, as the
821 project file, and there is no home layer.
822  
823 A file, project or home, that does not parse, whose top level is not a mapping, or that holds
824 a mapping under one of raider's own keys other than C<skills>, C<detect> and C<project_tools>
825 (see L</is_app_key>) -- at top level or in any section, active or not -- is
826 an error: readers croak and the writer refuses to
827 overwrite it.
828  
829 =head2 root
830  
831 The project directory. Required.
832  
833 =head2 file
834  
835 L<Path::Tiny> of the file in use: L</native_file> when it exists, else
836 L</legacy_file>. Decided once, when first asked. The writers write here, so
837 without any file they create the legacy F<.raider.yml>, never
838 F<.raider/config.yml>; only C<raider config migrate>
839 (L<Langertha::Raider::Config::Migrate>, with L</migration_content>)
840 creates that.
841  
842 =head2 home_file
843  
844 L<Path::Tiny> of F<config.yml> in the user's F<~/.raider>
845 (L<Langertha::Raider::Home/home_base>), present or not; undef when there
846 is no home at all.
847  
848 =head2 uses_home
849  
850 True when L</home_file> is read as the home layer: it exists and is not
851 the file in use (L</file>, compared by real path). Decided once, when
852 first asked.
853  
854 =head2 home_label
855  
856 C<home>: how reports name the home file as a source.
857  
858 =head2 native_file
859  
860 L<Path::Tiny> of F<.raider/config.yml> in L</root>, present or not.
861  
862 =head2 legacy_file
863  
864 L<Path::Tiny> of F<.raider.yml> in L</root>, present or not.
865  
866 =head2 is_native
867  
868 True when L</file> is F<.raider/config.yml>.
869  
870 =head2 label
871  
872 The file in use relative to L</root>, C<.raider/config.yml> or
873 C<.raider.yml>: how reports name it as a source.
874  
875 =head2 ignored_files
876  
877 for my $ign ($config->ignored_files) {
878 warn 'ignoring '.$ign->{file}.': '.$ign->{reason}."\n";
879 }
880  
881 The config files that are present but not loaded, each as C<file>
882 (absolute path) and C<reason>: the legacy F<.raider.yml> while
883 F<.raider/config.yml> is in use. Empty otherwise.
884  
885 =head2 data
886  
887 The parsed file as a hash; empty when the file is missing or empty. Croaks
888 when the file does not parse, its top level is not a mapping, or a raider
889 key other than C<skills>, C<detect> and C<project_tools> holds a mapping,
890 at top level or in a section.
891  
892 =head2 home_data
893  
894 L</home_file> parsed like L</data>, croaking like it; empty unless
895 L</uses_home>.
896  
897 =head2 file_exists
898  
899 True when L</file> exists.
900  
901 =head2 layer_label
902  
903 $config->layer_label('default'); # '.raider/config.yml default:'
904 $config->layer_label('home openai'); # 'home openai:'
905  
906 How reports name a layer of L</explain>: the label of its file (L</label>,
907 or L</home_label> for a C<home> layer), then the section and a colon
908 unless it is the top level.
909  
910 =head2 value_label
911  
912 my $where = $config->value_label($engine_name, 'packs'); # 'home'
913  
914 The label of the file the effective value of a key comes from:
915 L</home_label> when only the home file sets it, else L</label>.
916  
917 =head2 detect_rule_label
918  
919 my $from = $config->detect_rule_label($engine_name, 'perl'); # 'home detect:'
920  
921 Where the effective C<detect:> entry of a pack comes from: the label of
922 its file, as L</value_label>, and C<detect:>.
923  
924 =head2 engine
925  
926 The engine name from C<engine:> (top level or C<default:>), or undef.
927  
928 =head2 options
929  
930 my $opts = $config->options($engine_name);
931  
932 Every effective key except C<skills>, layered for C<$engine_name>.
933  
934 =head2 engine_options
935  
936 my $opts = $config->engine_options($engine_name);
937  
938 L</options> without raider's own keys (C<detect>, C<engine>, C<no_detect>,
939 C<packs>, C<perl>, C<preferred_lib_target>, C<project_tools>, C<skills>): what goes to the
940 engine constructor.
941  
942 =head2 is_app_key
943  
944 $config->is_app_key('perl'); # 1
945  
946 True for the keys that configure raider itself (C<detect>, C<engine>,
947 C<no_detect>, C<packs>, C<perl>, C<preferred_lib_target>, C<project_tools>,
948 C<skills>) and never reach the engine constructor.
949  
950 =head2 detect_settings
951  
952 my $d = $config->detect_settings($engine_name);
953 # { enabled => 1,
954 # rules => { perl => { must => [ { file => 'cpanfile' } ] } },
955 # off => { rust => 'no_detect', go => 'detect: go: false' } }
956  
957 Pack detection (ADR 0012) as configured in the file: L</normalize_detect>
958 of the effective C<detect> and C<no_detect> values for C<$engine_name>.
959 Croaks on an invalid value or rule.
960  
961 =head2 normalize_detect
962  
963 my $d = $config->normalize_detect($detect, $no_detect);
964  
965 Checks and normalizes a C<detect> value -- a map of pack name to rule
966 (L<Langertha::Raider::Detect>) or C<false>, a pack name mapped to C<false>
967 switching detection off for that pack, the whole key C<false> switching
968 it off entirely -- and a C<no_detect> list of pack names (or a
969 comma-separated string). Returns C<enabled>, C<rules> and C<off> (pack name
970 to the reason) as in L</detect_settings>; croaks naming the offending key.
971  
972 =head2 project_tools
973  
974 for my $entry (@{ $config->project_tools }) {
975 # { selector => '~/dev/*', kind => 'path', tools => ['telegram'] }
976 }
977  
978 C<project_tools> of the home file (ADR 0011): which home tools and
979 services a project gets, as a map of workspace selector to a list of tool
980 names (or one comma-separated string). Only the top level of
981 F<~/.raider/config.yml> counts -- the home layer, or the file in use when
982 raider runs in the home directory itself. A project file cannot grant:
983 its C<project_tools>, like one inside a C<default:> or engine section of
984 either file, is not read and is listed as ignored by L</explain>.
985  
986 The entries, sorted by selector, each with its C<kind>:
987  
988 =over
989  
990 =item C<all> -- the selector C<*>, every project
991  
992 =item C<path> -- a path glob: absolute, or starting with C<~/> (C<~> is
993 the user's home). It is matched against the real path of L</root>, the
994 whole path: C<**> matches any characters, C<*> and C<?> any characters or
995 one character except C</>; everything else, C<[> and C<{> included, is
996 literal. A trailing C</> is dropped, so C<~/dev/*> matches F<~/dev/foo>
997 but not F<~/dev/foo/bar>, and C<~/dev/**> matches every directory below
998 F<~/dev>, not F<~/dev> itself. The leading directories without a wildcard
999 are resolved to their real path when they exist, so a symlink on the way
1000 does not keep a glob from matching.
1001  
1002 =item C<workspace> -- any other selector: a workspace name (ADR 0004).
1003 Accepted, but never matched yet: raider has no workspace registry.
1004  
1005 =back
1006  
1007 Empty when the home file has no C<project_tools>. Croaks with C<Invalid
1008 project_tools setting ...> naming the offending key when the value is not
1009 a map, a selector holds no list of names, or a selector is C<~user>, a
1010 relative path, or a name with a wildcard. Information only: nothing is
1011 mounted from it yet (L</explain>).
1012  
1013 =head2 normalize_project_tools
1014  
1015 my $entries = $config->normalize_project_tools($value);
1016  
1017 Checks a C<project_tools> value and returns its entries as in
1018 L</project_tools>; croaks like it.
1019  
1020 =head2 project_tools_matches
1021  
1022 for my $m (@{ $config->project_tools_matches }) {
1023 # { selector => '~/dev/*', kind => 'path', tools => ['telegram'],
1024 # matched => 1, reason => 'matches /home/me/dev/app' }
1025 }
1026  
1027 The entries of L</project_tools>, each with whether it applies to
1028 L</root> (C<matched>) and why (C<reason>). A workspace name never matches:
1029 C<workspace names are not supported yet>.
1030  
1031 =head2 normalize_skill_spec
1032  
1033 my @specs = $config->normalize_skill_spec($item);
1034  
1035 Turns one C<skills:> item into skill-source hashes: C<claude> becomes
1036 F<CLAUDE.md> plus F<.claude/skills>, C<openai> / C<codex> / C<agents> become
1037 F<AGENTS.md>, any other string a markdown directory, a hash passes through.
1038  
1039 =head2 skill_specs
1040  
1041 my @specs = $config->skill_specs($engine_name, @cli_specs);
1042  
1043 The skill sources of every layer, then C<@cli_specs>, normalized and
1044 deduplicated in that order.
1045  
1046 =head2 profiles
1047  
1048 my @profiles = $config->profiles($engine_name);
1049  
1050 The agent profiles (C<claude>, C<openai>) named in C<skills:>, in order.
1051  
1052 =head2 explain
1053  
1054 my $report = $config->explain($engine_name);
1055  
1056 Where each effective value came from:
1057  
1058 {
1059 file => '/path/.raider/config.yml',
1060 exists => 1,
1061 label => '.raider/config.yml',
1062 ignored_files => [ { file => '/path/.raider.yml', reason => '...' } ],
1063 engine => 'openai',
1064 values => [
1065 { key => 'temperature', value => 0.7, source => 'openai',
1066 shadowed => ['default'], applies_to => 'engine' },
1067 { key => 'skills', value => ['claude'], source => 'top',
1068 merged => 1, applies_to => 'raider' },
1069 ],
1070 ignored => [ { key => 'anthropic', reason => 'section of an inactive engine' } ],
1071 }
1072  
1073 C<source> is a layer (C<top>, C<default> or the engine name), for the
1074 home file prefixed with C<home> (C<home top>, C<home default>, ...;
1075 L</layer_label> names them); C<applies_to> says whether the value reaches
1076 the engine constructor or configures raider itself. C<skills> gets one
1077 entry per layer, as they merge. A C<no_detect> or C<detect> merged from
1078 both files names the home layer it took values from in C<merged_with>.
1079 C<file> is the file in use, C<label> its L</label> and C<ignored_files>
1080 the L</ignored_files>; C<home_file> is L</home_file>, present only when
1081 L</uses_home>.
1082  
1083 C<project_tools> is present when the home file has one: C<file> and
1084 C<label> of the file it was read from, and C<selectors>, the
1085 L</project_tools_matches> -- information only, it mounts nothing. A
1086 C<project_tools> that is not read (in a project file, or inside a section)
1087 is listed in C<ignored>.
1088  
1089 =head2 update_home
1090  
1091 $config->update_home(sub {
1092 my ( $data ) = @_;
1093 $data->{default}{model} = 'gpt-4o';
1094 return 1; # true: write it
1095 });
1096  
1097 Internal, no caller yet besides tests. The one writer of the home file
1098 L</home_file>, shaped like the project writers: the callback gets the
1099 parsed data of that file (empty when the file is absent), changes it in
1100 place and returns true to have it written; false leaves the disk alone.
1101 Returns true when it wrote.
1102  
1103 Nothing but this method writes the home file. It creates F<~/.raider>
1104 (mode 0700) and the file (mode 0600, the home file may hold an C<api_key>)
1105 when absent. The new content is dumped first, written to a temporary file
1106 next to the target and renamed over it, so a failure never leaves a partial
1107 file; the previous file is kept as F<config.yml.bak>, one generation,
1108 replaced by every write. A home file that does not parse (or whose
1109 top level is no mapping) croaks like L</data> does and stays untouched.
1110  
1111 When raider runs in the home directory itself, L</home_file> is the project
1112 file: the same file is written, and the caches are dropped. Croaks when
1113 there is no home at all.
1114  
1115 =head2 add_skills
1116  
1117 my @added = $config->add_skills('claude', 'my-skills');
1118  
1119 Appends the items not yet listed to the top-level C<skills:> list and writes
1120 the file. Items already present at top level or in C<default:> are skipped.
1121 Returns the items that were added.
1122  
1123 =head2 set_model
1124  
1125 $config->set_model('gpt-4o');
1126  
1127 Writes C<default: { model: ... }>, the shape the REPL's C</model> saves.
1128  
1129 =head2 remove_api_keys
1130  
1131 my @where = $config->remove_api_keys($data); # ('top', 'openai')
1132  
1133 Deletes C<api_key> from the top level and from every section of the
1134 parsed C<$data>, in place. Returns the layers it was in, named as in
1135 L</explain> (C<top>, C<default>, the engine sections sorted).
1136  
1137 =head2 migration_content
1138  
1139 my $m = $config->migration_content;
1140 # { text => "...", api_keys => ['top', 'openai'],
1141 # removed_lines => [ 3, 9 ], rewritten => 0 }
1142  
1143 The legacy F<.raider.yml> (L</legacy_file>) as the content of a
1144 F<.raider/config.yml>, for C<raider config migrate>: the file as it is,
1145 but without any C<api_key> (L</remove_api_keys>), because a project must
1146 not choose a secret. The C<api_key> lines are dropped from the text, so
1147 comments and layout stay, when what is left parses to exactly the data
1148 without the keys; C<removed_lines> are their line numbers. Otherwise the
1149 data without the keys is written anew (C<rewritten>), losing comments and
1150 layout. Croaks like L</data> when the file does not parse; an absent file
1151 gives an empty text.
1152  
1153 =head1 SEE ALSO
1154  
1155 =over
1156  
1157 =item * L<Langertha::Raider::CLI>
1158  
1159 =back
1160  
1161 =head1 SUPPORT
1162  
1163 =head2 Issues
1164  
1165 Please report bugs and feature requests on GitHub at
1166 L<https://github.com/Getty/langertha-raider/issues>.
1167  
1168 =head2 IRC
1169  
1170 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
1171  
1172 =head1 CONTRIBUTING
1173  
1174 Contributions are welcome! Please fork the repository and submit a pull request.
1175  
1176 =head1 AUTHOR
1177  
1178 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
1179  
1180 =head1 COPYRIGHT AND LICENSE
1181  
1182 This software is copyright (c) 2026 by Torsten Raudssus.
1183  
1184 This is free software; you can redistribute it and/or modify it under
1185 the same terms as the Perl 5 programming language system itself.
1186  
1187 =cut
« blib/lib/Langertha/Raider/Hall/Protocol.pm ↑ Summary blib/lib/Langertha/Raider/Plugin/Trace.pm »