lib/Skilletor/Engine.pm

filter: Statementstmt 96.4% 950 / 985 Branchbran 84.2% 359 / 426 Conditioncond 70.1% 305 / 435 MC/DCmcdc 47.9% 117 / 244 Subroutinesub 100% 111 / 111 Podpod 100% 5 / 5 totaltotal 83.7% 1847 / 2206 CC 409 SCAR 32.9
CC
409
Cov
87%
_sync_codex_rules
114.8
_sync_scope_run
52.1
status
33.6
CRAP 26.8
« /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Cpanel/JSON/XS.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/Config.pm »
1 package Skilletor::Engine;
2 # ABSTRACT: sync, check and status for Claude Code, Codex and Hermes – the reference's engine pipeline after the resolve
3  
4 399 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 399 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 399 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 399 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 399 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 399 ▶use Scalar::Util qw( blessed refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 399 ▶use Skilletor::AgentsMD qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 RULES_FILE codex_hook_trusted inspect_agents_md parse_rules_file pointer_lines project_doc_limit rules_file_text with_block
12 399 );
13 399 ▶use Skilletor::Apply qw( apply );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 399 ▶use Skilletor::Backend;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 399 ▶use Skilletor::Briefing qw( briefing_warning missing_skills skill_roots );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 399 ▶use Skilletor::Bundles qw( matches_pattern );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 399 ▶use Skilletor::ClaudeSettings qw( plan_claude_settings );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 399 ▶use Skilletor::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 399 ▶use Skilletor::Convert qw( convert_for_target );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 399 ▶use Skilletor::Entry qw( HARNESSES ITEM_TYPES );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 399 ▶use Skilletor::FSUtil qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 decode_utf8_lossy encode_text hash_bytes is_absolute node_fs_error path_join path_resolve read_text same_file same_path to_posix write_text
23 399 );
24 399 ▶use Skilletor::Gitignore qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
25 CODEX_ENTRIES LOCAL_ENTRIES PROJECT_CLAUDE_ENTRIES SKILL_GITIGNORE WORKTREE_INCLUDE
26 block_entries has_block skill_gitignore_path update_gitignore update_worktree_include with_skill_gitignore
27 399 );
28 399 ▶use Skilletor::GitEnv qw( git_env );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 399 ▶use Skilletor::JSON qw( js_ordered js_sort_keys js_stringify js_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 399 ▶use Skilletor::Lock qw( key_to_type_name parse_lock_key read_lock write_lock );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 399 ▶use Skilletor::Process qw( run_command );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 399 ▶use Skilletor::Render qw( build executables renders_empty );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 399 ▶use Skilletor::Report qw( empty_scope_report );
Subroutine BEGIN: called CC=1 SCAR=0.0
34 399 ▶use Skilletor::Source::Git;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 399 ▶use Skilletor::Source::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 399 ▶use Skilletor::Source::Url;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 399 ▶use Skilletor::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 399 ▶use Skilletor::Targets qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
39 all_roots default_hermes_home detect_harnesses detect_project_harnesses is_block_type is_local_type lacks_local_prefix lock_key
40 place_output receivers root_of root_of_key select_targets served_via supports target_gaps
41 399 );
42 399 ▶use Sys::Hostname ();
Subroutine BEGIN: called CC=1 SCAR=0.0
43 399 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44 399 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 399 extends 'Skilletor::Resolver';
47  
48 399 our $VERSION = '0.008000';
49  
50 # What a sync makes of unchanged sources and inputs (the reference's RENDER_FORMAT, k107): part
51 # of the render-inputs hash, so both implementations record and compare the same one.
52 399 ▶use constant RENDER_FORMAT => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 399 my %TYPE_DIR = ( skill => 'skills', agent => 'agents', rule => 'rules' );
55  
56 # process.platform where Perl's $^O names the system otherwise.
57 399 my %NODE_PLATFORM = ( MSWin32 => 'win32', solaris => 'sunos' );
58  
59 # Does a user-scope root lie inside a git work tree (spec §6.4)? Default: ask git.
60 has is_git_work_tree => (
61 is => 'ro',
62 324 ▶ default => sub { \&Skilletor::Gitignore::is_git_work_tree },
Subroutine __ANON__: called CC=1 SCAR=0.0
63 399 );
64  
65 # Which of the paths (relative to a root) does git track? Default: one `git ls-files`.
66 has git_tracked => (
67 is => 'ro',
68 433 ▶ default => sub { \&Skilletor::Gitignore::git_tracked },
Subroutine __ANON__: called CC=1 SCAR=0.0
69 399 );
70  
71 # The project's `origin` remote, a render input of the project scope. Default: ask git.
72 has git_remote => (
73 is => 'ro',
74 4533 ▶ default => sub { \&_git_remote },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 399 );
76  
77 # `$HERMES_HOME` (spec §16.2): the root of user-scope Hermes skills – the Hermes plugin passes its
78 # session's. Unset or empty: the home the last user-scope sync recorded, else Hermes' default.
79 has hermes_home => (
80 is => 'lazy',
81 2493 ▶ builder => sub { defined $ENV{HERMES_HOME} ? decode_utf8_lossy( $ENV{HERMES_HOME} ) : undef },
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 2 branches
BranchTrueFalseTotal
defined $ENV{'HERMES_HOME'} ? : 9 2484 2493
defined $ENV{'HERMES_HOME'} ? : 0 336 336
82 399 );
83  
84 # `CLAUDE_PLUGIN_ROOT`: the running plugin's install, naming skilletor's marketplace (spec §6.8).
85 has plugin_root => (
86 is => 'lazy',
87 425 ▶ builder => sub { defined $ENV{CLAUDE_PLUGIN_ROOT} ? decode_utf8_lossy( $ENV{CLAUDE_PLUGIN_ROOT} ) : undef },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'CLAUDE_PLUGIN_ROOT'} ? : 4 421 425
88 399 );
89  
90 # The render context's `host` (spec §5). Default: this machine's name and OS, as Node names them.
91 has host => (
92 is => 'lazy',
93 60 ▶ builder => sub { js_ordered( name => Sys::Hostname::hostname(), os => $NODE_PLATFORM{$^O} // $^O ) },
Subroutine __ANON__: called CC=2 SCAR=10.1
Condition33%2/6
$NODE_PLATFORM{$^O} // $^O
l!l&&r!l&&!r
0600
$NODE_PLATFORM{$^O} // $^O
l!l&&r!l&&!r
01450
MC/DC0%0/2
$NODE_PLATFORM{$^O} // $^O
$NODE_PLATFORM{$^O} $^O
MC/DC0%0/2
$NODE_PLATFORM{$^O} // $^O
$NODE_PLATFORM{$^O} $^O
Truth table33%1/3
A // B
A= $NODE_PLATFORM{$^O}B= $^O
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $NODE_PLATFORM{$^O}B= $^O
ABresult
1X1
011
000
94 399 );
95  
96 # The render context's `user` (spec §5). Default: the login name, as Node's os.userInfo() finds
97 # it, and the engine's home.
98 has user => (
99 is => 'lazy',
100 164 ▶ builder => sub { js_ordered( name => _user_name(), home => $_[0]->home ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _build_user: called CC=1 SCAR=0.0
101 399 );
102  
103 # Node's os.userInfo().username: the effective user's passwd entry (Windows: the account name).
104 # Without an entry Node throws, and the reference's build of every item fails with its message.
105 123 ▶sub _user_name {
Subroutine _user_name: called CC=4 SCAR=16.1
106 123 ▶ return $ENV{USERNAME} // '' if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 123 123
Condition0%0/2
$ENV{"USERNAME"} // ""
l!l
00
MC/DC0%0/1
$ENV{"USERNAME"} // ""
$ENV{"USERNAME"}
Truth table0%0/2
A
A= $ENV{"USERNAME"}
Aresult
11
00
107 123 my $name = getpwuid $>;
108 123 ▶ die "A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)\n" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 123 123
109 123 return Encode::decode( 'UTF-8', $name );
110 }
111  
112 3186 ▶sub _git_remote {
Subroutine _git_remote: called CC=5 SCAR=21.6
113 3186 my ( $dir ) = @_;
114 3186 my $r = eval { run_command( cmd => [ 'git', '-C', $dir, 'remote', 'get-url', 'origin' ], env => git_env() ) };
115 3013 ▶ return '' unless $r && !$r->{spawn_error} && defined $r->{code} && $r->{code} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $r and not $r->{"spawn_error"} and defined $r->{"code"} and $r->{"code"} == 0 3013 0 3013
Condition33%3/9
$r and not $r->{"spawn_error"} and defined $r->{"code"} and $r->{"code"} == 0
!ll&&!rl&&r
030130
$r and not $r->{"spawn_error"} and defined $r->{"code"}
!ll&&!rl&&r
003013
$r and not $r->{"spawn_error"}
!ll&&!rl&&r
003013
MC/DC0%0/4
$r and not $r->{"spawn_error"} and defined $r->{"code"} and $r->{"code"} == 0
$r not $r->{"spawn_error"} defined $r->{"code"} $r->{"code"} == 0
Truth table20%1/5
A and not(B) and C and D
A= $rB= not $r->{"spawn_error"}C= defined $r->{"code"}D= $r->{"code"} == 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
116 0 ( my $out = Encode::decode( 'UTF-8', $r->{stdout} ) ) =~ s/\A\s+|\s+\z//g;
117 0 return $out;
118 }
119  
120 379 ▶sub _message {
Subroutine _message: called CC=3 SCAR=11.0
121 379 my ( $err ) = @_;
122 379 ▶ return $err->message if blessed $err && $err->can('message');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($err) and $err->can("message") 338 41 379
Condition66%2/3
builtin::blessed($err) and $err->can("message")
!ll&&!rl&&r
410338
MC/DC50%1/2
builtin::blessed($err) and $err->can("message")
builtin::blessed($err) $err->can("message")
Truth table66%2/3
A and B
A= builtin::blessed($err)B= $err->can("message")
ABresult
0X0
100
111
123 41 return ( "$err" =~ s/ at \S+ line \d+\.?\n?\z//r =~ s/\n\z//r );
124 }
125  
126 # The clock a sync's deadline is compared with: epoch ms, as Date.now().
127 2047 ▶sub _now_ms { int( Time::HiRes::time() * 1000 ) }
Subroutine _now_ms: called CC=1 SCAR=0.0
128  
129 8054 ▶sub _true { JSON::MaybeXS::true() }
Subroutine _true: called CC=1 SCAR=0.0
130 3289 ▶sub _false { JSON::MaybeXS::false() }
Subroutine _false: called CC=1 SCAR=0.0
131  
132 # Do two texts, either one undef (no file), differ?
133 2404 ▶sub _differs {
Subroutine _differs: called CC=3 SCAR=11.1
134 2404 my ( $x, $y ) = @_;
135 2404 ▶ return defined $x ? !defined $y || $x ne $y : defined $y;
Branch: 1 branch
BranchTrueFalseTotal
defined $x ? : 2308 96 2404
Condition66%2/3
not defined $y or $x ne $y
l!l&&r!l&&!r
93401374
MC/DC50%1/2
not defined $y or $x ne $y
not defined $y $x ne $y
Truth table66%2/3
not(A) or B
A= not defined $yB= $x ne $y
ABresult
1X1
011
000
136 }
137  
138 34021 ▶sub _uniq {
Subroutine _uniq: called CC=1 SCAR=0.0
139 34021 my %seen;
140 34021 return grep { !$seen{$_}++ } @_;
141 }
142  
143 #### Paths ###################################################################
144  
145 # path.relative (posix) of two absolute paths.
146 59498 ▶sub _relative {
Subroutine _relative: called CC=4 SCAR=13.9
147 59498 my ( $from, $to ) = @_;
148 59498 my @f = grep { length } split m{/}, path_resolve($from);
149 59498 my @t = grep { length } split m{/}, path_resolve($to);
150 59498 ▶ while ( @f && @t && $f[0] eq $t[0] ) { shift @f; shift @t }
Branch: 1 branch
BranchTrueFalseTotal
if (@f and @t and $f[0] eq $t[0]) 199115 59498 258613
Condition83%5/6
@f and @t and $f[0] eq $t[0]
!ll&&!rl&&r
582651233199115
@f and @t
!ll&&!rl&&r
582650200348
MC/DC66%2/3
@f and @t and $f[0] eq $t[0]
@f @t $f[0] eq $t[0]
Truth table75%3/4
A and B and C
A= @fB= @tC= $f[0] eq $t[0]
ABCresult
0XX0
10X0
1100
1111
151 59498 return join '/', ( map {'..'} @f ), @t;
152 }
153  
154 24189 ▶sub _codex_home_of {
Subroutine _codex_home_of: called CC=3 SCAR=11.0
155 24189 my ( $self ) = @_;
156 24189 my $cx = $self->codex_home;
157 24189 ▶ return ( defined $cx && length $cx ) ? $cx : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $cx && length $cx ? : 22848 1341 24189
Condition66%2/3
defined $cx and length $cx
!ll&&!rl&&r
1341022848
MC/DC50%1/2
defined $cx and length $cx
defined $cx length $cx
Truth table66%2/3
A and B
A= defined $cxB= length $cx
ABresult
0X0
100
111
158 }
159  
160 9078 ▶sub _lock_path { my ( $self, $scope ) = @_; return path_join( $self->_target_dir($scope), 'skilletor.lock.json' ) }
Subroutine _lock_path: called CC=1 SCAR=0.0
161  
162 # Hermes' default home for this machine (`~/.hermes`; `%LOCALAPPDATA%\hermes` on Windows).
163 15625 ▶sub _hermes_default { default_hermes_home( $_[0]->home ) }
Subroutine _hermes_default: called CC=1 SCAR=0.0
164  
165 # The Hermes home the user scope's `hermes:` entries were last synced under (spec §16.2): the
166 # recorded one, else the default. Never dies: a state dir that cannot be read is the default.
167 16146 ▶sub _recorded_hermes_home {
Subroutine _recorded_hermes_home: called CC=2 SCAR=7.0
168 16146 my ( $self ) = @_;
169 16146 my $recorded = eval { Skilletor::State->new( root => $self->state_root )->hermes_home };
170 16146 ▶ return $recorded // $self->_hermes_default;
Condition66%2/3
$recorded // $self->_hermes_default
l!l&&r!l&&!r
807153390
MC/DC0%0/2
$recorded // $self->_hermes_default
$recorded $self->_hermes_default
Truth table66%2/3
A // B
A= $recordedB= $self->_hermes_default
ABresult
1X1
011
000
171 }
172  
173 # The Hermes home this run serves (spec §16.2): `$HERMES_HOME` (L</hermes_home>), else the
174 # recorded one, else Hermes' default. So a run no Hermes started – a Claude Code session – sees
175 # the same home, and with it the same targets and root, as the Hermes session before it.
176 17757 ▶sub _hermes_home_of {
Subroutine _hermes_home_of: called CC=3 SCAR=11.0
177 17757 my ( $self ) = @_;
178 17757 my $given = $self->hermes_home;
179 17757 ▶ return $self->_recorded_hermes_home unless defined $given && length $given;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $given and length $given 12881 4876 17757
Condition100%3/3
defined $given and length $given
!ll&&!rl&&r
1287834876
MC/DC100%2/2
defined $given and length $given
defined $given length $given
Truth table100%3/3
A and B
A= defined $givenB= length $given
ABresult
0X0
100
111
180 4876 return path_resolve( Skilletor::Source::Local->expand_home( $given, $self->home ) );
181 }
182  
183 # Where a scope's roots live (spec §14.2, §16.2).
184 16726 ▶sub _root_context {
Subroutine _root_context: called CC=1 SCAR=0.0
185 16726 my ( $self, $scope ) = @_;
186 return {
187 16726 base => $self->_base_of($scope),
188 scope => $scope,
189 claude_dir => $self->claude_dir,
190 codex_home => $self->_codex_home_of,
191 hermes_home => $self->_hermes_home_of,
192 };
193 }
194  
195 # A path for the commit hint and the tracked warning: relative to the project, `~/…` in the user
196 # scope, absolute outside the scope's base.
197 5684 ▶sub _scope_label {
Subroutine _scope_label: called CC=4 SCAR=14.6
198 5684 my ( $scope, $base, $abs ) = @_;
199 5684 my $rel = _relative( $base, $abs );
200 5684 ▶ return $abs if $rel =~ /\A\.\./ || is_absolute($rel);
Branch: 1 branch
BranchTrueFalseTotal
if $rel =~ /\A\.\./ or is_absolute($rel) 0 5684 5684
Condition33%1/3
$rel =~ /\A\.\./ or is_absolute($rel)
l!l&&r!l&&!r
005684
MC/DC0%0/2
$rel =~ /\A\.\./ or is_absolute($rel)
$rel =~ /\A\.\./ is_absolute($rel)
Truth table33%1/3
A or B
A= $rel =~ /\A\.\./B= is_absolute($rel)
ABresult
1X1
011
000
201 5684 ▶ return $scope eq 'user' ? '~/'.$rel : $rel;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 16 5668 5684
202 }
203  
204 # `s` as one shell word: as is when plain, else single-quoted; a leading `~/` stays unquoted.
205 17 ▶sub _shell_word {
Subroutine _shell_word: called CC=3 SCAR=12.5
206 17 my ( $s ) = @_;
207 17 ▶ return '~/'._shell_word( substr $s, 2 ) if index( $s, '~/' ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($s, "~/") == 0 0 17 17
208 17 ▶ return $s if $s =~ m{\A[\w./@%+=:,-]+\z}a;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ m[\A[\w./\@%+=:,-]+\z]a 17 0 17
209 0 return "'".( $s =~ s/'/'\\''/gr )."'";
210 }
211  
212 #### Loading #################################################################
213  
214 # Config and targets as a sync needs them: no harness is a config error. A user-only operation
215 # passes false so a malformed project lock cannot affect it.
216 7676 ▶sub _load_strict {
Subroutine _load_strict: called CC=8 SCAR=20.8
217 7676 my ( $self, $include_project ) = @_;
218 7676 ▶ $include_project //= 1;
Condition100%2/2
$include_project //= 1
l!l
7147529
MC/DC100%1/1
$include_project //= 1
$include_project
Truth table100%2/2
A
A= $include_project
Aresult
11
00
219 7676 my $config = Skilletor::Config->load( home => $self->home, claude_config_dir => $self->claude_config_dir, project_dir => $self->project_dir_of );
220 7505 my $markers = $self->markers;
221 7505 ▶ my $wanted = { user => $config->user->{targets}, project => $config->project ? $config->project->{targets} : undef };
Branch: 1 branch
BranchTrueFalseTotal
$config->project ? : 7224 281 7505
222 7505 ▶ if ( $include_project && $config->project && !exists $config->project->{targets} && defined $self->project_dir_of ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($include_project and $config->project and not exists $config->project->{"targets"} and defined $self->project_dir_of) 4305 3200 7505
Condition88%8/9
$include_project and $config->project and not exists $config->project->{"targets"} and defined $self->project_dir_of
!ll&&!rl&&r
320004305
$include_project and $config->project and not exists $config->project->{"targets"}
!ll&&!rl&&r
182213784305
$include_project and $config->project
!ll&&!rl&&r
15412815683
MC/DC75%3/4
$include_project and $config->project and not exists $config->project->{"targets"} and defined $self->project_dir_of
$include_project $config->project not exists $config->project->{"targets"} defined $self->project_dir_of
Truth table80%4/5
A and B and not(C) and D
A= $include_projectB= $config->projectC= not exists $config->project->{"targets"}D= defined $self->project_dir_of
ABCDresult
0XXX0
10XX0
110X0
11100
11111
223 4305 my $target_dir = $self->_target_dir('project');
224 4305 my $lock_path = $self->_lock_path('project');
225 4305 my $in_use = grep { -e encode_text($_) } map { path_join( $target_dir, $_ ) } qw( skilletor.json skilletor.local.json skilletor.lock.json );
226 4305 ▶ $wanted->{project_evidence} = detect_project_harnesses( $self->project_dir_of, read_lock($lock_path) ) if $in_use;
Branch: 1 branch
BranchTrueFalseTotal
if $in_use 3164 1141 4305
227 }
228 7505 my $targets = select_targets( $wanted, detect_harnesses($markers), $markers );
229 7410 return ( $config, $targets );
230 }
231  
232 6654 ▶sub _scopes_of {
Subroutine _scopes_of: called CC=7 SCAR=19.5
233 6654 my ( $config, $sel ) = @_;
234 6654 ▶ croak 'scope must be user, project or all' unless $sel =~ /\A(?:user|project|all)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sel =~ /\A(?:user|project|all)\z/ 0 6654 6654
235 6654 my @scopes;
236 6654 ▶ push @scopes, [ user => $config->user ] if $sel eq 'user' || $sel eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $sel eq "user" or $sel eq "all" 4674 1980 6654
Condition100%3/3
$sel eq "user" or $sel eq "all"
l!l&&r!l&&!r
129233821980
MC/DC100%2/2
$sel eq "user" or $sel eq "all"
$sel eq "user" $sel eq "all"
Truth table100%3/3
A or B
A= $sel eq "user"B= $sel eq "all"
ABresult
1X1
011
000
237 6654 ▶ push @scopes, [ project => $config->project ] if ( $sel eq 'project' || $sel eq 'all' ) && $config->project;
Branch: 1 branch
BranchTrueFalseTotal
if $sel eq "project" || $sel eq "all" and $config->project 5121 1533 6654
Condition100%6/6
$sel eq "project" || $sel eq "all" and $config->project
!ll&&!rl&&r
12922415121
$sel eq "project" or $sel eq "all"
l!l&&r!l&&!r
198033821292
MC/DC100%3/3
$sel eq "project" || $sel eq "all" and $config->project
$sel eq "project" $sel eq "all" $config->project
Truth table80%4/5
A or B and C
A= $sel eq "project"B= $sel eq "all"C= $config->project
ABCresult
00X0
1X00
0100
1X11
0111
238 6654 return @scopes;
239 }
240  
241 # For a run Hermes started (spec §16.4): while `hermes` is no machine target – it is never
242 # detected, so until the user config's `targets` names it – the line that says how to opt in,
243 # naming the targets in use plus `hermes`. Undef when Hermes is a target, or when the config or
244 # the targets cannot be read (that error is reported on its own). Never dies.
245 281 ▶sub hermes_opt_in_hint {
Subroutine hermes_opt_in_hint: called CC=3 SCAR=11.0
Pod documented
246 281 my ( $self ) = @_;
247 281 my ( $config, $targets );
248 281 ▶ return undef unless eval { ( $config, $targets ) = $self->_load_strict(0); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { () = $self->_load_strict(0); 1 } } 33 248 281
249 248 my @machine = @{ $targets->{user} };
250 248 ▶ return undef if grep { $_ eq 'hermes' } @machine;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "hermes";} @machine 153 95 248
251 95 my $wanted = join ', ', map {"\"$_\""} @machine, 'hermes';
252 95 return 'Hermes gets no skills: "hermes" is not in "targets"; to opt in, set "targets": ['.$wanted.'] in ~/.claude/skilletor.json';
253 }
254  
255 # The CLAUDE.md files Claude Code reads for a scope (spec §14.8).
256 86 ▶sub _claude_memory_files {
Subroutine _claude_memory_files: called CC=2 SCAR=6.9
257 86 my ( $self, $scope ) = @_;
258 86 ▶ return path_join( $self->claude_dir, 'CLAUDE.md' ) if $scope eq 'user';
Branch: 1 branch
BranchTrueFalseTotal
if $scope eq "user" 34 52 86
259 52 my $base = $self->_base_of($scope);
260 52 return ( path_join( $base, 'CLAUDE.md' ), path_join( $base, '.claude', 'CLAUDE.md' ) );
261 }
262  
263 #### Run notes and warnings (spec §14.8, §16.3) ##############################
264  
265 399 my %HARNESS_LABEL = ( claude => 'Claude Code', codex => 'Codex', hermes => 'Hermes' );
266  
267 # Why a harness has no place for the types it lacks, in a note's words.
268 399 my %NO_COUNTERPART = ( hermes => 'Hermes has no agent files and no rules directory' );
269  
270 # Where a harness reads the copy of another, in a note's words.
271 399 my %SERVED_FROM = ( codex => '.agents/skills' );
272  
273 # The run's notes (spec §16.3) of what an active harness got no copy of ({ harness, type, scope,
274 # via? } each): one line per harness for the types it has no counterpart of, one per harness and
275 # scope for what another harness's copy serves, each with a count per type.
276 3098 ▶sub _run_notes {
Subroutine _run_notes: called CC=8 SCAR=20.8
277 3098 my ( $no_copy ) = @_;
278 3098 my ( %groups, @order );
279 3098 for my $n (@$no_copy) {
280 188 ▶ my $id = defined $n->{via} ? "$n->{harness} $n->{scope} $n->{via}" : $n->{harness};
Branch: 1 branch
BranchTrueFalseTotal
defined $n->{'via'} ? : 61 127 188
281 188 ▶ push @order, $id unless $groups{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $groups{$id} 108 80 188
282 188 ▶ $groups{$id} //= { first => $n, counts => {} };
Condition100%2/2
$groups{$id} //= {"first", $n, "counts", {}}
l!l
80108
MC/DC100%1/1
$groups{$id} //= {"first", $n, "counts", {}}
$groups{$id}
Truth table100%2/2
A
A= $groups{$id}
Aresult
11
00
283 188 $groups{$id}{counts}{ $n->{type} }++;
284 }
285 return map {
286 3098 my ( $first, $counts ) = @{ $groups{$_} }{qw( first counts )};
287 108 my $label = $HARNESS_LABEL{ $first->{harness} };
288 108 my $what = join ' and ', map { $counts->{$_}.' '.$_.'(s)' } grep { $counts->{$_} } qw( skill agent rule );
289 defined $first->{via}
290 ? $what.' not installed for '.$label.' in the '.$first->{scope}.' scope ('.$label.' reads the '.$HARNESS_LABEL{ $first->{via} }
291 .' copy in '.( $SERVED_FROM{ $first->{via} } // 'its own root' ).')'
292 108 ▶ : $what.' not installed for '.$label.' ('.( $NO_COUNTERPART{ $first->{harness} } // $label.' has no counterpart' ).')';
Branch: 1 branch
BranchTrueFalseTotal
defined $first->{'via'} ? : 45 63 108
Condition100%4/4
$SERVED_FROM{$first->{"via"}} // "its own root"
l!l
432
$NO_COUNTERPART{$first->{"harness"}} // $label . ' has no counterpart'
l!l
612
MC/DC100%1/1
$SERVED_FROM{$first->{"via"}} // "its own root"
$SERVED_FROM{$first->{"via"}}
MC/DC100%1/1
$NO_COUNTERPART{$first->{"harness"}} // $label . ' has no counterpart'
$NO_COUNTERPART{$first->{"harness"}}
Truth table100%2/2
A
A= $SERVED_FROM{$first->{"via"}}
Aresult
11
00
Truth table100%2/2
A
A= $NO_COUNTERPART{$first->{"harness"}}
Aresult
11
00
293 } @order;
294 }
295  
296 # Codex skips plugin hooks the user has not trusted, silently (spec §14.8): when Codex is a
297 # machine target and its config.toml has no trusted SessionStart hook for skilletor, one warning.
298 3670 ▶sub _hook_trust_warning {
Subroutine _hook_trust_warning: called CC=4 SCAR=14.0
299 3670 my ( $self, $targets ) = @_;
300 3670 ▶ return undef unless grep { $_ eq 'codex' } @{ $targets->{user} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "codex";} @{$$targets{"user"};} 2162 1508 3670
301 1508 ▶ my $codex_home = $self->_codex_home_of // path_join( $self->home, '.codex' );
Condition33%1/3
$self->_codex_home_of // path_join($self->home, ".codex")
l!l&&r!l&&!r
150800
MC/DC0%0/2
$self->_codex_home_of // path_join($self->home, ".codex")
$self->_codex_home_of path_join($self->home, ".codex")
Truth table33%1/3
A // B
A= $self->_codex_home_ofB= path_join($self->home, ".codex")
ABresult
1X1
011
000
302 1508 ▶ return undef if codex_hook_trusted($codex_home);
Branch: 1 branch
BranchTrueFalseTotal
if codex_hook_trusted($codex_home) 146 1362 1508
303 1362 return q{Codex has not trusted skilletor's SessionStart hook (no trusted_hash for it in }.path_join( $codex_home, 'config.toml' ).'); '
304 .'until you trust it with /hooks in Codex, Codex sessions get no syncs and no rules';
305 }
306  
307 #### Render inputs (spec §5, §14.3, k76) #####################################
308  
309 7007 ▶sub _render_inputs_of {
Subroutine _render_inputs_of: called CC=2 SCAR=6.9
310 7007 my ( $self, $scope, $scope_cfg ) = @_;
311 7007 ▶ return { vars => $scope_cfg->{vars} } unless $scope eq 'project';
Branch: 1 branch
BranchTrueFalseTotal
unless $scope eq "project" 3780 3227 7007
312 3227 my $dir = $self->project_dir_of;
313 3227 ( my $name = $dir ) =~ s{\A.*/}{};
314 3227 return { vars => $scope_cfg->{vars}, project => { dir => $dir, name => $name, git_remote => $self->git_remote->($dir) } };
315 }
316  
317 # The value as JSON with every object's keys sorted: key order in a config file is no change.
318 33169 ▶sub _canonical_json {
Subroutine _canonical_json: called CC=3 SCAR=11.1
319 33169 my ( $v ) = @_;
320 33169 my $type = js_type($v);
321 0 ▶ return '['.join( ',', map { _canonical_json($_) } @$v ).']' if $type eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "array" 0 33169 33169
322 33169 ▶ if ( $type eq 'object' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "object") 16722 16447 33169
323 16722 return '{'.join( ',', map { js_stringify("$_").':'._canonical_json( $v->{$_} ) } js_sort_keys( keys %$v ) ).'}';
324 }
325 16447 return js_stringify($v);
326 }
327  
328 6834 ▶sub _render_inputs_hash {
Subroutine _render_inputs_hash: called CC=1 SCAR=0.0
329 6834 my ( $inputs ) = @_;
330 6834 return hash_bytes( encode_text( _canonical_json( { format => 0 + RENDER_FORMAT, %$inputs } ) ) );
331 }
332  
333 # The template context of one copy (spec §5): the item's vars (source defaults < bundle vars <
334 # the scope's), the project, the scope, the harness and the root it is rendered for, host, user,
335 # the item. Deliberately no env.* and no git branch.
336 485 ▶sub _render_context {
Subroutine _render_context: called CC=2 SCAR=6.9
337 485 my ( $self, $inputs, $scope, $harness, $target_dir, $item, $source_vars, $bundle_vars ) = @_;
338 485 my $p = $inputs->{project};
339 return {
340 vars => Skilletor::Resolver::_item_vars( $source_vars, $bundle_vars, $inputs->{vars} ),
341 project => $p ? js_ordered( dir => $p->{dir}, name => $p->{name}, git_remote => $p->{git_remote} ) : undef,
342 scope => $scope,
343 harness => $harness,
344 target => js_ordered( dir => $target_dir ),
345 host => $self->host,
346 user => $self->user,
347 485 ▶ item => js_ordered( name => $item->{name}, type => $item->{type}, source => $item->{source} ),
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 75 410 485
348 };
349 }
350  
351 13412 ▶sub _scope_sources {
Subroutine _scope_sources: called CC=1 SCAR=0.0
352 13412 my ( $scope_cfg ) = @_;
353 13412 return _uniq( map { $_->{source} } @{ $scope_cfg->{install} }, @{ $scope_cfg->{wildcards} }, @{ $scope_cfg->{bundles} } );
354 }
355  
356 # The sources a scope renders items from: those it declares, and those its lock holds entries of.
357 8834 ▶sub _render_sources {
Subroutine _render_sources: called CC=1 SCAR=0.0
358 8834 my ( $scope_cfg, $lock ) = @_;
359 8834 return _uniq( _scope_sources($scope_cfg), map { $lock->{$_}{source} } keys %$lock );
360 }
361  
362 4137 ▶sub _source_read {
Subroutine _source_read: called CC=3 SCAR=11.3
363 4137 my ( $backend, $version ) = @_;
364 4137 my $read = { kind => $backend->{kind}, address => $backend->{address}, version => $version };
365 4137 ▶ $read->{ref} = $backend->{ref} if defined $backend->{ref};
Branch: 1 branch
BranchTrueFalseTotal
if defined $backend->{"ref"} 0 4137 4137
366 4137 ▶ $read->{path} = $backend->{path} if defined $backend->{path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $backend->{"path"} 0 4137 4137
367 4137 return $read;
368 }
369  
370 811 ▶sub _source_version {
Subroutine _source_version: called CC=4 SCAR=15.2
371 811 my ( $lock, $name ) = @_;
372 811 ▶ for my $e ( values %$lock ) { return $e->{version} if defined $e->{source} && $e->{source} eq $name }
Branch: 1 branch
BranchTrueFalseTotal
if defined $e->{"source"} and $e->{"source"} eq $name 82 0 82
Condition33%1/3
defined $e->{"source"} and $e->{"source"} eq $name
!ll&&!rl&&r
0082
MC/DC0%0/2
defined $e->{"source"} and $e->{"source"} eq $name
defined $e->{"source"} $e->{"source"} eq $name
Truth table33%1/3
A and B
A= defined $e->{"source"}B= $e->{"source"} eq $name
ABresult
0X0
100
111
373 729 return undef;
374 }
375  
376 # The version `check` compares a source with: the one the last sync read through this very
377 # backend (kind, address, ref, path); with no record, the lock's.
378 2285 ▶sub _checked_version {
Subroutine _checked_version: called CC=8 SCAR=25.7
379 2285 my ( $read, $backend, $lock, $name ) = @_;
380 2285 ▶ return _source_version( $lock, $name ) unless $read;
Branch: 1 branch
BranchTrueFalseTotal
unless $read 811 1474 2285
381 my $same = $read->{kind} eq $backend->{kind} && $read->{address} eq $backend->{address}
382 && ( $read->{ref} // "\0" ) eq ( $backend->{ref} // "\0" )
383 1474 ▶ && js_stringify( $read->{path} ) eq js_stringify( $backend->{path} );
Condition38%5/13
$read->{'kind'} eq $backend->{'kind'} && $read->{'address'} eq $backend->{'address'} && ($read->{'ref'} // "\000") eq ($backend->{'ref'} // "\000") && js_stringify($read->{'path'}) eq js_stringify($backend->{'path'})
!ll&&!rl&&r
001474
$read->{"kind"} eq $backend->{"kind"} and $read->{"address"} eq $backend->{"address"} and ($read->{"ref"} // "\0") eq ($backend->{"ref"} // "\0")
!ll&&!rl&&r
001474
$read->{"kind"} eq $backend->{"kind"} and $read->{"address"} eq $backend->{"address"}
!ll&&!rl&&r
001474
$read->{"ref"} // "\0"
l!l
01474
$backend->{"ref"} // "\0"
l!l
01474
MC/DC0%0/4
$read->{'kind'} eq $backend->{'kind'} && $read->{'address'} eq $backend->{'address'} && ($read->{'ref'} // "\000") eq ($backend->{'ref'} // "\000") && js_stringify($read->{'path'}) eq js_stringify($backend->{'path'})
$read->{"kind"} eq $backend->{"kind"} $read->{"address"} eq $backend->{"address"} $read->{"ref"} js_stringify($read->{'path'}) eq js_stringify($backend->{'path'})
MC/DC0%0/1
$backend->{"ref"} // "\0"
$backend->{"ref"}
Truth table0%0/5
A and B and C && D
A= $read->{"kind"} eq $backend->{"kind"}B= $read->{"address"} eq $backend->{"address"}C= $read->{"ref"}D= js_stringify($read->{'path'}) eq js_stringify($backend->{'path'})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table50%1/2
A
A= $backend->{"ref"}
Aresult
11
00
384 1474 ▶ return $same ? $read->{version} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$same ? : 1474 0 1474
385 }
386  
387 #### sync ####################################################################
388  
389 3667 ▶sub sync {
Subroutine sync: called CC=3 SCAR=11.0
Pod documented
390 3667 my ( $self, %opts ) = @_;
391 3667 ▶ my $sel = $opts{scope} // 'all';
Condition100%2/2
$opts{"scope"} // "all"
l!l
16542013
MC/DC100%1/1
$opts{"scope"} // "all"
$opts{"scope"}
Truth table100%2/2
A
A= $opts{"scope"}
Aresult
11
00
392 3667 my $state = Skilletor::State->new( root => $self->state_root, read_once => 1 );
393 my $report = $state->with_lock(
394 3628 ▶ sub {
Subroutine __ANON__: called CC=14 SCAR=26.4
395 3628 Skilletor::Source::Url->sweep_cache( $self->cache_root );
396 3628 Skilletor::Source::Git->sweep_cache( $self->cache_root );
397 # Once the lock is held: another run this one waited for may have left nothing to do.
398 3628 ▶ if ( $opts{if_changed} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"if_changed"}) 376 3252 3628
399 376 my $chk = $self->check( scope => $sel, local => 1 );
400 360 ▶ return js_ordered( scopes => [] ) if !$chk->{changed} && !( defined $chk->{error} && length $chk->{error} ); # an error: the sync reports it
Branch: 1 branch
BranchTrueFalseTotal
unless $chk->{"changed"} or defined $chk->{"error"} and length $chk->{"error"} 123 237 360
Condition83%5/6
$chk->{"changed"} or defined $chk->{"error"} and length $chk->{"error"}
l!l&&r!l&&!r
20532123
defined $chk->{"error"} and length $chk->{"error"}
!ll&&!rl&&r
123032
MC/DC66%2/3
$chk->{"changed"} or defined $chk->{"error"} and length $chk->{"error"}
$chk->{"changed"} defined $chk->{"error"} length $chk->{"error"}
Truth table75%3/4
A or B and C
A= $chk->{"changed"}B= defined $chk->{"error"}C= length $chk->{"error"}
ABCresult
1XX1
0111
00X0
0100
401 }
402 3489 my ( $config, $targets );
403 return js_ordered( scopes => [], error => _message($@) )
404 3489 ▶ unless eval { ( $config, $targets ) = $self->_load_strict( $sel ne 'user' ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { () = $self->_load_strict($sel ne "user"); 1 } } 75 3414 3489
405 3414 my @scopes = _scopes_of( $config, $sel );
406 3414 my $run = {};
407 3414 my $no_copy = []; # what an active harness got no copy of, named once per run
408 3414 my $out = js_ordered( scopes => [] );
409 3414 for my $s (@scopes) {
410 4989 my ( $scope, $scope_cfg ) = @$s;
411 4989 ▶ if ( $scope eq 'project' && $targets->{project_unresolved} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope eq "project" and $targets->{"project_unresolved"}) 4 4985 4989
Condition100%3/3
$scope eq "project" and $targets->{"project_unresolved"}
!ll&&!rl&&r
260923764
MC/DC100%2/2
$scope eq "project" and $targets->{"project_unresolved"}
$scope eq "project" $targets->{"project_unresolved"}
Truth table100%3/3
A and B
A= $scope eq "project"B= $targets->{"project_unresolved"}
ABresult
0X0
100
111
412 4 my $rep = empty_scope_report('project');
413 4 push @{ $rep->{warnings} }, @{ $targets->{warnings} };
414 4 push @{ $out->{scopes} }, $rep;
415 4 next;
416 }
417 4985 my $rep = $self->_sync_scope( $config, $scope_cfg, $scope, $targets->{$scope}, \%opts, $state, $run, $no_copy );
418 # The record lives while Hermes is a target (spec §16.2); its entries went with it.
419 4663 ▶ $state->put_hermes_home(undef) if $scope eq 'user' && !grep { $_ eq 'hermes' } @{ $targets->{user} };
Branch: 1 branch
BranchTrueFalseTotal
if $scope eq "user" and not grep({$_ eq "hermes";} @{$$targets{"user"};}) 2041 2622 4663
Condition100%3/3
$scope eq "user" and not grep({$_ eq "hermes";} @{$$targets{"user"};})
!ll&&!rl&&r
22473752041
MC/DC100%2/2
$scope eq "user" and not grep({$_ eq "hermes";} @{$$targets{"user"};})
$scope eq "user" not grep({$_ eq "hermes";} @{$$targets{"user"};})
Truth table100%3/3
A and not(B)
A= $scope eq "user"B= not grep({$_ eq "hermes";} @{$$targets{"user"};})
ABresult
0X0
100
111
420 4663 ▶ unshift @{ $rep->{warnings} }, @{ $targets->{warnings} } if $scope eq 'project';
Branch: 1 branch
BranchTrueFalseTotal
if $scope eq "project" 2247 2416 4663
421 4663 push @{ $out->{scopes} }, $rep;
422 }
423 3092 my $trust = $self->_hook_trust_warning($targets);
424 3092 ▶ $out->{warnings} = [$trust] if defined $trust;
Branch: 1 branch
BranchTrueFalseTotal
if defined $trust 1004 2088 3092
425 3092 my @notes = _run_notes($no_copy);
426 3092 ▶ $out->{notes} = \@notes if @notes;
Branch: 1 branch
BranchTrueFalseTotal
if @notes 100 2992 3092
427 3092 return $out;
428 },
429 3667 ▶ timeout_ms => $opts{lock_timeout_ms} // $self->lock_timeout_ms,
Condition66%2/3
$opts{"lock_timeout_ms"} // $self->lock_timeout_ms
l!l&&r!l&&!r
4736200
MC/DC0%0/2
$opts{"lock_timeout_ms"} // $self->lock_timeout_ms
$opts{"lock_timeout_ms"} $self->lock_timeout_ms
Truth table66%2/3
A // B
A= $opts{"lock_timeout_ms"}B= $self->lock_timeout_ms
ABresult
1X1
011
000
430 );
431 3290 return $report;
432 }
433  
434 # A sync that stops with an error may have changed the lock (a partial entry): the scope's
435 # records no longer hold and are cleared, so `check` counts everything again.
436 4985 ▶sub _sync_scope {
Subroutine _sync_scope: called CC=2 SCAR=6.9
437 4985 my ( $self, @args ) = @_;
438 4985 my $rep;
439 4985 ▶ return $rep if eval { $rep = $self->_sync_scope_run(@args); 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $rep = $self->_sync_scope_run(@args); 1 } } 4663 116 4779
440 116 my $err = $@;
441 116 my ( $scope, $state ) = @args[ 2, 5 ];
442 116 eval {
443 116 my $lock_path = $self->_lock_path($scope);
444 116 $state->put_unreached( $lock_path, [] );
445 116 $state->put_sources_read( $lock_path, {} );
446 116 $state->put_render_inputs( $lock_path, undef );
447 116 1;
448 };
449 116 die $err;
450 }
451  
452 4985 ▶sub _sync_scope_run {
Subroutine _sync_scope_run: called CC=49 SCAR=39.5
453 4985 my ( $self, $config, $scope_cfg, $scope, $harnesses, $opts, $state, $run, $no_copy ) = @_;
454 4985 my $target_dir = $self->_target_dir($scope);
455 4985 my $base = $self->_base_of($scope);
456 4985 my $rc = $self->_root_context($scope);
457 # Hermes no target: its entries go as an inactive target's, from the home they were synced under.
458 4985 ▶ $rc->{hermes_home} = $self->_recorded_hermes_home if $scope eq 'user' && !grep { $_ eq 'hermes' } @$harnesses;
Branch: 1 branch
BranchTrueFalseTotal
if $scope eq "user" and not grep({$_ eq "hermes";} @$harnesses) 2234 2751 4985
Condition100%3/3
$scope eq "user" and not grep({$_ eq "hermes";} @$harnesses)
!ll&&!rl&&r
23763752234
MC/DC100%2/2
$scope eq "user" and not grep({$_ eq "hermes";} @$harnesses)
$scope eq "user" not grep({$_ eq "hermes";} @$harnesses)
Truth table100%3/3
A and not(B)
A= $scope eq "user"B= not grep({$_ eq "hermes";} @$harnesses)
ABresult
0X0
100
111
459 4985 my $lock_path = path_join( $target_dir, 'skilletor.lock.json' );
460 4985 my @move_warnings;
461 4985 ▶ $self->_move_hermes_home( $state, $target_dir, $rc, $harnesses, \@move_warnings ) if $scope eq 'user';
Branch: 1 branch
BranchTrueFalseTotal
if $scope eq "user" 2609 2376 4985
462 4985 my $old_lock = read_lock($lock_path);
463 4985 ▶ my $gitignore_on = $scope_cfg->{gitignore} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$scope_cfg->{'gitignore'} ? : 4672 313 4985
464 4985 my $inputs;
465 4985 ▶ my $inputs_of = sub { $inputs //= $self->_render_inputs_of( $scope, $scope_cfg ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
$inputs //= $self->_render_inputs_of($scope, $scope_cfg)
l!l&&r!l&&!r
485378094
MC/DC100%2/2
$inputs //= $self->_render_inputs_of($scope, $scope_cfg)
$inputs $self->_render_inputs_of($scope, $scope_cfg)
Truth table100%3/3
A //= B
A= $inputsB= $self->_render_inputs_of($scope, $scope_cfg)
ABresult
1X1
011
000
466  
467 4985 my @plan;
468 # Entries this version cannot place (an unknown harness prefix) are never touched.
469 4985 my @keep = grep { !defined root_of_key( $rc, $_ ) } keys %$old_lock;
470 4985 my %key_info;
471 4985 ▶ my $receivers_of = sub { @{ receivers( $harnesses, $_[0], $scope ) } };
Subroutine __ANON__: called CC=1 SCAR=0.0
472 my $hooks = {
473 223 ▶ keep => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
474 223 my ( $target, $type ) = @_;
475 223 for my $h ( $receivers_of->($type) ) {
476 223 my $key = lock_key( $h, $target );
477 223 ▶ push @keep, $key if exists $old_lock->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $old_lock->{$key} 0 223 223
478 }
479 },
480 4884 ▶ declare => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
481 4884 my ( $item ) = @_;
482 4884 my @targets = $receivers_of->( $item->{type} );
483 4884 for my $h (@$harnesses) {
484 5748 ▶ next if grep { $_ eq $h } @targets;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $h;} @targets 5569 179 5748
485 179 my $via = served_via( $harnesses, $h, $item->{type}, $scope );
486 179 ▶ push @$no_copy, { harness => $h, type => $item->{type}, scope => $scope, ( defined $via ? ( via => $via ) : () ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $via ? : 59 120 179
487 }
488 4884 ▶ return 0 unless @targets;
Branch: 1 branch
BranchTrueFalseTotal
unless @targets 22 4862 4884
489 4862 for my $h (@targets) {
490 5569 my $key = lock_key( $h, $item->{target} );
491 5569 $key_info{$key} = js_ordered( key => $key, type => $item->{type}, name => $item->{name}, source => $item->{source} );
492 }
493 4862 return 1;
494 },
495 4639 ▶ build => sub {
Subroutine __ANON__: called CC=17 SCAR=29.2
496 4639 my ( $item, $extra, $found, $warnings ) = @_;
497 4639 my ( $r, $cat, $ci ) = @{$found}{qw( r cat item )};
498 # Rendered once per target, with that target's harness and root (spec §14.3).
499 4639 for my $h ( $receivers_of->( $item->{type} ) ) {
500 5345 my $key = lock_key( $h, $item->{target} );
501 5345 my ( $output, $executable );
502 5345 my $ok = eval {
503 486 ▶ $output = build( $ci, $r->{dir}, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
504 $self->_render_context( $inputs_of->(), $scope, $h, root_of( $rc, $h, $item->{type} ), $item,
505 486 $cat->{meta}{vars}, $extra->{bundleVars} );
506 5345 } );
507 # A skill's scripts keep their source's executable bit (k99); an agent or rule never.
508 5221 ▶ $executable = $item->{type} eq 'skill' ? executables( $ci, $r->{dir} ) : {};
Branch: 1 branch
BranchTrueFalseTotal
$item->{'type'} eq 'skill' ? : 3260 1961 5221
509 5221 1;
510 };
511 5344 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 123 5221 5344
512 123 ▶ my $where = @$harnesses > 1 ? ' ('.$h.')' : '';
Branch: 1 branch
BranchTrueFalseTotal
@$harnesses > 1 ? : 0 123 123
513 123 push @$warnings, 'template error in '.$item->{type}.' '.$item->{name}.$where.': '._message($@);
514 123 ▶ push @keep, $key if exists $old_lock->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $old_lock->{$key} 123 0 123
515 123 next;
516 }
517 5221 my $p = { key => $key, type => $item->{type}, name => $item->{name}, source => $item->{source}, version => $r->{version} };
518 5221 ▶ $p->{via} = $extra->{via} if $extra->{via} && @{ $extra->{via} };
Branch: 1 branch
BranchTrueFalseTotal
if $extra->{"via"} and @{$extra->{"via"};} 240 4981 5221
Condition66%2/3
$extra->{"via"} and @{$extra->{"via"};}
!ll&&!rl&&r
04981240
MC/DC50%1/2
$extra->{"via"} and @{$extra->{"via"};}
$extra->{"via"} @{$extra->{"via"};}
Truth table66%2/3
A and B
A= $extra->{"via"}B= @{$extra->{"via"};}
ABresult
0X0
100
111
519 5221 ▶ $p->{inBlock} = 1 if is_block_type( $h, $item->{type} );
Branch: 1 branch
BranchTrueFalseTotal
if is_block_type($h, $item->{"type"}) 1154 4067 5221
520 # Main template renders empty: not applicable here (spec §5).
521 5221 ▶ if ( renders_empty( $ci, $output ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (renders_empty($ci, $output)) 41 5180 5221
522 41 $p->{output} = [];
523 41 $p->{skipped} = 'renders-empty';
524 41 push @plan, $p;
525 41 next;
526 }
527 # Per-target output mapping (spec §14.7): a Codex agent becomes TOML, a Codex rule a
528 # section of the rules file. A conversion error leaves the target's copy as it was.
529 5180 my $conv = eval { convert_for_target( $h, $item->{type}, $item->{name}, $output ) };
530 5180 ▶ unless ($conv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conv) 0 5180 5180
531 0 push @$warnings, $item->{type}.' '.$item->{name}.' ('.$h.'): '._message($@);
532 0 ▶ push @keep, $key if exists $old_lock->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $old_lock->{$key} 0 0 0
533 0 next;
534 }
535 0 push @$warnings, map { $item->{type}.' '.$item->{name}.' ('.$h.'): '.$_ } @{ $conv->{warnings} };
536 5180 $p->{output} = $conv->{output};
537 5180 ▶ if ( $conv->{skipped} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conv->{"skipped"}) 0 5180 5180
538 0 $p->{skipped} = 'renders-empty';
539 0 push @plan, $p;
540 0 next;
541 }
542 5180 $output = $p->{output};
543 # Layout names (spec §6.3, §6.4): `.local.` agents and rules claiming their plain path; a
544 # skill carries its own `.gitignore` while the scope's switch is on.
545 5180 my $placed = place_output( $h, $item->{type}, $output );
546 5180 $p->{output} = $placed->{output};
547 5180 ▶ $p->{claims} = $placed->{claims} if @{ $placed->{claims} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$placed->{"claims"};} 766 4414 5180
548 5180 ▶ if ( $item->{type} eq 'skill' && $gitignore_on ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"type"} eq "skill" and $gitignore_on) 2654 2526 5180
Condition100%3/3
$item->{"type"} eq "skill" and $gitignore_on
!ll&&!rl&&r
19206062654
MC/DC100%2/2
$item->{"type"} eq "skill" and $gitignore_on
$item->{"type"} eq "skill" $gitignore_on
Truth table100%3/3
A and B
A= $item->{"type"} eq "skill"B= $gitignore_on
ABresult
0X0
100
111
549 2654 $p->{output} = with_skill_gitignore( $p->{output}, $item->{name} );
550 2654 delete $executable->{ skill_gitignore_path( $item->{name} ) }; # skilletor's own, not the source's
551 }
552 5180 ▶ $p->{executable} = $executable if %$executable;
Branch: 1 branch
BranchTrueFalseTotal
if %$executable 41 5139 5180
553 5180 push @plan, $p;
554 }
555 },
556 4985 };
557  
558 4985 my ( $rep, $info ) = $self->_resolve_scope( $config, $scope_cfg, $scope, $state, $run, $hooks );
559 4883 undef $hooks;
560 # Past its deadline (spec §8): this scope's apply does not begin. Earlier scopes may already
561 # have completed; from here on the scope's remaining work is local.
562 die "sync stopped before applying the $scope scope: its sources took too long\n"
563 4883 ▶ if defined $opts->{deadline} && _now_ms() > $opts->{deadline};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"deadline"} and _now_ms() > $opts->{"deadline"} 49 4834 4883
Condition100%3/3
defined $opts->{"deadline"} and _now_ms() > $opts->{"deadline"}
!ll&&!rl&&r
2771206349
MC/DC100%2/2
defined $opts->{"deadline"} and _now_ms() > $opts->{"deadline"}
defined $opts->{"deadline"} _now_ms() > $opts->{"deadline"}
Truth table100%3/3
A and B
A= defined $opts->{"deadline"}B= _now_ms() > $opts->{"deadline"}
ABresult
0X0
100
111
564 4834 my $out = empty_scope_report($scope);
565 4834 $out->{warnings} = [ @move_warnings, @{ $rep->{warnings} } ];
566 4834 $out->{trustRequests} = $rep->{trustRequests};
567 4834 my $warnings = $out->{warnings};
568 2422 ▶ my $label_of = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
569 2422 my ( $abs ) = @_;
570 2422 my $rel = _relative( $base, $abs );
571 2422 ▶ return ( $rel =~ /\A\.\./ || is_absolute($rel) ) ? $abs : to_posix($rel);
Branch: 1 branch
BranchTrueFalseTotal
$rel =~ /\A\.\./ || is_absolute($rel) ? : 18 2404 2422
Condition66%2/3
$rel =~ /\A\.\./ or is_absolute($rel)
l!l&&r!l&&!r
1802404
MC/DC50%1/2
$rel =~ /\A\.\./ or is_absolute($rel)
$rel =~ /\A\.\./ is_absolute($rel)
Truth table66%2/3
A or B
A= $rel =~ /\A\.\./B= is_absolute($rel)
ABresult
1X1
011
000
572 4834 };
573  
574 my $result = apply(
575 \@plan,
576 target_dir => $target_dir,
577 force => $opts->{force},
578 keep => \@keep,
579 4503 ▶ root_of => sub { root_of_key( $rc, $_[0] ) // $target_dir },
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
root_of_key($rc, $_[0]) // $target_dir
l!l&&r!l&&!r
450300
MC/DC0%0/2
root_of_key($rc, $_[0]) // $target_dir
root_of_key($rc, $_[0]) $target_dir
Truth table33%1/3
A // B
A= root_of_key($rc, $_[0])B= $target_dir
ABresult
1X1
011
000
580 4834 );
581  
582 # Codex rules (spec §14.8): the rules file and the AGENTS.md pointer, from the new lock.
583 4767 ▶ my $rules = ( grep { $_->{block} } values %$old_lock ) || ( grep { $_->{inBlock} } @plan )
Branch: 1 branch
BranchTrueFalseTotal
grep({$_->{'block'};} values %$old_lock) || grep({$_->{'inBlock'};} @plan) || -e encode_text(path_join(root_of($rc, 'codex', 'rule'), 'skilletor-rules.md')) ? : 1202 3565 4767
Condition100%6/6
grep {$_->{"block"};} values %$old_lock or grep {$_->{"inBlock"};} @plan or -e encode_text(path_join(root_of($rc, "codex", "rule"), "skilletor-rules.md"))
l!l&&r!l&&!r
1185173565
grep {$_->{"block"};} values %$old_lock or grep {$_->{"inBlock"};} @plan
l!l&&r!l&&!r
7184673582
MC/DC100%3/3
grep {$_->{"block"};} values %$old_lock or grep {$_->{"inBlock"};} @plan or -e encode_text(path_join(root_of($rc, "codex", "rule"), "skilletor-rules.md"))
grep {$_->{"block"};} values %$old_lock grep {$_->{"inBlock"};} @plan -e encode_text(path_join(root_of($rc, "codex", "rule"), "skilletor-rules.md"))
Truth table100%4/4
A or B or C
A= grep {$_->{"block"};} values %$old_lockB= grep {$_->{"inBlock"};} @planC= -e encode_text(path_join(root_of($rc, "codex", "rule"), "skilletor-rules.md"))
ABCresult
1XX1
01X1
0011
0000
584 || -e encode_text( path_join( root_of( $rc, 'codex', 'rule' ), RULES_FILE ) )
585 ? $self->_sync_codex_rules(
586 scope => $scope, harnesses => $harnesses, rc => $rc, old_lock => $old_lock, plan => \@plan,
587 lock_path => $lock_path, label_of => $label_of, warnings => $warnings,
588 )
589 : { overwritten => [], exists => 0, written => 0 };
590  
591 {
592 # One block of fixed entries per target root (spec §6.4): `.claude/.gitignore` while the
593 # scope is in use; a block found in another root goes. User roots get one only inside a git
594 # work tree.
595 4767 my $new_lock = read_lock($lock_path);
596 4767 ▶ my $in_use = $scope eq 'user' || _project_in_use( $target_dir, $new_lock );
Condition100%3/3
$scope eq 'user' || _project_in_use($target_dir, $new_lock)
l!l&&r!l&&!r
24231850494
MC/DC100%2/2
$scope eq 'user' || _project_in_use($target_dir, $new_lock)
$scope eq 'user' _project_in_use($target_dir, $new_lock)
Truth table100%3/3
A || B
A= $scope eq 'user'B= _project_in_use($target_dir, $new_lock)
ABresult
1X1
011
000
597 4767 my $codex_root = root_of( $rc, 'codex', 'rule' );
598 3116 ▶ my $holds_managed = sub {
Subroutine __ANON__: called CC=5 SCAR=16.5
599 3116 my ( $root ) = @_;
600 return grep {
601 3116 my $e = $new_lock->{$_};
602 3707 ▶ !$e->{block} && %{ $e->{files} // {} } && ( root_of_key( $rc, $_ ) // '' ) eq $root;
Condition70%7/10
!$e->{'block'} && %{$e->{'files'} // {};} && (root_of_key($rc, $_) // '') eq $root
!ll&&!rl&&r
82361015
not $e->{"block"} and %{$e->{"files"} // {};}
!ll&&!rl&&r
0823625
$e->{"files"} // {}
l!l
37070
root_of_key($rc, $_) // ""
l!l
36250
MC/DC33%1/3
!$e->{'block'} && %{$e->{'files'} // {};} && (root_of_key($rc, $_) // '') eq $root
not $e->{"block"} %{$e->{"files"} // {};} root_of_key($rc, $_)
MC/DC0%0/1
$e->{"files"} // {}
$e->{"files"}
Truth table50%2/4
not(A) and B && C
A= not $e->{"block"}B= %{$e->{"files"} // {};}C= root_of_key($rc, $_)
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $e->{"files"}
Aresult
11
00
603 } keys %$new_lock;
604 4767 };
605 4767 for my $root ( all_roots($rc) ) {
606 14295 my @entries;
607 14295 ▶ if ( $in_use && $root eq $target_dir ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($in_use and $root eq $target_dir) { } 4273 10022 14295
elsif ($in_use and $root eq $codex_root and $rules->{'exists'} || &$holds_managed($root)) { } 1169 14605 15774
Condition100%3/3
$in_use and $root eq $target_dir
!ll&&!rl&&r
148285404273
MC/DC100%2/2
$in_use and $root eq $target_dir
$in_use $root eq $target_dir
Truth table100%3/3
A and B
A= $in_useB= $root eq $target_dir
ABresult
0X0
100
111
608 4273 ▶ @entries = $scope eq 'project' ? PROJECT_CLAUDE_ENTRIES : $self->_user_claude_entries($target_dir);
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'project' ? : 1850 2423 4273
609 }
610 ▶ elsif ( $in_use && $root eq $codex_root && ( $rules->{exists} || $holds_managed->($root) ) ) {
Condition100%9/9
$in_use and $root eq $codex_root and $rules->{"exists"} || &$holds_managed($root)
!ll&&!rl&&r
575231011169
$in_use and $root eq $codex_root
!ll&&!rl&&r
148242704270
$rules->{"exists"} or &$holds_managed($root)
l!l&&r!l&&!r
1154153101
MC/DC100%4/4
$in_use and $root eq $codex_root and $rules->{"exists"} || &$holds_managed($root)
$in_use $root eq $codex_root $rules->{"exists"} &$holds_managed($root)
Truth table100%5/5
A and B and C or D
A= $in_useB= $root eq $codex_rootC= $rules->{"exists"}D= &$holds_managed($root)
ABCDresult
0XXX0
10XX0
11000
111X1
11011
611 1169 @entries = CODEX_ENTRIES;
612 }
613 14295 ▶ my $enabled = $gitignore_on && @entries && ( $scope eq 'project' || $self->_in_work_tree($root) );
Condition100%9/9
$gitignore_on && @entries && ($scope eq 'project' || $self->_in_work_tree($root))
!ll&&!rl&&r
916629562173
$gitignore_on and @entries
!ll&&!rl&&r
93982275129
$scope eq "project" or $self->_in_work_tree($root)
l!l&&r!l&&!r
2157162956
MC/DC100%4/4
$gitignore_on && @entries && ($scope eq 'project' || $self->_in_work_tree($root))
$gitignore_on @entries $scope eq "project" $self->_in_work_tree($root)
Truth table100%5/5
A and B && C or D
A= $gitignore_onB= @entriesC= $scope eq "project"D= $self->_in_work_tree($root)
ABCDresult
0XXX0
10XX0
11000
111X1
11011
614 14292 my $change = update_gitignore( dir => $root, entries => \@entries, enabled => $enabled );
615 14292 ▶ push @{ $out->{gitignoreUpdated} }, _scope_label( $scope, $base, path_join( $root, '.gitignore' ) )
Branch: 1 branch
BranchTrueFalseTotal
if $change eq "created" or $change eq "changed" 1145 13147 14292
Condition66%2/3
$change eq "created" or $change eq "changed"
l!l&&r!l&&!r
1145013147
MC/DC50%1/2
$change eq "created" or $change eq "changed"
$change eq "created" $change eq "changed"
Truth table66%2/3
A or B
A= $change eq "created"B= $change eq "changed"
ABresult
1X1
011
000
616 if $change eq 'created' || $change eq 'changed';
617 }
618 # The project's `.worktreeinclude` (spec §6.4, k124), written while the project is in use.
619 4764 ▶ if ( $scope eq 'project' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope eq "project") 2344 2420 4764
620 2344 my $change;
621 2344 ▶ if ( eval { $change = update_worktree_include( dir => $base, entries => [ $self->_worktree_include_entries($rc) ], enabled => $gitignore_on && $in_use ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $change = update_worktree_include('dir', $base, 'entries', [$self->_worktree_include_entries($rc)], 'enabled', $gitignore_on && $in_use); 1 } }) { } 2344 0 2344
Condition100%3/3
$gitignore_on && $in_use
!ll&&!rl&&r
3134941537
MC/DC100%2/2
$gitignore_on && $in_use
$gitignore_on $in_use
Truth table100%3/3
A && B
A= $gitignore_onB= $in_use
ABresult
0X0
100
111
622 2344 ▶ push @{ $out->{gitignoreUpdated} }, _scope_label( $scope, $base, path_join( $base, WORKTREE_INCLUDE ) )
Branch: 1 branch
BranchTrueFalseTotal
if $change eq "created" or $change eq "changed" 865 1479 2344
Condition66%2/3
$change eq "created" or $change eq "changed"
l!l&&r!l&&!r
86501479
MC/DC50%1/2
$change eq "created" or $change eq "changed"
$change eq "created" $change eq "changed"
Truth table66%2/3
A or B
A= $change eq "created"B= $change eq "changed"
ABresult
1X1
011
000
623 if $change eq 'created' || $change eq 'changed';
624 }
625 else {
626 0 push @$warnings, WORKTREE_INCLUDE.' not updated: '._message($@);
627 }
628 }
629 }
630  
631 # The plugin requirement in the committed `.claude/settings.json` (spec §6.8): add-only.
632 4764 my $final_lock = read_lock($lock_path);
633 4764 ▶ if ( my $settings = $self->_claude_settings_plan( $config, $scope, $harnesses, $final_lock ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $settings = $self->_claude_settings_plan($config, $scope, $harnesses, $final_lock)) 945 3819 4764
634 945 my $file = $self->_settings_file;
635 945 my $label = _scope_label( $scope, $base, $file );
636 945 push @$warnings, @{ $settings->{warnings} };
637 945 ▶ $out->{settingsSkipped} = [ @{ $settings->{warnings} } ] if @{ $settings->{warnings} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$settings->{"warnings"};} 147 798 945
638 945 ▶ if ( defined $settings->{next} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $settings->{"next"}) 171 774 945
639 171 ▶ if ( eval { write_text( $file, $settings->{next} ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { write_text($file, $settings->{'next'}); 1 } }) { } 171 0 171
640 171 $out->{settingsUpdated} = js_ordered( path => $label, enabled => $settings->{enabled}, declared => $settings->{declared} );
641 }
642 else {
643 0 push @$warnings, $label.' not updated: '._message($@);
644 }
645 }
646 }
647  
648 # Managed paths git still tracks (spec §6.4): only what this run wrote or adopted.
649 4764 ▶ if ($gitignore_on) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gitignore_on) 4451 313 4764
650 4451 ▶ my @written = map { { root => root_of_key( $rc, $_->{key} ) // $target_dir, key => $_->{key}, path => $_->{path} } } @{ $result->{written} };
Condition33%1/3
root_of_key($rc, $_->{"key"}) // $target_dir
l!l&&r!l&&!r
394900
MC/DC0%0/2
root_of_key($rc, $_->{"key"}) // $target_dir
root_of_key($rc, $_->{"key"}) $target_dir
Truth table33%1/3
A // B
A= root_of_key($rc, $_->{"key"})B= $target_dir
ABresult
1X1
011
000
651 4451 ▶ push @written, { root => root_of( $rc, 'codex', 'rule' ), path => RULES_FILE } if $rules->{written};
Branch: 1 branch
BranchTrueFalseTotal
if $rules->{"written"} 467 3984 4451
652 4451 push @$warnings, $self->_tracked_warnings( $scope, $base, \@written );
653 }
654  
655 5252 ▶ my $to_change = sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
656 5252 my ( $key ) = @_;
657 5252 ▶ return $key_info{$key} if $key_info{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $key_info{$key} 5052 200 5252
658 200 my $t = key_to_type_name($key);
659 200 ▶ return js_ordered( key => $key, type => $t->{type}, name => $t->{name}, source => ( $info->{old_lock}{$key} || {} )->{source} // '?' );
Condition50%2/4
+($info->{"old_lock"}{$key} || {})->{"source"} // "?"
l!l
2000
$info->{'old_lock'}{$key} || {}
l!l
2000
MC/DC0%0/1
+($info->{"old_lock"}{$key} || {})->{"source"} // "?"
$info->{'old_lock'}{$key}
Truth table50%1/2
A
A= $info->{'old_lock'}{$key}
Aresult
11
00
660 4756 };
661 4756 $out->{$_} = [ map { $to_change->($_) } @{ $result->{$_} } ] for qw( added updated removed unchanged skipped );
662 103 ▶ my $shown = sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
663 103 my ( $c ) = @_;
664 103 ▶ my $root = root_of_key( $rc, $c->{key} ) // $target_dir;
Condition33%1/3
root_of_key($rc, $c->{"key"}) // $target_dir
l!l&&r!l&&!r
10300
MC/DC0%0/2
root_of_key($rc, $c->{"key"}) // $target_dir
root_of_key($rc, $c->{"key"}) $target_dir
Truth table33%1/3
A // B
A= root_of_key($rc, $c->{"key"})B= $target_dir
ABresult
1X1
011
000
665 103 ▶ return $root eq $target_dir ? $c->{path} : $label_of->( path_join( $root, $c->{path} ) );
Branch: 1 branch
BranchTrueFalseTotal
$root eq $target_dir ? : 85 18 103
666 4756 };
667 $out->{conflicts} = [
668 map {
669 103 my $c = js_ordered( path => $shown->($_) );
670 103 ▶ $c->{replace} = $_->{replace} if $_->{replace};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"replace"} 0 103 103
671 103 ▶ $c->{notFile} = $_->{notFile} if $_->{notFile};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"notFile"} 0 103 103
672 103 $c;
673 4756 } @{ $result->{conflicts} }
674 ];
675 0 $out->{overwritten} = [ ( map { js_ordered( path => $shown->($_) ) } @{ $result->{overwritten} } ), map { js_ordered( path => $_ ) } @{ $rules->{overwritten} } ];
676 4756 for my $l ( @{ $result->{leftInPlace} } ) {
677 0 push @$warnings, $shown->($l).' is a symbolic link: files of '.$l->{key}.' behind it left in place (never deleted through a link)';
678 }
679  
680 # Briefing check (spec §6.7): every agent the lock holds now, from its installed file.
681 4756 my @briefing = $self->_briefing_of( $scope, $final_lock );
682 4756 push @$warnings, briefing_warning( parse_lock_key( $_->{key} )->{name}, $_->{harness}, $_->{missing} ) for @briefing;
683 4756 ▶ $out->{briefingMissing} = \@briefing if @briefing;
Branch: 1 branch
BranchTrueFalseTotal
if @briefing 3 4753 4756
684  
685 # The records `check` compares with (spec §14.3). A source counts as reached when it was
686 # resolved and scanned: what a sync left in place although it read every source it needed – an
687 # item its source lacks, a lasting conflict, a template error – is not counted again.
688 4756 my %resolved = %{ $info->{resolved} };
689 4756 my %catalogs = %{ $info->{catalogs} };
690 8794 ▶ my $reachable = sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
691 8794 my ( $name ) = @_;
692 8794 ▶ return 0 unless $resolved{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $resolved{$name} 360 8434 8794
693 8434 ▶ return ( exists $catalogs{$name} && !defined $catalogs{$name} ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $catalogs{$name} && !defined($catalogs{$name}) ? : 0 8434 8434
Condition66%2/3
exists $catalogs{$name} and not defined $catalogs{$name}
!ll&&!rl&&r
4483900
MC/DC0%0/2
exists $catalogs{$name} and not defined $catalogs{$name}
exists $catalogs{$name} not defined $catalogs{$name}
Truth table66%2/3
A and not(B)
A= exists $catalogs{$name}B= not defined $catalogs{$name}
ABresult
0X0
100
111
694 4756 };
695 4756 my @drift = $self->_scope_drift( $config, $scope, $harnesses, $final_lock, $info->{served} );
696 4756 $state->put_unreached( $lock_path, [ map { $_->{id} } grep { my $d = $_; !grep { !$reachable->($_) } @{ $d->{sources} } } @drift ] );
697 4756 my $before = $state->sources_read($lock_path);
698 4756 my %read;
699 4756 for my $name ( @{ $info->{resolved_order} } ) {
700 4317 my $r = $resolved{$name};
701 4317 ▶ if ( $r && $reachable->($name) ) { $read{$name} = _source_read( $r->{backend}, $r->{version} ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($r and &$reachable($name)) { } 4137 180 4317
elsif ($before->{$name}) { } 0 180 180
Condition66%2/3
$r and &$reachable($name)
!ll&&!rl&&r
18004137
MC/DC50%1/2
$r and &$reachable($name)
$r &$reachable($name)
Truth table66%2/3
A and B
A= $rB= &$reachable($name)
ABresult
0X0
100
111
702 0 elsif ( $before->{$name} ) { $read{$name} = $before->{$name} }
703 }
704 4756 $state->put_sources_read( $lock_path, \%read );
705 4756 my %untrusted = map { ( $_->{name} => 1 ) } @{ $out->{trustRequests} };
706 4756 ▶ if ( !_render_sources( $scope_cfg, $final_lock ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not _render_sources($scope_cfg, $final_lock)) { } 852 3904 4756
elsif (not grep({not &$reachable($_) || $untrusted{$_};} @{$$info{'resolved_order'};})) { } 3873 31 3904
707 852 $state->put_render_inputs( $lock_path, undef );
708 }
709 4317 ▶ elsif ( !grep { !$reachable->($_) && !$untrusted{$_} } @{ $info->{resolved_order} } ) {
Condition100%3/3
&$reachable($_) || $untrusted{$_}
l!l&&r!l&&!r
413714931
MC/DC100%2/2
&$reachable($_) || $untrusted{$_}
&$reachable($_) $untrusted{$_}
Truth table100%3/3
A || B
A= &$reachable($_)B= $untrusted{$_}
ABresult
1X1
011
000
710 3873 $state->put_render_inputs( $lock_path, _render_inputs_hash( $inputs_of->() ) );
711 }
712 4663 return $out;
713 }
714  
715 # Rebuild a scope's Codex rules file from the new lock, then its AGENTS.md pointer (spec §14.8).
716 # Planned rules take their rendered section; kept ones (source unreachable) their text from the
717 # file – or, for an entry of the first design (#41, keyed `AGENTS.md`), from the old rules block
718 # in AGENTS.md, and the entry is rewritten under the new file name. A pointer refusal is a warning
719 # and touches neither the rules file nor the lock. Returns the overwritten local changes
720 # (`<file>#rules/<name>`), whether the rules file exists now, and whether this run wrote it.
721 1202 ▶sub _sync_codex_rules {
Subroutine _sync_codex_rules: called CC=56 SCAR=47.4
722 1202 my ( $self, %a ) = @_;
723 1202 my ( $scope, $rc, $old_lock, $label_of, $warnings ) = @a{qw( scope rc old_lock label_of warnings )};
724 1202 my $codex_root = root_of( $rc, 'codex', 'rule' );
725 1202 my $rules_file = path_join( $codex_root, RULES_FILE );
726 1202 my $rules_label = $label_of->($rules_file);
727 1202 ▶ my $agents_file = path_join( $scope eq 'user' ? $codex_root : $rc->{base}, 'AGENTS.md' );
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 534 668 1202
728 1202 my $agents_label = $label_of->($agents_file);
729 1202 my $legacy_key = 'AGENTS.md'; # the files key of a first-design entry
730  
731 1202 my $file_text = eval { read_text($rules_file) }; # missing (or unreadable: rewritten below)
732 1202 ▶ my $current = defined $file_text ? parse_rules_file($file_text) : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $file_text ? : 735 467 1202
733 1202 my $agents = inspect_agents_md($agents_file);
734 1202 ▶ my $legacy = $agents->{ok} && $agents->{parsed} ? $agents->{parsed}{sections} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$agents->{'ok'} && $agents->{'parsed'} ? : 718 484 1202
Condition66%2/3
$agents->{"ok"} and $agents->{"parsed"}
!ll&&!rl&&r
0484718
MC/DC50%1/2
$agents->{"ok"} and $agents->{"parsed"}
$agents->{"ok"} $agents->{"parsed"}
Truth table66%2/3
A and B
A= $agents->{"ok"}B= $agents->{"parsed"}
ABresult
0X0
100
111
735 1202 my %planned;
736 1202 ▶ for my $p ( grep { $_->{inBlock} && !$_->{skipped} } @{ $a{plan} } ) {
Condition66%2/3
$_->{'inBlock'} && !$_->{'skipped'}
!ll&&!rl&&r
29101154
MC/DC50%1/2
$_->{'inBlock'} && !$_->{'skipped'}
$_->{'inBlock'} !$_->{'skipped'}
Truth table66%2/3
A && not(B)
A= $_->{'inBlock'}B= !$_->{'skipped'}
ABresult
0X0
100
111
737 1154 my ($pair) = grep { $_->[0] eq RULES_FILE } @{ $p->{output} };
738 1154 $planned{ $p->{key} } = decode_utf8_lossy( $pair->[1] );
739 }
740  
741 1202 my $new_lock = read_lock( $a{lock_path} );
742 1202 my $migrated = 0;
743 1202 my ( %sections, @overwritten );
744 1202 for my $key ( keys %$new_lock ) {
745 1445 my $entry = $new_lock->{$key};
746 1445 ▶ next if !$entry->{block} || $entry->{skipped};
Branch: 1 branch
BranchTrueFalseTotal
if not $entry->{"block"} or $entry->{"skipped"} 291 1154 1445
Condition66%2/3
not $entry->{"block"} or $entry->{"skipped"}
l!l&&r!l&&!r
29101154
MC/DC50%1/2
not $entry->{"block"} or $entry->{"skipped"}
not $entry->{"block"} $entry->{"skipped"}
Truth table66%2/3
not(A) or B
A= not $entry->{"block"}B= $entry->{"skipped"}
ABresult
1X1
011
000
747 1154 my $name = parse_lock_key($key)->{name};
748 1154 my $old = $old_lock->{$key};
749 1154 ▶ my $old_files = $old ? $old->{files} // {} : {};
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 687 467 1154
Condition50%1/2
$old->{"files"} // {}
l!l
6870
MC/DC0%0/1
$old->{"files"} // {}
$old->{"files"}
Truth table50%1/2
A
A= $old->{"files"}
Aresult
11
00
750 1154 ▶ my $prev_hash = $old && !$old->{skipped} ? $old_files->{ RULES_FILE() } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$old && !$old->{'skipped'} ? : 687 467 1154
Condition66%2/3
$old and not $old->{"skipped"}
!ll&&!rl&&r
4670687
MC/DC50%1/2
$old and not $old->{"skipped"}
$old not $old->{"skipped"}
Truth table66%2/3
A and not(B)
A= $oldB= not $old->{"skipped"}
ABresult
0X0
100
111
751 1154 ▶ my $on_disk = $current->{$name} // ( defined $old_files->{$legacy_key} && $legacy ? $legacy->{$name} : undef );
Branch: 1 branch
BranchTrueFalseTotal
defined $old_files->{$legacy_key} && $legacy ? : 0 467 467
Condition50%3/6
$current->{$name} // (defined $old_files->{$legacy_key} && $legacy ? $legacy->{$name} : undef)
l!l&&r!l&&!r
6870467
defined $old_files->{$legacy_key} and $legacy
!ll&&!rl&&r
46700
MC/DC33%1/3
$current->{$name} // (defined $old_files->{$legacy_key} && $legacy ? $legacy->{$name} : undef)
$current->{$name} defined $old_files->{$legacy_key} $legacy
Truth table50%2/4
A // B and C
A= $current->{$name}B= defined $old_files->{$legacy_key}C= $legacy
ABCresult
1XX1
0111
00X0
0100
752 1154 ▶ my $files = $entry->{files} // {};
Condition50%1/2
$entry->{"files"} // {}
l!l
11540
MC/DC0%0/1
$entry->{"files"} // {}
$entry->{"files"}
Truth table50%1/2
A
A= $entry->{"files"}
Aresult
11
00
753 1154 ▶ if ( defined $files->{$legacy_key} && !defined $files->{ RULES_FILE() } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $files->{$legacy_key} and not defined $files->{"skilletor-rules.md"}) 0 1154 1154
Condition33%1/3
defined $files->{$legacy_key} and not defined $files->{"skilletor-rules.md"}
!ll&&!rl&&r
115400
MC/DC0%0/2
defined $files->{$legacy_key} and not defined $files->{"skilletor-rules.md"}
defined $files->{$legacy_key} not defined $files->{"skilletor-rules.md"}
Truth table33%1/3
A and not(B)
A= defined $files->{$legacy_key}B= not defined $files->{"skilletor-rules.md"}
ABresult
0X0
100
111
754 0 $entry->{files} = js_ordered( RULES_FILE() => $files->{$legacy_key} ); # kept first-design entry: same section, new file
755 0 $migrated = 1;
756 }
757 1154 ▶ my $text = $planned{$key} // ( $on_disk ? $on_disk->{text} : undef );
Branch: 1 branch
BranchTrueFalseTotal
$on_disk ? : 0 0 0
Condition33%1/3
$planned{$key} // ($on_disk ? $on_disk->{"text"} : undef)
l!l&&r!l&&!r
115400
MC/DC0%0/2
$planned{$key} // ($on_disk ? $on_disk->{"text"} : undef)
$planned{$key} ($on_disk ? $on_disk->{"text"} : undef)
Truth table33%1/3
A // B
A= $planned{$key}B= ($on_disk ? $on_disk->{"text"} : undef)
ABresult
1X1
011
000
758 1154 ▶ next unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1154 1154
759 # Edited or deleted by hand; a first-design entry (no hash for this file) moves silently.
760 1154 ▶ if ( defined $prev_hash && ( !$on_disk || hash_bytes( encode_text( $on_disk->{text} ) ) ne $prev_hash ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev_hash and !$on_disk || hash_bytes(encode_text($on_disk->{"text"})) ne $prev_hash) 0 1154 1154
Condition50%3/6
defined $prev_hash and !$on_disk || hash_bytes(encode_text($on_disk->{"text"})) ne $prev_hash
!ll&&!rl&&r
4676870
not $on_disk or hash_bytes(encode_text($on_disk->{"text"})) ne $prev_hash
l!l&&r!l&&!r
00687
MC/DC0%0/3
defined $prev_hash and !$on_disk || hash_bytes(encode_text($on_disk->{"text"})) ne $prev_hash
defined $prev_hash not $on_disk hash_bytes(encode_text($on_disk->{"text"})) ne $prev_hash
Truth table50%2/4
A and not(B) or C
A= defined $prev_hashB= not $on_diskC= hash_bytes(encode_text($on_disk->{"text"})) ne $prev_hash
ABCresult
0XX0
1000
11X1
1011
761 0 push @overwritten, $rules_label.'#rules/'.$name;
762 }
763 1154 $sections{$name} = { name => $name, source => $entry->{source}, text => $text };
764 }
765 1202 ▶ write_lock( $a{lock_path}, $new_lock ) if $migrated;
Branch: 1 branch
BranchTrueFalseTotal
if $migrated 0 1202 1202
766 1202 my @sections = map { $sections{$_} } js_sort_keys( keys %sections );
767  
768 1202 my $next = rules_file_text( $scope, \@sections );
769 1202 ▶ my $exists = defined $file_text ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $file_text ? : 735 467 1202
770 1202 my $written = 0;
771 1202 my $ok = eval {
772 1202 ▶ if ( _differs( $next, $file_text ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_differs($next, $file_text)) 515 687 1202
773 515 ▶ if ( defined $next ) { write_text( $rules_file, $next ) }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next) { } 467 48 515
774 48 ▶ else { unlink encode_text($rules_file) or $!{ENOENT} or die node_fs_error( 0 + $!, 'rm', $rules_file )."\n" }
Branch: 1 branch
BranchTrueFalseTotal
unlink encode_text($rules_file) or $!{"ENOENT"} or die node_fs_error(0 + $!, "rm", $rules_file) . "\n" 48 0 48
Condition33%1/3
unlink encode_text($rules_file) or $!{"ENOENT"}
l!l&&r!l&&!r
4800
MC/DC0%0/2
unlink encode_text($rules_file) or $!{"ENOENT"}
unlink encode_text($rules_file) $!{"ENOENT"}
Truth table33%1/3
A or B
A= unlink encode_text($rules_file)B= $!{"ENOENT"}
ABresult
1X1
011
000
775 515 ▶ $written = defined $next ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $next ? : 467 48 515
776 }
777 1202 ▶ $exists = defined $next ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $next ? : 1154 48 1202
778 1202 1;
779 };
780 1202 ▶ push @$warnings, $rules_label.': cannot write the Codex rules file ('._message($@).')' unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1202 1202
781  
782 # The pointer: present exactly when the rules file is.
783 1202 my $want = $exists;
784 1202 my $state = $agents;
785 # Claude Code reads CLAUDE.md: when that is this AGENTS.md, Claude would be sent to the Codex rules.
786 1240 my ($memory) = $want && grep( { $_ eq 'claude' } @{ $a{harnesses} } )
787 1202 ▶ ? grep { same_file( $_, $agents_file ) } $self->_claude_memory_files($scope)
Branch: 1 branch
BranchTrueFalseTotal
$want && grep({$_ eq 'claude';} @{$a{'harnesses'};}) ? : 86 1116 1202
Condition100%3/3
$want and grep {$_ eq "claude";} @{$a{"harnesses"};}
!ll&&!rl&&r
48106886
MC/DC100%2/2
$want and grep {$_ eq "claude";} @{$a{"harnesses"};}
$want grep {$_ eq "claude";} @{$a{"harnesses"};}
Truth table100%3/3
A and B
A= $wantB= grep {$_ eq "claude";} @{$a{"harnesses"};}
ABresult
0X0
100
111
788 : ();
789 1202 ▶ $state = { ok => 0, reason => 'is the same file as '.$label_of->($memory).' (Claude Code would read it)' } if $state->{ok} && defined $memory;
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"ok"} and defined $memory 0 1202 1202
Condition33%1/3
$state->{"ok"} and defined $memory
!ll&&!rl&&r
012020
MC/DC0%0/2
$state->{"ok"} and defined $memory
$state->{"ok"} defined $memory
Truth table33%1/3
A and B
A= $state->{"ok"}B= defined $memory
ABresult
0X0
100
111
790 1202 ▶ unless ( $state->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"ok"}) 0 1202 1202
791 0 my $why = $state->{reason};
792 0 ▶ if ( $want || index( $why, 'malformed' ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want or index($why, "malformed") == 0) 0 0 0
Condition0%0/3
$want or index($why, "malformed") == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$want or index($why, "malformed") == 0
$want index($why, "malformed") == 0
Truth table0%0/3
A or B
A= $wantB= index($why, "malformed") == 0
ABresult
1X1
011
000
793 0 ▶ push @$warnings, $agents_label.( index( $why, 'is ' ) == 0 ? ' ' : ': ' ).$why.'; pointer to the Codex rules not written';
Branch: 1 branch
BranchTrueFalseTotal
index($why, 'is ') == 0 ? : 0 0 0
794 }
795 0 return { overwritten => \@overwritten, exists => $exists, written => $written };
796 }
797 1202 ▶ my $shown_rules = $scope eq 'user' ? $rules_file : '.codex/'.RULES_FILE;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 534 668 1202
798 1202 ▶ my $agents_next = with_block( $state->{text}, $want ? [ pointer_lines( $scope, $shown_rules ) ] : undef );
Branch: 1 branch
BranchTrueFalseTotal
$want ? : 1154 48 1202
799 1202 ▶ if ( _differs( $agents_next, $state->{text} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_differs($agents_next, $state->{"text"})) 498 704 1202
800 498 ▶ if ( defined $agents_next ) { write_text( $agents_file, $agents_next ) }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $agents_next) { } 467 31 498
801 31 ▶ else { unlink encode_text($agents_file) or $!{ENOENT} or die node_fs_error( 0 + $!, 'rm', $agents_file )."\n" }
Branch: 1 branch
BranchTrueFalseTotal
unlink encode_text($agents_file) or $!{"ENOENT"} or die node_fs_error(0 + $!, "rm", $agents_file) . "\n" 31 0 31
Condition33%1/3
unlink encode_text($agents_file) or $!{"ENOENT"}
l!l&&r!l&&!r
3100
MC/DC0%0/2
unlink encode_text($agents_file) or $!{"ENOENT"}
unlink encode_text($agents_file) $!{"ENOENT"}
Truth table33%1/3
A or B
A= unlink encode_text($agents_file)B= $!{"ENOENT"}
ABresult
1X1
011
000
802 }
803 1202 ▶ if ($want) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want) 1154 48 1202
804 1154 ▶ my $override = path_join( $scope eq 'user' ? $codex_root : $rc->{base}, 'AGENTS.override.md' );
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 534 620 1154
805 1154 ▶ if ( -e encode_text($override) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e encode_text($override)) 0 1154 1154
806 0 push @$warnings, $label_of->($override).' exists; Codex reads it instead of AGENTS.md, so the pointer to the skilletor rules is not seen';
807 }
808 1154 ▶ if ( $scope eq 'project' && defined $agents_next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope eq "project" and defined $agents_next) 620 534 1154
Condition66%2/3
$scope eq "project" and defined $agents_next
!ll&&!rl&&r
5340620
MC/DC50%1/2
$scope eq "project" and defined $agents_next
$scope eq "project" defined $agents_next
Truth table66%2/3
A and B
A= $scope eq "project"B= defined $agents_next
ABresult
0X0
100
111
809 620 ▶ my $limit = project_doc_limit( $self->_codex_home_of // path_join( $self->home, '.codex' ) );
Condition33%1/3
$self->_codex_home_of // path_join($self->home, ".codex")
l!l&&r!l&&!r
62000
MC/DC0%0/2
$self->_codex_home_of // path_join($self->home, ".codex")
$self->_codex_home_of path_join($self->home, ".codex")
Truth table33%1/3
A // B
A= $self->_codex_home_ofB= path_join($self->home, ".codex")
ABresult
1X1
011
000
810 620 my $bytes = length encode_text($agents_next);
811 620 ▶ if ( $bytes > $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes > $limit) 0 620 620
812 0 push @$warnings, $agents_label.' is '.$bytes.' bytes; Codex reads at most '.$limit.' bytes of project instructions '
813 .'(project_doc_max_bytes), so the pointer to the rules at its end may be cut off';
814 }
815 }
816 }
817 1202 return { overwritten => \@overwritten, exists => $exists, written => $written };
818 }
819  
820 2972 ▶sub _in_work_tree {
Subroutine _in_work_tree: called CC=2 SCAR=6.9
821 2972 my ( $self, $dir ) = @_;
822 2972 my $yes = eval { $self->is_git_work_tree->($dir) };
823 2969 ▶ return $yes ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$yes ? : 16 2953 2969
824 }
825  
826 # Entries of the user `~/.claude` block: the lock, the state dir when it lies under `~/.claude`,
827 # the agent and rule patterns. Never `skilletor.json`.
828 2423 ▶sub _user_claude_entries {
Subroutine _user_claude_entries: called CC=4 SCAR=14.0
829 2423 my ( $self, $claude_dir ) = @_;
830 2423 my $rel = _relative( $claude_dir, $self->state_root );
831 2423 ▶ my $under = length $rel && $rel !~ /\A\.\./ && !is_absolute($rel);
Condition66%4/6
length $rel && !($rel =~ /\A\.\./) && !is_absolute($rel)
!ll&&!rl&&r
121501208
length $rel and not $rel =~ /\A\.\./
!ll&&!rl&&r
012151208
MC/DC33%1/3
length $rel && !($rel =~ /\A\.\./) && !is_absolute($rel)
length $rel not $rel =~ /\A\.\./ !is_absolute($rel)
Truth table50%2/4
A and not(B) && not(C)
A= length $relB= not $rel =~ /\A\.\./C= !is_absolute($rel)
ABCresult
0XX0
10X0
1100
1111
832 2423 ▶ return ( 'skilletor.lock.json', ( $under ? $rel.'/' : () ), LOCAL_ENTRIES );
Branch: 1 branch
BranchTrueFalseTotal
$under ? : 1208 1215 2423
833 }
834  
835 # Is the project scope in use: a project config file, or lock entries?
836 6888 ▶sub _project_in_use {
Subroutine _project_in_use: called CC=3 SCAR=11.0
837 6888 my ( $target_dir, $lock ) = @_;
838 6888 ▶ return 1 if %$lock;
Branch: 1 branch
BranchTrueFalseTotal
if %$lock 3945 2943 6888
839 2943 ▶ return ( grep { -e encode_text( path_join( $target_dir, $_ ) ) } qw( skilletor.json skilletor.local.json ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({-e encode_text(path_join($target_dir, $_));} 'skilletor.json', 'skilletor.local.json') ? : 1529 1414 2943
840 }
841  
842 # The `.worktreeinclude` block of a project (k124): every project root a harness's items go to,
843 # whether or not this machine targets it, the lock and the local config – fixed, sorted.
844 5441 ▶sub _worktree_include_entries {
Subroutine _worktree_include_entries: called CC=7 SCAR=19.5
845 5441 my ( $self, $rc ) = @_;
846 5441 ▶ my $at = sub { '/'.to_posix( _relative( $rc->{base}, $_[0] ) ).( $_[1] // '' ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_[1] // ""
l!l
3264616323
MC/DC100%1/1
$_[1] // ""
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
847 5441 my $claude = path_join( $rc->{base}, '.claude' );
848 5441 my @out = ( $at->( path_join( $claude, 'skilletor.lock.json' ) ), $at->( path_join( $claude, 'skilletor.local.json' ) ) );
849 5441 for my $h (HARNESSES) {
850 16323 for my $type (ITEM_TYPES) {
851 48969 ▶ my $root = root_of( $rc, $h, $type ) // next;
Condition100%2/2
root_of($rc, $h, $type) // (next)
l!l
3808710882
MC/DC100%1/1
root_of($rc, $h, $type) // (next)
root_of($rc, $h, $type)
Truth table100%2/2
A
A= root_of($rc, $h, $type)
Aresult
11
00
852 38087 ▶ if ( is_block_type( $h, $type ) ) { push @out, $at->( path_join( $root, RULES_FILE ) ) }
Branch: 3 branches
BranchTrueFalseTotal
if (is_block_type($h, $type)) { } 5441 32646 38087
elsif ($type eq 'skill') { } 16323 16323 32646
elsif (is_local_type($h, $type)) { } 16323 0 16323
853 16323 elsif ( $type eq 'skill' ) { push @out, $at->( path_join( $root, 'skills' ), '/' ) }
854 16323 elsif ( is_local_type( $h, $type ) ) { push @out, $at->( path_join( $root, $type.'s' ), '/**/.local.*' ) }
855 }
856 }
857 5441 return js_sort_keys( _uniq(@out) );
858 }
859  
860 3640 ▶sub _settings_file { my ( $self ) = @_; return path_join( $self->_target_dir('project'), 'settings.json' ) }
Subroutine _settings_file: called CC=1 SCAR=0.0
861  
862 # What a sync adds to the project's `.claude/settings.json` (spec §6.8), or undef when the file is
863 # not skilletor's to touch. A proposed write must preserve implicit targets. $lock owns the files
864 # currently on disk (the new lock after apply, not the pre-sync lock). Never throws.
865 13598 ▶sub _claude_settings_plan {
Subroutine _claude_settings_plan: called CC=13 SCAR=25.9
866 13598 my ( $self, $config, $scope, $harnesses, $lock ) = @_;
867 13598 ▶ return undef unless $scope eq 'project';
Branch: 1 branch
BranchTrueFalseTotal
unless $scope eq "project" 6710 6888 13598
868 6888 my $scope_cfg = $config->project;
869 6888 ▶ return undef if js_type( $scope_cfg->{claudeSettings} ) eq 'boolean' && !$scope_cfg->{claudeSettings};
Branch: 1 branch
BranchTrueFalseTotal
if js_type($scope_cfg->{"claudeSettings"}) eq "boolean" and not $scope_cfg->{"claudeSettings"} 0 6888 6888
Condition33%1/3
js_type($scope_cfg->{"claudeSettings"}) eq "boolean" and not $scope_cfg->{"claudeSettings"}
!ll&&!rl&&r
068880
MC/DC0%0/2
js_type($scope_cfg->{"claudeSettings"}) eq "boolean" and not $scope_cfg->{"claudeSettings"}
js_type($scope_cfg->{"claudeSettings"}) eq "boolean" not $scope_cfg->{"claudeSettings"}
Truth table33%1/3
A and not(B)
A= js_type($scope_cfg->{"claudeSettings"}) eq "boolean"B= not $scope_cfg->{"claudeSettings"}
ABresult
0X0
100
111
870 6888 ▶ return undef unless grep { $_ eq 'claude' } @$harnesses;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "claude";} @$harnesses 2999 3889 6888
871 3889 ▶ return undef unless -e encode_text( path_join( $self->_target_dir($scope), 'skilletor.json' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless -e encode_text(path_join($self->_target_dir($scope), "skilletor.json")) 1194 2695 3889
872 2695 my $file = $self->_settings_file;
873 2695 my $label = _scope_label( $scope, $self->project_dir_of, $file );
874 2695 my $plan = eval {
875 2695 ▶ my $proposed = plan_claude_settings(
Branch: 1 branch
BranchTrueFalseTotal
defined $self->plugin_root && length $self->plugin_root ? : 0 2695 2695
Condition66%2/3
defined $self->plugin_root and length $self->plugin_root
!ll&&!rl&&r
149312020
MC/DC0%0/2
defined $self->plugin_root and length $self->plugin_root
defined $self->plugin_root length $self->plugin_root
Truth table66%2/3
A and B
A= defined $self->plugin_rootB= length $self->plugin_root
ABresult
0X0
100
111
876 file => $file, label => $label, project_dir => $self->project_dir_of,
877 claude_dir => $self->claude_dir,
878 plugin_root => ( defined $self->plugin_root && length $self->plugin_root ) ? $self->plugin_root : undef,
879 );
880 2695 ▶ if ( defined $proposed->{next} && !exists $scope_cfg->{targets} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proposed->{"next"} and not exists $scope_cfg->{"targets"}) 556 2139 2695
Condition100%3/3
defined $proposed->{"next"} and not exists $scope_cfg->{"targets"}
!ll&&!rl&&r
1972167556
MC/DC100%2/2
defined $proposed->{"next"} and not exists $scope_cfg->{"targets"}
defined $proposed->{"next"} not exists $scope_cfg->{"targets"}
Truth table100%3/3
A and not(B)
A= defined $proposed->{"next"}B= not exists $scope_cfg->{"targets"}
ABresult
0X0
100
111
881 my $projected = select_targets(
882 556 { user => $config->user->{targets}, project_evidence => detect_project_harnesses( $self->project_dir_of, $lock, $proposed->{next} ) },
883 detect_harnesses( $self->markers ),
884 );
885 556 ▶ if ( $projected->{project_unresolved} || join( ',', @{ $projected->{project} } ) ne join( ',', @$harnesses ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($projected->{"project_unresolved"} or join(",", @{$projected->{"project"};}) ne join(",", @$harnesses)) 491 65 556
Condition100%3/3
$projected->{"project_unresolved"} or join(",", @{$projected->{"project"};}) ne join(",", @$harnesses)
l!l&&r!l&&!r
1647565
MC/DC100%2/2
$projected->{"project_unresolved"} or join(",", @{$projected->{"project"};}) ne join(",", @$harnesses)
$projected->{"project_unresolved"} join(",", @{$projected->{"project"};}) ne join(",", @$harnesses)
Truth table100%3/3
A or B
A= $projected->{"project_unresolved"}B= join(",", @{$projected->{"project"};}) ne join(",", @$harnesses)
ABresult
1X1
011
000
886 491 $proposed = { enabled => [], declared => [], warnings => [ @{ $proposed->{warnings} },
887 $label.' not updated: the plugin requirement would change implicitly selected project targets; '
888 .'set "targets" in the project\'s .claude/skilletor.json or .claude/skilletor.local.json, then sync',
889 ] };
890 }
891 }
892 2695 $proposed;
893 };
894 2695 ▶ return $plan // { enabled => [], declared => [], warnings => [ $label.' not updated: '._message($@) ] };
Condition50%1/2
$plan // {"enabled", [], "declared", [], "warnings", [$label . ' not updated: ' . _message($@)]}
l!l
26950
MC/DC0%0/1
$plan // {"enabled", [], "declared", [], "warnings", [$label . ' not updated: ' . _message($@)]}
$plan
Truth table50%1/2
A
A= $plan
Aresult
11
00
895 }
896  
897 # The tracked-file warnings (spec §6.4): of the written and adopted paths, the ones git tracks –
898 # one warning per item with the command that untracks it.
899 4451 ▶sub _tracked_warnings {
Subroutine _tracked_warnings: called CC=17 SCAR=30.1
900 4451 my ( $self, $scope, $base, $written ) = @_;
901 4451 my ( %by_root, @roots );
902 4451 for my $w (@$written) {
903 4416 ▶ push @roots, $w->{root} unless $by_root{ $w->{root} };
Branch: 1 branch
BranchTrueFalseTotal
unless $by_root{$w->{"root"}} 2335 2081 4416
904 4416 push @{ $by_root{ $w->{root} } }, $w;
905 }
906 4451 my @out;
907 4451 for my $root (@roots) {
908 2335 my $list = $by_root{$root};
909 2335 ▶ my $tracked = eval { $self->git_tracked->( $root, [ _uniq( map { $_->{path} } @$list ) ] ) } or next;
Branch: 1 branch
BranchTrueFalseTotal
my $tracked = eval { do { $self->git_tracked->($root, [_uniq(map({$_->{"path"};} @$list))]) } } or next 2327 0 2327
910 2327 my %tracked = map { ( $_ => 1 ) } @$tracked;
911 2327 my ( %items, @ids );
912 2327 for my $w (@$list) {
913 4398 ▶ next unless $tracked{ $w->{path} };
Branch: 1 branch
BranchTrueFalseTotal
unless $tracked{$w->{"path"}} 4381 17 4398
914 17 ▶ my $id = $w->{key} // $w->{path};
Condition33%1/3
$w->{"key"} // $w->{"path"}
l!l&&r!l&&!r
0170
MC/DC0%0/2
$w->{"key"} // $w->{"path"}
$w->{"key"} $w->{"path"}
Truth table33%1/3
A // B
A= $w->{"key"}B= $w->{"path"}
ABresult
1X1
011
000
915 17 ▶ push @ids, $id unless $items{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $items{$id} 17 0 17
916 17 ▶ $items{$id} //= { key => $w->{key}, paths => [] };
Condition50%1/2
$items{$id} //= {"key", $w->{"key"}, "paths", []}
l!l
017
MC/DC0%0/1
$items{$id} //= {"key", $w->{"key"}, "paths", []}
$items{$id}
Truth table50%1/2
A
A= $items{$id}
Aresult
11
00
917 17 push @{ $items{$id}{paths} }, $w->{path};
918 }
919 2327 for my $id (@ids) {
920 17 my ( $key, $paths ) = @{ $items{$id} }{qw( key paths )};
921 17 ▶ my $k = defined $key ? parse_lock_key($key) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 0 17 17
922 17 ▶ my $skill = $k && $k->{type} eq 'skill';
Condition33%1/3
$k && $k->{'type'} eq 'skill'
!ll&&!rl&&r
1700
MC/DC0%0/2
$k && $k->{'type'} eq 'skill'
$k $k->{'type'} eq 'skill'
Truth table33%1/3
A && B
A= $kB= $k->{'type'} eq 'skill'
ABresult
0X0
100
111
923 17 ▶ my @targets = $skill ? ( $k->{target} ) : @$paths;
Branch: 1 branch
BranchTrueFalseTotal
$skill ? : 0 17 17
924 17 ▶ my $r = $skill ? ' -r' : '';
Branch: 1 branch
BranchTrueFalseTotal
$skill ? : 0 17 17
925 my $cmd = $scope eq 'project'
926 17 ? 'git rm'.$r.' --cached '.join( ' ', map { _shell_word( _scope_label( $scope, $base, path_join( $root, $_ ) ) ) } @targets )
927 0 ▶ : 'git -C '._shell_word( _scope_label( $scope, $base, $root ) ).' rm'.$r.' --cached '.join( ' ', map { _shell_word($_) } @targets );
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'project' ? : 17 0 17
928 17 ▶ my $label = $key // _scope_label( $scope, $base, path_join( $root, $paths->[0] ) );
Condition33%1/3
$key // _scope_label($scope, $base, path_join($root, $paths->[0]))
l!l&&r!l&&!r
0170
MC/DC0%0/2
$key // _scope_label($scope, $base, path_join($root, $paths->[0]))
$key _scope_label($scope, $base, path_join($root, $paths->[0]))
Truth table33%1/3
A // B
A= $keyB= _scope_label($scope, $base, path_join($root, $paths->[0]))
ABresult
1X1
011
000
929 17 push @out, $label.' is tracked by git although skilletor manages it — untrack it: '.$cmd;
930 }
931 }
932 4443 return @out;
933 }
934  
935 # Installed agents of a scope's lock whose declared briefing skills do not resolve (spec §6.7).
936 5335 ▶sub _briefing_of {
Subroutine _briefing_of: called CC=15 SCAR=28.2
937 5335 my ( $self, $scope, $lock, $only ) = @_;
938 5335 my $rc = $self->_root_context($scope);
939 5335 ▶ my $roots = { home => $self->home, claude_dir => $self->claude_dir, codex_home => $self->_codex_home_of, project_dir => $scope eq 'project' ? $self->project_dir_of : undef };
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'project' ? : 2728 2607 5335
940 5335 my ( %roots_of, @out );
941 5335 for my $key ( keys %$lock ) {
942 5792 my $entry = $lock->{$key};
943 5792 my $k = parse_lock_key($key);
944 5792 ▶ next if !defined $k->{harness} || $k->{type} ne 'agent' || $entry->{skipped} || $entry->{block} || ( $only && !$only->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $k->{"harness"} or $k->{"type"} ne "agent" or $entry->{"skipped"} or $entry->{"block"} or $only and not $only->{$key} 5490 302 5792
Condition73%11/15
not defined $k->{"harness"} or $k->{"type"} ne "agent" or $entry->{"skipped"} or $entry->{"block"} or $only and not $only->{$key}
l!l&&r!l&&!r
54900302
not defined $k->{"harness"} or $k->{"type"} ne "agent" or $entry->{"skipped"} or $entry->{"block"}
l!l&&r!l&&!r
54900302
not defined $k->{"harness"} or $k->{"type"} ne "agent" or $entry->{"skipped"}
l!l&&r!l&&!r
54900302
not defined $k->{"harness"} or $k->{"type"} ne "agent"
l!l&&r!l&&!r
415449302
$only and not $only->{$key}
!ll&&!rl&&r
231710
MC/DC33%2/6
not defined $k->{"harness"} or $k->{"type"} ne "agent" or $entry->{"skipped"} or $entry->{"block"} or $only and not $only->{$key}
not defined $k->{"harness"} $k->{"type"} ne "agent" $entry->{"skipped"} $entry->{"block"} $only not $only->{$key}
Truth table57%4/7
not(A) or B or C or D or E and not(F)
A= not defined $k->{"harness"}B= $k->{"type"} ne "agent"C= $entry->{"skipped"}D= $entry->{"block"}E= $onlyF= not $only->{$key}
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
0000111
00000X0
0000100
945 302 my $root = root_of_key( $rc, $key );
946 302 ▶ my ($file) = keys %{ $entry->{files} // {} };
Condition50%1/2
$entry->{"files"} // {}
l!l
3020
MC/DC0%0/1
$entry->{"files"} // {}
$entry->{"files"}
Truth table50%1/2
A
A= $entry->{"files"}
Aresult
11
00
947 302 ▶ next unless defined $root && defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root and defined $file 0 302 302
Condition33%1/3
defined $root and defined $file
!ll&&!rl&&r
00302
MC/DC0%0/2
defined $root and defined $file
defined $root defined $file
Truth table33%1/3
A and B
A= defined $rootB= defined $file
ABresult
0X0
100
111
948 302 ▶ $roots_of{ $k->{harness} } //= skill_roots( $k->{harness}, $scope, $roots );
Condition66%2/3
$roots_of{$k->{"harness"}} //= skill_roots($k->{"harness"}, $scope, $roots)
l!l&&r!l&&!r
452570
MC/DC0%0/2
$roots_of{$k->{"harness"}} //= skill_roots($k->{"harness"}, $scope, $roots)
$roots_of{$k->{"harness"}} skill_roots($k->{"harness"}, $scope, $roots)
Truth table66%2/3
A //= B
A= $roots_of{$k->{"harness"}}B= skill_roots($k->{"harness"}, $scope, $roots)
ABresult
1X1
011
000
949 302 my $missing = missing_skills( $k->{harness}, path_join( $root, $file ), $roots_of{ $k->{harness} } );
950 302 ▶ push @out, js_ordered( key => $key, harness => $k->{harness}, missing => $missing ) if $missing && @$missing;
Branch: 1 branch
BranchTrueFalseTotal
if $missing and @$missing 5 297 302
Condition66%2/3
$missing and @$missing
!ll&&!rl&&r
02975
MC/DC50%1/2
$missing and @$missing
$missing @$missing
Truth table66%2/3
A and B
A= $missingB= @$missing
ABresult
0X0
100
111
951 }
952 5335 return @out;
953 }
954  
955 #### Drift (spec §14.3) ######################################################
956  
957 399 my $SKILL_GITIGNORE_HASH = hash_bytes( encode_text(SKILL_GITIGNORE) );
958  
959 # Every drift of a scope: targets, layout, declarations, each { kind, id, sources }.
960 8834 ▶sub _scope_drift {
Subroutine _scope_drift: called CC=10 SCAR=23.0
961 8834 my ( $self, $config, $scope, $harnesses, $lock, $served_by ) = @_;
962 8834 ▶ my $scope_cfg = $scope eq 'project' ? $config->project : $config->user;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'project' ? : 4544 4290 8834
963 8834 my @out;
964 8834 for my $g ( @{ target_gaps( [ keys %$lock ], $harnesses, $scope ) } ) {
965 149 my $source = $lock->{ $g->{key} }{source};
966 push @out, defined $g->{missing}
967 ? { kind => 'targets', id => 'missing:'.$g->{missing}.'@'.( $source // 'undefined' ), sources => [$source] }
968 149 ▶ : { kind => 'targets', id => 'orphan:'.$g->{key}, sources => [] };
Branch: 1 branch
BranchTrueFalseTotal
defined $g->{'missing'} ? : 63 86 149
Condition50%1/2
$source // "undefined"
l!l
630
MC/DC0%0/1
$source // "undefined"
$source
Truth table50%1/2
A
A= $source
Aresult
11
00
969 }
970 # The run's Hermes home is not the one the user scope was last synced under (spec §16.2): a
971 # sync moves the lock's Hermes entries there, or just records the home Hermes now uses.
972 # (Hermes no target: its entries are orphans above.)
973 8834 ▶ if ( $scope eq 'user' && grep { $_ eq 'hermes' } @$harnesses ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope eq "user" and grep {$_ eq "hermes";} @$harnesses) 656 8178 8834
Condition100%3/3
$scope eq "user" and grep {$_ eq "hermes";} @$harnesses
!ll&&!rl&&r
45443634656
MC/DC100%2/2
$scope eq "user" and grep {$_ eq "hermes";} @$harnesses
$scope eq "user" grep {$_ eq "hermes";} @$harnesses
Truth table100%3/3
A and B
A= $scope eq "user"B= grep {$_ eq "hermes";} @$harnesses
ABresult
0X0
100
111
974 656 my $home = $self->_hermes_home_of;
975 656 ▶ push @out, { kind => 'targets', id => 'hermes-home:'.$home, sources => [] } unless same_path( $home, $self->_recorded_hermes_home );
Branch: 1 branch
BranchTrueFalseTotal
unless same_path($home, $self->_recorded_hermes_home) 139 517 656
976 }
977 8834 my $settings = $self->_claude_settings_plan( $config, $scope, $harnesses, $lock );
978 8834 ▶ push @out, { kind => 'layout', id => 'layout:claude-settings', sources => [] } if $settings && defined $settings->{next};
Branch: 1 branch
BranchTrueFalseTotal
if $settings and defined $settings->{"next"} 61 8773 8834
Condition100%3/3
$settings and defined $settings->{"next"}
!ll&&!rl&&r
7084168961
MC/DC100%2/2
$settings and defined $settings->{"next"}
$settings defined $settings->{"next"}
Truth table100%3/3
A and B
A= $settingsB= defined $settings->{"next"}
ABresult
0X0
100
111
979 8834 return ( @out, $self->_layout_drift( $scope, $scope_cfg, $lock ), _declared_drift( $scope_cfg, $scope, $harnesses, $lock, $served_by ) );
980 }
981  
982 # A user-scope sync under another Hermes home than the last (spec §16.2): the lock's Hermes
983 # entries are paths under the old home, so what it owns there is deleted and the entries are
984 # dropped – the sync then installs under the new home by the ordinary rules, and a file already
985 # there is never taken for skilletor's own. The new home is recorded before anything is
986 # installed under it: a sync that stops later leaves a lock and a record that agree. With Hermes
987 # no target nothing moves: the sync removes its entries from the recorded home as an inactive
988 # target's, and then drops the record.
989 2609 ▶sub _move_hermes_home {
Subroutine _move_hermes_home: called CC=6 SCAR=18.0
990 2609 my ( $self, $state, $target_dir, $rc, $harnesses, $warnings ) = @_;
991 2609 ▶ return unless grep { $_ eq 'hermes' } @$harnesses;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "hermes";} @$harnesses 2234 375 2609
992 375 my $previous = $self->_recorded_hermes_home;
993 375 my $current = $self->_hermes_home_of;
994 375 ▶ return if same_path( $previous, $current );
Branch: 1 branch
BranchTrueFalseTotal
if same_path($previous, $current) 89 286 375
995 286 my $lock = read_lock( path_join( $target_dir, 'skilletor.lock.json' ) );
996 286 ▶ my @moved = grep { ( parse_lock_key($_)->{harness} // '' ) eq 'hermes' } keys %$lock;
Condition50%1/2
parse_lock_key($_)->{"harness"} // ""
l!l
470
MC/DC0%0/1
parse_lock_key($_)->{"harness"} // ""
parse_lock_key($_)->{"harness"}
Truth table50%1/2
A
A= parse_lock_key($_)->{"harness"}
Aresult
11
00
997 286 ▶ if (@moved) {
Branch: 1 branch
BranchTrueFalseTotal
if (@moved) 3 283 286
998 3 my %moved = map { ( $_ => 1 ) } @moved;
999 3 my $old = { %$rc, hermes_home => $previous };
1000 apply(
1001 [],
1002 target_dir => $target_dir,
1003 12 keep => [ grep { !$moved{$_} } keys %$lock ],
1004 6 ▶ root_of => sub { root_of_key( $old, $_[0] ) // $target_dir },
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
root_of_key($old, $_[0]) // $target_dir
l!l&&r!l&&!r
600
MC/DC0%0/2
root_of_key($old, $_[0]) // $target_dir
root_of_key($old, $_[0]) $target_dir
Truth table33%1/3
A // B
A= root_of_key($old, $_[0])B= $target_dir
ABresult
1X1
011
000
1005 3 );
1006 3 push @$warnings, 'Hermes home changed from '.$previous.' to '.$current.': '.scalar(@moved).' item(s) removed from the old home; '
1007 .'what is declared installs anew under the new one';
1008 }
1009 286 ▶ $state->put_hermes_home( same_path( $current, $self->_hermes_default ) ? undef : $current );
Branch: 1 branch
BranchTrueFalseTotal
same_path($current, $self->_hermes_default) ? : 0 286 286
1010 }
1011  
1012 8834 ▶sub _layout_drift {
Subroutine _layout_drift: called CC=25 SCAR=33.1
1013 8834 my ( $self, $scope, $scope_cfg, $lock ) = @_;
1014 8834 ▶ my $gitignore_on = $scope_cfg->{gitignore} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$scope_cfg->{'gitignore'} ? : 8307 527 8834
1015 8834 my @out;
1016 8834 for my $key ( keys %$lock ) {
1017 8014 my $entry = $lock->{$key};
1018 8014 my $k = parse_lock_key($key);
1019 8014 ▶ my @files = keys %{ $entry->{files} // {} };
Condition50%1/2
$entry->{"files"} // {}
l!l
80140
MC/DC0%0/1
$entry->{"files"} // {}
$entry->{"files"}
Truth table50%1/2
A
A= $entry->{"files"}
Aresult
11
00
1020 8014 ▶ next if !defined $k->{harness} || !supports( $k->{harness}, $k->{type} ) || $entry->{skipped} || $entry->{block} || !@files;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $k->{"harness"} && supports($k->{"harness"}, $k->{"type"}) or $entry->{"skipped"} or $entry->{"block"} or not @files 1904 6110 8014
Condition83%10/12
not defined $k->{"harness"} && supports($k->{"harness"}, $k->{"type"}) or $entry->{"skipped"} or $entry->{"block"} or not @files
l!l&&r!l&&!r
190406110
not defined $k->{"harness"} && supports($k->{"harness"}, $k->{"type"}) or $entry->{"skipped"} or $entry->{"block"}
l!l&&r!l&&!r
8218226110
not defined $k->{"harness"} && supports($k->{"harness"}, $k->{"type"}) or $entry->{"skipped"}
l!l&&r!l&&!r
41417932
defined $k->{'harness'} && supports($k->{'harness'}, $k->{'type'})
!ll&&!rl&&r
4107973
MC/DC60%3/5
not defined $k->{"harness"} && supports($k->{"harness"}, $k->{"type"}) or $entry->{"skipped"} or $entry->{"block"} or not @files
defined $k->{'harness'} supports($k->{'harness'}, $k->{'type'}) $entry->{"skipped"} $entry->{"block"} not @files
Truth table66%4/6
not(A && B) or C or D or not(E)
A= defined $k->{'harness'}B= supports($k->{'harness'}, $k->{'type'})C= $entry->{"skipped"}D= $entry->{"block"}E= not @files
ABCDEresult
0XXXX1
10XXX1
111XX1
1101X1
110011
110000
1021 6110 ▶ my $drift = sub { push @out, { kind => 'layout', id => 'layout:'.$key.':'.$_[0], sources => [ $entry->{source} ] } };
Subroutine __ANON__: called CC=1 SCAR=0.0
1022 6110 ▶ $drift->('local') if lacks_local_prefix( $k->{harness}, $k->{type}, \@files );
Branch: 1 branch
BranchTrueFalseTotal
if lacks_local_prefix($k->{"harness"}, $k->{"type"}, \@files) 0 6110 6110
1023 6110 ▶ if ( $k->{type} eq 'skill' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k->{"type"} eq "skill") 5306 804 6110
1024 5306 ▶ my $ours = ( $entry->{files}{ skill_gitignore_path( $k->{name} ) } // '' ) eq $SKILL_GITIGNORE_HASH ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($entry->{'files'}{skill_gitignore_path($k->{'name'})} // '') eq $SKILL_GITIGNORE_HASH ? : 4238 1068 5306
Condition100%2/2
$entry->{"files"}{skill_gitignore_path($k->{"name"})} // ""
l!l
42381068
MC/DC100%1/1
$entry->{"files"}{skill_gitignore_path($k->{"name"})} // ""
$entry->{"files"}{skill_gitignore_path($k->{"name"})}
Truth table100%2/2
A
A= $entry->{"files"}{skill_gitignore_path($k->{"name"})}
Aresult
11
00
1025 5306 ▶ $drift->( $gitignore_on ? 'gitignore' : 'no-gitignore' ) if $ours != $gitignore_on;
Branch: 2 branches
BranchTrueFalseTotal
if $ours != $gitignore_on 41 5265 5306
$gitignore_on ? : 41 0 41
1026 }
1027 }
1028 8834 ▶ my $in_use = $scope eq 'project' && _project_in_use( $self->_target_dir($scope), $lock );
Condition100%3/3
$scope eq 'project' && _project_in_use($self->_target_dir($scope), $lock)
!ll&&!rl&&r
42909203624
MC/DC100%2/2
$scope eq 'project' && _project_in_use($self->_target_dir($scope), $lock)
$scope eq 'project' _project_in_use($self->_target_dir($scope), $lock)
Truth table100%3/3
A && B
A= $scope eq 'project'B= _project_in_use($self->_target_dir($scope), $lock)
ABresult
0X0
100
111
1029 8834 ▶ if ( $scope eq 'project' && !$in_use && grep { has_block($_) } all_roots( $self->_root_context($scope) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope eq "project" and not $in_use and grep {has_block($_);} all_roots($self->_root_context($scope))) 0 8834 8834
Condition83%5/6
$scope eq "project" and not $in_use and grep {has_block($_);} all_roots($self->_root_context($scope))
!ll&&!rl&&r
79149200
$scope eq "project" and not $in_use
!ll&&!rl&&r
42903624920
MC/DC0%0/3
$scope eq "project" and not $in_use and grep {has_block($_);} all_roots($self->_root_context($scope))
$scope eq "project" not $in_use grep {has_block($_);} all_roots($self->_root_context($scope))
Truth table75%3/4
A and not(B) and C
A= $scope eq "project"B= not $in_useC= grep {has_block($_);} all_roots($self->_root_context($scope))
ABCresult
0XX0
10X0
1100
1111
1030 0 push @out, { kind => 'layout', id => 'layout:unused-project', sources => [] };
1031 }
1032 8834 ▶ if ( $scope eq 'project' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope eq "project") 4544 4290 8834
1033 4544 my $rc = $self->_root_context($scope);
1034 4544 ▶ my @want = $gitignore_on && $in_use ? $self->_worktree_include_entries($rc) : ();
Branch: 1 branch
BranchTrueFalseTotal
$gitignore_on && $in_use ? : 3097 1447 4544
Condition100%3/3
$gitignore_on and $in_use
!ll&&!rl&&r
5279203097
MC/DC100%2/2
$gitignore_on and $in_use
$gitignore_on $in_use
Truth table100%3/3
A and B
A= $gitignore_onB= $in_use
ABresult
0X0
100
111
1035 4544 my @have = block_entries( path_join( $rc->{base}, WORKTREE_INCLUDE ) );
1036 4544 ▶ if ( join( "\n", @have ) ne join( "\n", @want ) && ( @have || %$lock ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (join("\n", @have) ne join("\n", @want) and @have || %$lock) 0 4544 4544
Condition50%3/6
join("\n", @have) ne join("\n", @want) and @have || %$lock
!ll&&!rl&&r
40205240
@have or %$lock
l!l&&r!l&&!r
00524
MC/DC0%0/3
join("\n", @have) ne join("\n", @want) and @have || %$lock
join("\n", @have) ne join("\n", @want) @have %$lock
Truth table50%2/4
A and B or C
A= join("\n", @have) ne join("\n", @want)B= @haveC= %$lock
ABCresult
0XX0
1000
11X1
1011
1037 0 push @out, { kind => 'layout', id => 'layout:worktreeinclude', sources => [] };
1038 }
1039 }
1040 8834 return @out;
1041 }
1042  
1043 # The wildcards and bundles of a scope that declare a lock entry: a bundle its `via` names, a
1044 # wildcard of its source and type whose pattern matches its name.
1045 7918 ▶sub _cover_of {
Subroutine _cover_of: called CC=4 SCAR=14.6
1046 7918 my ( $scope_cfg, $k, $entry ) = @_;
1047 return (
1048 252 ( grep { Skilletor::Resolver::_via_has( $entry->{via}, Skilletor::Resolver->bundle_label($_) ) } @{ $scope_cfg->{bundles} } ),
1049 337 ▶ ( grep { defined $entry->{source} && $_->{source} eq $entry->{source} && $_->{type} eq $k->{type} && matches_pattern( $_->{pattern}, $k->{name} ) }
Condition55%5/9
defined $entry->{'source'} && $_->{'source'} eq $entry->{'source'} && $_->{'type'} eq $k->{'type'} && matches_pattern($_->{'pattern'}, $k->{'name'})
!ll&&!rl&&r
1650172
defined $entry->{"source"} and $_->{"source"} eq $entry->{"source"} and $_->{"type"} eq $k->{"type"}
!ll&&!rl&&r
0165172
defined $entry->{"source"} and $_->{"source"} eq $entry->{"source"}
!ll&&!rl&&r
00337
MC/DC25%1/4
defined $entry->{'source'} && $_->{'source'} eq $entry->{'source'} && $_->{'type'} eq $k->{'type'} && matches_pattern($_->{'pattern'}, $k->{'name'})
defined $entry->{"source"} $_->{"source"} eq $entry->{"source"} $_->{"type"} eq $k->{"type"} matches_pattern($_->{'pattern'}, $k->{'name'})
Truth table40%2/5
A and B and C && D
A= defined $entry->{"source"}B= $_->{"source"} eq $entry->{"source"}C= $_->{"type"} eq $k->{"type"}D= matches_pattern($_->{'pattern'}, $k->{'name'})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1050 7918 @{ $scope_cfg->{wildcards} } ),
1051 );
1052 }
1053  
1054 8834 ▶sub _declared_drift {
Subroutine _declared_drift: called CC=19 SCAR=29.5
1055 8834 my ( $scope_cfg, $scope, $harnesses, $lock, $served_by ) = @_;
1056 8834 my @out;
1057 8834 ▶ my $drift = sub { push @out, { kind => 'declared', id => $_[0], sources => $_[1] } };
Subroutine __ANON__: called CC=1 SCAR=0.0
1058 8834 my %explicit;
1059 8834 for my $item ( @{ $scope_cfg->{install} } ) {
1060 8453 $explicit{ $item->{target} } = 1;
1061 8453 for my $h ( @{ receivers( $harnesses, $item->{type}, $scope ) } ) {
1062 9599 my $key = lock_key( $h, $item->{target} );
1063 9599 ▶ my $have = $lock->{$key} ? $lock->{$key}{source} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$lock->{$key} ? : 7497 2102 9599
1064 9599 ▶ $drift->( 'missing:'.$key.'@'.$item->{source}, [ $item->{source} ] ) unless defined $have && $have eq $item->{source};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $have and $have eq $item->{"source"} 2102 7497 9599
Condition66%2/3
defined $have and $have eq $item->{"source"}
!ll&&!rl&&r
210207497
MC/DC50%1/2
defined $have and $have eq $item->{"source"}
defined $have $have eq $item->{"source"}
Truth table66%2/3
A and B
A= defined $haveB= $have eq $item->{"source"}
ABresult
0X0
100
111
1065 }
1066 }
1067 8834 my %covered;
1068 8834 for my $key ( keys %$lock ) {
1069 8014 my $entry = $lock->{$key};
1070 8014 my $k = parse_lock_key($key);
1071 8014 ▶ next unless defined $k->{harness} && grep { $_ eq $k->{harness} } @{ receivers( $harnesses, $k->{type}, $scope ) };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k->{"harness"} and grep {$_ eq $k->{"harness"};} @{receivers($harnesses, $k->{"type"}, $scope);} 127 7887 8014
Condition100%3/3
defined $k->{"harness"} and grep {$_ eq $k->{"harness"};} @{receivers($harnesses, $k->{"type"}, $scope);}
!ll&&!rl&&r
41867887
MC/DC100%2/2
defined $k->{"harness"} and grep {$_ eq $k->{"harness"};} @{receivers($harnesses, $k->{"type"}, $scope);}
defined $k->{"harness"} grep {$_ eq $k->{"harness"};} @{receivers($harnesses, $k->{"type"}, $scope);}
Truth table100%3/3
A and B
A= defined $k->{"harness"}B= grep {$_ eq $k->{"harness"};} @{receivers($harnesses, $k->{"type"}, $scope);}
ABresult
0X0
100
111
1072 7887 my @by = _cover_of( $scope_cfg, $k, $entry );
1073 7887 $covered{ refaddr $_ } = 1 for @by;
1074 7887 ▶ $drift->( 'orphan:'.$key, [] ) if !@by && !$explicit{ $k->{target} };
Branch: 1 branch
BranchTrueFalseTotal
unless @by or $explicit{$k->{"target"}} 21 7866 7887
Condition100%3/3
@by or $explicit{$k->{"target"}}
l!l&&r!l&&!r
375749121
MC/DC100%2/2
@by or $explicit{$k->{"target"}}
@by $explicit{$k->{"target"}}
Truth table100%3/3
A or B
A= @byB= $explicit{$k->{"target"}}
ABresult
1X1
011
000
1075 7887 ▶ $drift->( 'partial:'.$key, [ $entry->{source} ] ) if $entry->{partial}; # a sync failed midway (k71)
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"partial"} 41 7846 7887
1076 }
1077 8834 for my $w ( @{ $scope_cfg->{wildcards} } ) {
1078 68 ▶ $drift->( 'wildcard:'.$w->{type}.':'.$w->{raw}, [ $w->{source} ] ) unless $covered{ refaddr $w };
Branch: 1 branch
BranchTrueFalseTotal
unless $covered{builtin::refaddr($w)} 0 68 68
1079 }
1080 8834 for my $b ( @{ $scope_cfg->{bundles} } ) {
1081 290 my $label = Skilletor::Resolver->bundle_label($b);
1082 290 ▶ $drift->( $label, [ $b->{source}, @{ ( $served_by // {} )->{$label} // [] } ] ) unless $covered{ refaddr $b };
Branch: 1 branch
BranchTrueFalseTotal
unless $covered{builtin::refaddr($b)} 52 238 290
Condition50%2/4
+($served_by // {})->{$label} // []
l!l
520
$served_by // {}
l!l
520
MC/DC0%0/1
+($served_by // {})->{$label} // []
$served_by
Truth table50%1/2
A
A= $served_by
Aresult
11
00
1083 }
1084 8834 return @out;
1085 }
1086  
1087 #### check ###################################################################
1088  
1089 2759 ▶sub check {
Subroutine check: called CC=24 SCAR=31.8
Pod documented
1090 2759 my ( $self, %opts ) = @_;
1091 2759 ▶ my $sel = $opts{scope} // 'all';
Condition100%2/2
$opts{"scope"} // "all"
l!l
12561503
MC/DC100%1/1
$opts{"scope"} // "all"
$opts{"scope"}
Truth table100%2/2
A
A= $opts{"scope"}
Aresult
11
00
1092 2759 my ( $config, $targets );
1093 2759 ▶ unless ( eval { ( $config, $targets ) = $self->_load_strict( $sel ne 'user' ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { () = $self->_load_strict($sel ne "user"); 1 } }) 97 2662 2759
1094 97 return js_ordered( changed => _false, sources => [], warnings => [], error => _message($@) );
1095 }
1096 2662 my @scopes = _scopes_of( $config, $sel );
1097 2662 my $state = Skilletor::State->new( root => $self->state_root, read_once => 1 ); # it only reads
1098 2662 my $out = js_ordered( changed => _false, sources => [], warnings => [] );
1099 2662 my %field = ( targets => 'targetsChanged', layout => 'layoutChanged', declared => 'declaredChanged' );
1100 2 push @{ $out->{warnings} }, @{ $targets->{warnings} }
1101 2662 ▶ if $targets->{project_unresolved} && grep { $_->[0] eq 'project' } @scopes;
Branch: 1 branch
BranchTrueFalseTotal
if $targets->{"project_unresolved"} and grep {$_->[0] eq "project";} @scopes 2 2660 2662
Condition66%2/3
$targets->{"project_unresolved"} and grep {$_->[0] eq "project";} @scopes
!ll&&!rl&&r
266002
MC/DC50%1/2
$targets->{"project_unresolved"} and grep {$_->[0] eq "project";} @scopes
$targets->{"project_unresolved"} grep {$_->[0] eq "project";} @scopes
Truth table66%2/3
A and B
A= $targets->{"project_unresolved"}B= grep {$_->[0] eq "project";} @scopes
ABresult
0X0
100
111
1102  
1103 2662 for my $s (@scopes) {
1104 4080 my ( $scope, $scope_cfg ) = @$s;
1105 4080 ▶ next if $scope eq 'project' && $targets->{project_unresolved};
Branch: 1 branch
BranchTrueFalseTotal
if $scope eq "project" and $targets->{"project_unresolved"} 2 4078 4080
Condition100%3/3
$scope eq "project" and $targets->{"project_unresolved"}
!ll&&!rl&&r
187422042
MC/DC100%2/2
$scope eq "project" and $targets->{"project_unresolved"}
$scope eq "project" $targets->{"project_unresolved"}
Truth table100%3/3
A and B
A= $scope eq "project"B= $targets->{"project_unresolved"}
ABresult
0X0
100
111
1106 4078 my $lock_path = $self->_lock_path($scope);
1107 4078 my $old_lock = read_lock($lock_path);
1108 4078 my %trust;
1109 5667 ▶ my $trusted = sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
1110 5667 my ( $name ) = @_;
1111 5667 ▶ $trust{$name} //= do {
Condition66%2/3
$trust{$name} //= do { my $src = $config->source_of($scope, $name); $src && eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } } ? 1 : 0 }
l!l&&r!l&&!r
194537220
MC/DC0%0/2
$trust{$name} //= do { my $src = $config->source_of($scope, $name); $src && eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } } ? 1 : 0 }
$trust{$name} do { my $src = $config->source_of($scope, $name); $src && eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } } ? 1 : 0 }
Truth table66%2/3
A //= B
A= $trust{$name}B= do { my $src = $config->source_of($scope, $name); $src && eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } } ? 1 : 0 }
ABresult
1X1
011
000
1112 3722 my $src = $config->source_of( $scope, $name );
1113 3722 ▶ ( $src && eval { $state->is_trusted( $name, Skilletor::Backend->resolve( $src, $self->home ) ) } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$src && eval { do { $state->is_trusted($name, 'Skilletor::Backend'->resolve($src, $self->home)) } } ? : 3457 265 3722
Condition66%2/3
$src and eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } }
!ll&&!rl&&r
02653457
MC/DC50%1/2
$src and eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } }
$src eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } }
Truth table66%2/3
A and B
A= $srcB= eval { do { $state->is_trusted($name, "Skilletor::Backend"->resolve($src, $self->home)) } }
ABresult
0X0
100
111
1114 };
1115 5667 return $trust{$name};
1116 4078 };
1117 # Drift counts unless the last sync tried it with its sources at hand, or a source it needs
1118 # is untrusted – that asks for trust, not for a sync.
1119 4078 my %unreached = map { ( $_ => 1 ) } @{ $state->unreached($lock_path) };
1120 4078 my $read = $state->sources_read($lock_path);
1121 my @open = grep {
1122 2266 my $d = $_;
1123 2266 ▶ !$unreached{ $d->{id} } && !grep { !$trusted->($_) } @{ $d->{sources} };
Condition100%3/3
$unreached{$d->{'id'}} || grep({not &$trusted($_);} @{$$d{'sources'};})
l!l&&r!l&&!r
142651987
MC/DC100%2/2
$unreached{$d->{'id'}} || grep({not &$trusted($_);} @{$$d{'sources'};})
$unreached{$d->{'id'}} grep({not &$trusted($_);} @{$$d{'sources'};})
Truth table100%3/3
A || B
A= $unreached{$d->{'id'}}B= grep({not &$trusted($_);} @{$$d{'sources'};})
ABresult
1X1
011
000
1124 4078 } $self->_scope_drift( $config, $scope, $targets->{$scope}, $old_lock );
1125 4078 for my $kind (qw( targets layout declared )) {
1126 12234 ▶ next unless grep { $_->{kind} eq $kind } @open;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_->{"kind"} eq $kind;} @open 10391 1843 12234
1127 1843 $out->{changed} = _true;
1128 1843 push @{ $out->{ $field{$kind} } }, $scope;
1129 }
1130 # What the last sync rendered with (k76), while a trusted source has items to render.
1131 4078 ▶ if ( ( grep { $trusted->($_) } _render_sources( $scope_cfg, $old_lock ) )
Branch: 1 branch
BranchTrueFalseTotal
if (grep {&$trusted($_);} _render_sources($scope_cfg, $old_lock) and ($state->render_inputs($lock_path) // "") ne _render_inputs_hash($self->_render_inputs_of($scope, $scope_cfg))) 1184 2815 3999
Condition100%5/5
grep {&$trusted($_);} _render_sources($scope_cfg, $old_lock) and ($state->render_inputs($lock_path) // "") ne _render_inputs_hash($self->_render_inputs_of($scope, $scope_cfg))
!ll&&!rl&&r
94519491184
$state->render_inputs($lock_path) // ""
l!l
19501183
MC/DC100%2/2
grep {&$trusted($_);} _render_sources($scope_cfg, $old_lock) and ($state->render_inputs($lock_path) // "") ne _render_inputs_hash($self->_render_inputs_of($scope, $scope_cfg))
grep {&$trusted($_);} _render_sources($scope_cfg, $old_lock) $state->render_inputs($lock_path)
Truth table100%3/3
A and B
A= grep {&$trusted($_);} _render_sources($scope_cfg, $old_lock)B= $state->render_inputs($lock_path)
ABresult
0X0
100
111
1132 && ( $state->render_inputs($lock_path) // '' ) ne _render_inputs_hash( $self->_render_inputs_of( $scope, $scope_cfg ) ) )
1133 {
1134 1184 $out->{changed} = _true;
1135 1184 push @{ $out->{varsChanged} }, $scope;
1136 }
1137 # Sources a bundle pulled items from (spec §15.6) are not declared here; the lock names them.
1138 0 ▶ my @via_sources = map { $old_lock->{$_}{source} } grep { my $v = $old_lock->{$_}{via}; ref $v eq 'ARRAY' ? @$v : ( defined $v && length $v ) } keys %$old_lock;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 2849 2849
Condition33%1/3
defined $v and length $v
!ll&&!rl&&r
284900
MC/DC0%0/2
defined $v and length $v
defined $v length $v
Truth table33%1/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
1139 3999 for my $name ( _uniq( _scope_sources($scope_cfg), @via_sources ) ) {
1140 3606 ▶ my $src = $config->source_of( $scope, $name ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $src = $config->source_of($scope, $name) or next 3606 0 3606
1141 3606 my $ok = eval {
1142 3606 my $backend = Skilletor::Backend->resolve( $src, $self->home );
1143 3606 ▶ if ( !$state->is_trusted( $name, $backend ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->is_trusted($name, $backend)) 264 3342 3606
1144 # Named in every check, as a sync names it (spec §4.3); never fetched.
1145 264 my $t = Skilletor::Backend->trust_request( $name, $backend );
1146 264 push @{ $out->{trustRequests} }, js_ordered( scope => $scope, map { ( $_ => $t->{$_} ) } keys %$t );
1147 264 return 1;
1148 }
1149 3342 ▶ return 1 if $opts{local}; # the lock against the config only: no source asked
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"local"} 1057 2285 3342
1150 2285 my $version = _checked_version( $read->{$name}, $backend, $old_lock, $name );
1151 2285 ▶ my $changed = Skilletor::Backend->make( $backend, $self->cache_root, $self->timeout_ms )->check($version) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
'Skilletor::Backend'->make($backend, $self->cache_root, $self->timeout_ms)->check($version) ? : 2194 45 2239
1152 2239 ▶ push @{ $out->{sources} }, js_ordered( name => $name, scope => $scope, changed => $changed ? _true : _false );
Branch: 1 branch
BranchTrueFalseTotal
$changed ? : 2194 45 2239
1153 2239 ▶ $out->{changed} = _true if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 2194 45 2239
1154 2239 1;
1155 };
1156 3604 ▶ push @{ $out->{warnings} }, 'source '.$name.': '._message($@) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 44 3560 3604
1157 }
1158 }
1159 2581 return $out;
1160 }
1161  
1162 #### status ##################################################################
1163  
1164 618 ▶sub status {
Subroutine status: called CC=32 SCAR=35.1
Pod documented
1165 618 my ( $self, %opts ) = @_;
1166 618 ▶ my $sel = $opts{scope} // 'all';
Condition100%2/2
$opts{"scope"} // "all"
l!l
53781
MC/DC100%1/1
$opts{"scope"} // "all"
$opts{"scope"}
Truth table100%2/2
A
A= $opts{"scope"}
Aresult
11
00
1167 618 my ( $config, $targets );
1168 return js_ordered( scopes => [], error => _message($@) )
1169 618 ▶ unless eval { ( $config, $targets ) = $self->_load_strict( $sel ne 'user' ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { () = $self->_load_strict($sel ne "user"); 1 } } 40 578 618
1170 578 my @scopes = _scopes_of( $config, $sel );
1171 578 my $state = Skilletor::State->new( root => $self->state_root );
1172 578 my $out = js_ordered( scopes => [] );
1173 0 $out->{warnings} = [ @{ $targets->{warnings} } ]
1174 0 ▶ if $targets->{project_unresolved} && grep { $_->[0] eq 'project' } @scopes;
Branch: 1 branch
BranchTrueFalseTotal
if $targets->{"project_unresolved"} and grep {$_->[0] eq "project";} @scopes 0 578 578
Condition33%1/3
$targets->{"project_unresolved"} and grep {$_->[0] eq "project";} @scopes
!ll&&!rl&&r
57800
MC/DC0%0/2
$targets->{"project_unresolved"} and grep {$_->[0] eq "project";} @scopes
$targets->{"project_unresolved"} grep {$_->[0] eq "project";} @scopes
Truth table33%1/3
A and B
A= $targets->{"project_unresolved"}B= grep {$_->[0] eq "project";} @scopes
ABresult
0X0
100
111
1175 578 my $given = $self->project_dir;
1176 578 ▶ $out->{projectIsHome} = _true if $sel ne 'user' && defined $given && length $given && !defined $self->project_dir_of;
Branch: 1 branch
BranchTrueFalseTotal
if $sel ne "user" and defined $given and length $given and not defined $self->project_dir_of 1 577 578
Condition88%8/9
$sel ne "user" and defined $given and length $given and not defined $self->project_dir_of
!ll&&!rl&&r
1893881
$sel ne "user" and defined $given and length $given
!ll&&!rl&&r
1890389
$sel ne "user" and defined $given
!ll&&!rl&&r
15039389
MC/DC75%3/4
$sel ne "user" and defined $given and length $given and not defined $self->project_dir_of
$sel ne "user" defined $given length $given not defined $self->project_dir_of
Truth table80%4/5
A and B and C and not(D)
A= $sel ne "user"B= defined $givenC= length $givenD= not defined $self->project_dir_of
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1177  
1178 578 for my $s (@scopes) {
1179 579 my ( $scope, $scope_cfg ) = @$s;
1180 579 my $lock = read_lock( $self->_lock_path($scope) );
1181 579 my $active = $targets->{$scope};
1182 # One row per declared item and active target that gets a copy of its type.
1183 my @rows = map {
1184 691 my $i = $_;
1185 691 map { { key => lock_key( $_, $i->{target} ), source => $i->{source} } } @{ receivers( $active, $i->{type}, $scope ) };
1186 579 } @{ $scope_cfg->{install} };
1187 579 my %declared_keys = map { ( $_->{key} => 1 ) } @rows;
1188 579 my $versions = js_ordered();
1189 579 $versions->{ $lock->{$_}{source} } = $lock->{$_}{version} for grep { defined $lock->{$_}{source} } keys %$lock;
1190 579 my @trust;
1191 579 for my $name ( _scope_sources($scope_cfg) ) {
1192 580 ▶ my $src = $config->source_of( $scope, $name ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $src = $config->source_of($scope, $name) or next 580 0 580
1193 580 my $backend = Skilletor::Backend->resolve( $src, $self->home );
1194 580 ▶ push @trust, Skilletor::Backend->trust_request( $name, $backend ) unless $state->is_trusted( $name, $backend );
Branch: 1 branch
BranchTrueFalseTotal
unless $state->is_trusted($name, $backend) 1 579 580
1195 }
1196 # A skip entry is declared but deliberately not installed.
1197 my @declared = map {
1198 579 my $entry = $lock->{ $_->{key} };
1199 1051 ▶ my $d = js_ordered( key => $_->{key}, source => $_->{source}, installed => ( $entry && !$entry->{skipped} ) ? _true : _false );
Branch: 1 branch
BranchTrueFalseTotal
$entry && !$entry->{'skipped'} ? : 566 485 1051
Condition100%3/3
$entry and not $entry->{"skipped"}
!ll&&!rl&&r
44441566
MC/DC100%2/2
$entry and not $entry->{"skipped"}
$entry not $entry->{"skipped"}
Truth table100%3/3
A and not(B)
A= $entryB= not $entry->{"skipped"}
ABresult
0X0
100
111
1200 1051 ▶ $d->{skipped} = $entry->{skipped} if $entry && $entry->{skipped};
Branch: 1 branch
BranchTrueFalseTotal
if $entry and $entry->{"skipped"} 41 1010 1051
Condition100%3/3
$entry and $entry->{"skipped"}
!ll&&!rl&&r
44456641
MC/DC100%2/2
$entry and $entry->{"skipped"}
$entry $entry->{"skipped"}
Truth table100%3/3
A and B
A= $entryB= $entry->{"skipped"}
ABresult
0X0
100
111
1201 1051 ▶ $d->{partial} = _true if $entry && $entry->{partial};
Branch: 1 branch
BranchTrueFalseTotal
if $entry and $entry->{"partial"} 41 1010 1051
Condition100%3/3
$entry and $entry->{"partial"}
!ll&&!rl&&r
44456641
MC/DC100%2/2
$entry and $entry->{"partial"}
$entry $entry->{"partial"}
Truth table100%3/3
A and B
A= $entryB= $entry->{"partial"}
ABresult
0X0
100
111
1202 1051 $d;
1203 } @rows;
1204 579 my ( %via, @orphans ); # distinct item targets per covering entry
1205 579 for my $key ( keys %$lock ) {
1206 679 ▶ next if $declared_keys{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $declared_keys{$key} 607 72 679
1207 72 my $entry = $lock->{$key};
1208 72 my $k = parse_lock_key($key);
1209 72 ▶ my @covering = ( defined $k->{harness} && grep { $_ eq $k->{harness} } @$active ) ? _cover_of( $scope_cfg, $k, $entry ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $k->{'harness'} && grep({$_ eq $k->{'harness'};} @$active) ? : 31 41 72
Condition66%2/3
defined $k->{"harness"} and grep {$_ eq $k->{"harness"};} @$active
!ll&&!rl&&r
04131
MC/DC50%1/2
defined $k->{"harness"} and grep {$_ eq $k->{"harness"};} @$active
defined $k->{"harness"} grep {$_ eq $k->{"harness"};} @$active
Truth table66%2/3
A and B
A= defined $k->{"harness"}B= grep {$_ eq $k->{"harness"};} @$active
ABresult
0X0
100
111
1210 72 my $first = $covering[0];
1211 72 ▶ unless ($first) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first) 41 31 72
1212 41 push @orphans, $key;
1213 41 next;
1214 }
1215 31 ▶ my $label = exists $first->{pattern} ? $first->{raw} : Skilletor::Resolver->bundle_label($first);
Branch: 1 branch
BranchTrueFalseTotal
exists $first->{'pattern'} ? : 31 0 31
1216 31 ▶ if ( $entry->{skipped} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"skipped"}) 0 31 31
1217 0 push @declared, js_ordered( key => $key, source => $entry->{source}, installed => _false, via => $label, skipped => $entry->{skipped} );
1218 0 next;
1219 }
1220 31 my $d = js_ordered( key => $key, source => $entry->{source}, installed => _true, via => $label );
1221 31 ▶ $d->{partial} = _true if $entry->{partial};
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"partial"} 0 31 31
1222 31 push @declared, $d;
1223 31 $via{ refaddr $_ }{ $k->{target} } = 1 for @covering;
1224 }
1225 579 my %installed = map { ( $_->{key} => 1 ) } grep { $_->{installed} } @declared;
1226 579 my %missing = map { ( $_->{key} => $_->{missing} ) } $self->_briefing_of( $scope, $lock, \%installed );
1227 579 $_->{briefingMissing} = $missing{ $_->{key} } for grep { $missing{ $_->{key} } } @declared;
1228 579 ▶ my $installed_via = sub { 0 + keys %{ $via{ refaddr $_[0] } // {} } };
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition50%1/2
$via{builtin::refaddr($_[0])} // {}
l!l
160
MC/DC0%0/1
$via{builtin::refaddr($_[0])} // {}
$via{builtin::refaddr($_[0])}
Truth table50%1/2
A
A= $via{builtin::refaddr($_[0])}
Aresult
11
00
1229 579 push @{ $out->{scopes} }, js_ordered(
1230 scope => $scope,
1231 targets => [@$active],
1232 declared => \@declared,
1233 orphans => \@orphans,
1234 16 wildcards => [ map { js_ordered( type => $_->{type}, source => $_->{source}, entry => $_->{raw}, installed => $installed_via->($_) ) }
1235 579 @{ $scope_cfg->{wildcards} } ],
1236 0 bundles => [ map { js_ordered( name => $_->{name}, source => $_->{source}, entry => $_->{raw}, installed => $installed_via->($_) ) }
1237 579 @{ $scope_cfg->{bundles} } ],
1238 trustRequests => \@trust,
1239 sourceVersions => $versions,
1240 );
1241 }
1242 578 my $trust = $self->_hook_trust_warning($targets);
1243 578 ▶ push @{ $out->{warnings} //= [] }, $trust if defined $trust;
Branch: 1 branch
BranchTrueFalseTotal
if defined $trust 358 220 578
Condition50%1/2
$out->{"warnings"} //= []
l!l
0358
MC/DC0%0/1
$out->{"warnings"} //= []
$out->{"warnings"}
Truth table50%1/2
A
A= $out->{"warnings"}
Aresult
11
00
1244 578 return $out;
1245 }
1246  
1247 #### The Codex rules context (spec §14.8) #####################################
1248  
1249 # The Codex rules files the SessionStart hook injects: the user scope's, then the project's, each
1250 # when it exists and Codex is a target of that scope. When the config or the targets cannot be
1251 # loaded, every existing file (the last good state). Reads no source and never throws.
1252 529 ▶sub codex_rules_files {
Subroutine codex_rules_files: called CC=6 SCAR=17.9
Pod documented
1253 529 my ( $self ) = @_;
1254 529 my ( $config, $targets );
1255 529 my $loaded = eval { ( $config, $targets ) = $self->_load_strict; 1 };
1256 529 my @out;
1257 529 ▶ for my $scope ( 'user', ( defined $self->project_dir_of ? 'project' : () ) ) {
Branch: 1 branch
BranchTrueFalseTotal
defined $self->project_dir_of ? : 528 1 529
1258 1057 ▶ next if $loaded && !grep { $_ eq 'codex' } @{ $targets->{$scope} };
Branch: 1 branch
BranchTrueFalseTotal
if $loaded and not grep({$_ eq "codex";} @{$$targets{$scope};}) 115 942 1057
Condition100%3/3
$loaded and not grep({$_ eq "codex";} @{$$targets{$scope};})
!ll&&!rl&&r
42900115
MC/DC100%2/2
$loaded and not grep({$_ eq "codex";} @{$$targets{$scope};})
$loaded not grep({$_ eq "codex";} @{$$targets{$scope};})
Truth table100%3/3
A and not(B)
A= $loadedB= not grep({$_ eq "codex";} @{$$targets{$scope};})
ABresult
0X0
100
111
1259 942 my $file = path_join( root_of( $self->_root_context($scope), 'codex', 'rule' ), RULES_FILE );
1260 942 ▶ push @out, $file if -e encode_text($file);
Branch: 1 branch
BranchTrueFalseTotal
if -e encode_text($file) 845 97 942
1261 }
1262 529 return @out;
1263 }
1264  
1265 399 1;
1266  
1267 __END__
« /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Cpanel/JSON/XS.pm ↑ Summary /usr/local/lib/perl5/5.44.0/x86_64-linux/Config.pm »