Skilletor/Report.pm

filter: Statementstmt 77.9% 113 / 145 Branchbran 40.7% 22 / 54 Conditioncond 50.0% 30 / 60 MC/DCmcdc 13.7% 4 / 29 Subroutinesub 73.6% 14 / 19 Podpod 100% 10 / 10 totaltotal 60.8% 193 / 317 CC 69 SCAR 29.2
CC
69
Cov
64%
status_text
34.0
report_text
24.2
has_changes
20.0
CRAP 18.5
« Skilletor/Spec.pm ↑ Summary Skilletor/JSON.pm »
1 package Skilletor::Report;
2 # ABSTRACT: The reports of sync, check and status – their shape, their text, their exit codes (spec §8)
3  
4 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 31 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 31 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use Skilletor::Lock qw( parse_lock_key );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 31 our $VERSION = '0.001';
12  
13 31 our @EXPORT_OK = qw(
14 ACTIVATION empty_scope_report display_safe backend_label conflict_hint has_changes has_notable
15 report_text status_text check_text exit_code
16 );
17  
18 # Per item type: when Claude Code sees an item a sync installed (spec §12).
19 31 ▶use constant ACTIVATION => {
Subroutine BEGIN: called CC=1 SCAR=0.0
20 skill => 'active now',
21 agent => 'active after /reload-plugins or restart',
22 rule => 'active after /reload-plugins or restart',
23 31 };
24  
25 31 my %HARNESS_ACTIVATION = ( codex => 'active from the next Codex session', hermes => 'active from the next Hermes session' );
26  
27 3 ▶sub _activation_of {
Subroutine _activation_of: called CC=3 SCAR=13.3
28 3 my ( $it ) = @_;
29 3 my $harness = parse_lock_key( $it->{key} )->{harness};
30 3 ▶ return ( defined $harness && $HARNESS_ACTIVATION{$harness} ) // ACTIVATION->{ $it->{type} };
Condition33%2/6
defined $harness && $HARNESS_ACTIVATION{$harness} // {"agent" => "active after /reload-plugins or restart","rule" => "active after /reload-plugins or restart","skill" => "active now"}->{$it->{"type"}}
l!l&&r!l&&!r
030
defined $harness and $HARNESS_ACTIVATION{$harness}
!ll&&!rl&&r
030
MC/DC0%0/3
defined $harness && $HARNESS_ACTIVATION{$harness} // {"agent" => "active after /reload-plugins or restart","rule" => "active after /reload-plugins or restart","skill" => "active now"}->{$it->{"type"}}
defined $harness $HARNESS_ACTIVATION{$harness} {"agent" => "active after /reload-plugins or restart","rule" => "active after /reload-plugins or restart","skill" => "active now"}->{$it->{"type"}}
Truth table20%1/5
A and B // C
A= defined $harnessB= $HARNESS_ACTIVATION{$harness}C= {"agent" => "active after /reload-plugins or restart","rule" => "active after /reload-plugins or restart","skill" => "active now"}->{$it->{"type"}}
ABCresult
11X1
0X11
1011
0X00
1000
31 }
32  
33 28 ▶sub empty_scope_report {
Subroutine empty_scope_report: called CC=1 SCAR=0.0
Pod documented
34 28 my ( $scope ) = @_;
35 return {
36 28 scope => $scope, added => [], updated => [], removed => [], unchanged => [], skipped => [], conflicts => [], overwritten => [],
37 warnings => [], trustRequests => [],
38 };
39 }
40  
41 31 my %C0 = ( "\b" => '\\b', "\f" => '\\f', "\n" => '\\n', "\r" => '\\r' );
42  
43 # One display line safe for a terminal and a model's context: control characters but tab, the
44 # bidi controls, the line and paragraph separators, the zero-width space, word joiner and BOM
45 # escaped the JSON way.
46 10 ▶sub display_safe {
Subroutine display_safe: called CC=3 SCAR=11.0
Pod documented
47 10 my ( $line ) = @_;
48 10 $line =~ s{((?!\t)[\p{Cc}\p{Bidi_Control}\x{200B}\x{2028}\x{2029}\x{2060}\x{FEFF}])}{
49 3 my $c = $1;
50 3 ▶ ord($c) < 0x20 ? ( $C0{$c} // sprintf( '\\u%04x', ord $c ) ) : sprintf( '\\u%04x', ord $c );
Branch: 1 branch
BranchTrueFalseTotal
ord $c < 32 ? : 2 1 3
Condition100%2/2
$C0{$c} // sprintf("\\u%04x", ord $c)
l!l
11
MC/DC100%1/1
$C0{$c} // sprintf("\\u%04x", ord $c)
$C0{$c}
Truth table100%2/2
A
A= $C0{$c}
Aresult
11
00
51 }ge;
52 10 return $line;
53 }
54  
55 0 ▶sub backend_label {
Subroutine backend_label: not called CC=1 SCAR=6.9
Pod documented
56 0 my ( $b ) = @_;
57 0 return $b->{kind}.' '.$b->{url};
58 }
59  
60 0 ▶sub conflict_hint {
Subroutine conflict_hint: not called CC=3 SCAR=24.8
Pod documented
61 0 my ( $c ) = @_;
62 0 ▶ return 'is not a file (move or remove it yourself; --force leaves it)' if $c->{notFile};
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"notFile"} 0 0 0
63 0 ▶ return 'already exists (use --force to '.( $c->{replace} ? 'replace it' : 'adopt' ).')';
Branch: 1 branch
BranchTrueFalseTotal
$c->{'replace'} ? : 0 0 0
64 }
65  
66 0 ▶sub has_changes {
Subroutine has_changes: not called CC=4 SCAR=30.0
Pod documented
67 0 my ( $r ) = @_;
68 0 ▶ return ( grep { @{ $_->{added} } || @{ $_->{updated} } || @{ $_->{removed} } } @{ $r->{scopes} } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({@{$_->{'added'};} or @{$_->{'updated'};} or @{$_->{'removed'};};} @{$$r{'scopes'};}) ? : 0 0 0
Condition0%0/6
@{$_->{'added'};} || @{$_->{'updated'};} || @{$_->{'removed'};}
l!l&&r!l&&!r
000
@{$_->{"added"};} or @{$_->{"updated"};}
l!l&&r!l&&!r
000
MC/DC0%0/3
@{$_->{'added'};} || @{$_->{'updated'};} || @{$_->{'removed'};}
@{$_->{"added"};} @{$_->{"updated"};} @{$_->{'removed'};}
Truth table0%0/4
A or B || C
A= @{$_->{"added"};}B= @{$_->{"updated"};}C= @{$_->{'removed'};}
ABCresult
1XX1
01X1
0011
0000
69 }
70  
71 4 ▶sub _is_notable {
Subroutine _is_notable: called CC=11 SCAR=25.3
72 4 my ( $s ) = @_;
73 4 return ( @{ $s->{added} } || @{ $s->{updated} } || @{ $s->{removed} } || @{ $s->{conflicts} } || @{ $s->{overwritten} }
74 4 ▶ || @{ $s->{warnings} } || @{ $s->{trustRequests} } || @{ $s->{gitignoreUpdated} // [] } || $s->{settingsUpdated} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$s->{'added'};} || @{$s->{'updated'};} || @{$s->{'removed'};} || @{$s->{'conflicts'};} || @{$s->{'overwritten'};} || @{$s->{'warnings'};} || @{$s->{'trustRequests'};} || @{$s->{'gitignoreUpdated'} // [];} || $s->{'settingsUpdated'} ? : 3 1 4
Condition65%17/26
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};} or @{$s->{"conflicts"};} or @{$s->{"overwritten"};} or @{$s->{"warnings"};} or @{$s->{"trustRequests"};} or @{$s->{"gitignoreUpdated"} // [];} or $s->{"settingsUpdated"}
l!l&&r!l&&!r
301
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};} or @{$s->{"conflicts"};} or @{$s->{"overwritten"};} or @{$s->{"warnings"};} or @{$s->{"trustRequests"};} or @{$s->{"gitignoreUpdated"} // [];}
l!l&&r!l&&!r
301
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};} or @{$s->{"conflicts"};} or @{$s->{"overwritten"};} or @{$s->{"warnings"};} or @{$s->{"trustRequests"};}
l!l&&r!l&&!r
301
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};} or @{$s->{"conflicts"};} or @{$s->{"overwritten"};} or @{$s->{"warnings"};}
l!l&&r!l&&!r
301
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};} or @{$s->{"conflicts"};} or @{$s->{"overwritten"};}
l!l&&r!l&&!r
301
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};} or @{$s->{"conflicts"};}
l!l&&r!l&&!r
301
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};}
l!l&&r!l&&!r
301
@{$s->{"added"};} or @{$s->{"updated"};}
l!l&&r!l&&!r
301
$s->{"gitignoreUpdated"} // []
l!l
01
MC/DC11%1/9
@{$s->{"added"};} or @{$s->{"updated"};} or @{$s->{"removed"};} or @{$s->{"conflicts"};} or @{$s->{"overwritten"};} or @{$s->{"warnings"};} or @{$s->{"trustRequests"};} or @{$s->{"gitignoreUpdated"} // [];} or $s->{"settingsUpdated"}
@{$s->{"added"};} @{$s->{"updated"};} @{$s->{"removed"};} @{$s->{"conflicts"};} @{$s->{"overwritten"};} @{$s->{"warnings"};} @{$s->{"trustRequests"};} @{$s->{"gitignoreUpdated"} // [];} $s->{"settingsUpdated"}
MC/DC0%0/1
$s->{"gitignoreUpdated"} // []
$s->{"gitignoreUpdated"}
Truth table20%2/10
A or B or C or D or E or F or G or H or I
A= @{$s->{"added"};}B= @{$s->{"updated"};}C= @{$s->{"removed"};}D= @{$s->{"conflicts"};}E= @{$s->{"overwritten"};}F= @{$s->{"warnings"};}G= @{$s->{"trustRequests"};}H= @{$s->{"gitignoreUpdated"} // [];}I= $s->{"settingsUpdated"}
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
Truth table50%1/2
A
A= $s->{"gitignoreUpdated"}
Aresult
11
00
75 }
76  
77 0 ▶sub has_notable {
Subroutine has_notable: not called CC=3 SCAR=24.8
Pod documented
78 0 my ( $r ) = @_;
79 0 ▶ return ( defined $r->{error} || grep { _is_notable($_) } @{ $r->{scopes} } ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'error'} || grep({_is_notable($_);} @{$$r{'scopes'};}) ? : 0 0 0
Condition0%0/3
defined $r->{"error"} or grep {_is_notable($_);} @{$$r{"scopes"};}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $r->{"error"} or grep {_is_notable($_);} @{$$r{"scopes"};}
defined $r->{"error"} grep {_is_notable($_);} @{$$r{"scopes"};}
Truth table0%0/3
A or B
A= defined $r->{"error"}B= grep {_is_notable($_);} @{$$r{"scopes"};}
ABresult
1X1
011
000
80 }
81  
82 0 ▶sub _settings_hint {
Subroutine _settings_hint: not called CC=4 SCAR=30.0
83 0 my ( $u ) = @_;
84 0 my @what;
85 0 ▶ push @what, 'enables '.join( ', ', @{ $u->{enabled} } ) if @{ $u->{enabled} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$u->{"enabled"};} 0 0 0
86 0 ▶ push @what, 'declares marketplace'.( @{ $u->{declared} } > 1 ? 's' : '' ).' '.join( ', ', @{ $u->{declared} } ) if @{ $u->{declared} };
Branch: 2 branches
BranchTrueFalseTotal
if @{$u->{"declared"};} 0 0 0
@{$u->{'declared'};} > 1 ? : 0 0 0
87 0 return $u->{path}.' updated ('.join( '; ', @what ).') — commit it';
88 }
89  
90 # The sync report as the CLI prints it; empty when there is nothing to say.
91 4 ▶sub report_text {
Subroutine report_text: called CC=21 SCAR=31.9
Pod documented
92 4 my ( $r ) = @_;
93 4 ▶ return display_safe( 'skilletor: config error, nothing changed — '.$r->{error} ) if defined $r->{error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"error"} 0 4 4
94 4 my @lines;
95 4 for my $s ( @{ $r->{scopes} } ) {
96 # Skips are informational: shown here, but not notable.
97 4 ▶ next if !_is_notable($s) && !@{ $s->{skipped} };
Branch: 1 branch
BranchTrueFalseTotal
unless _is_notable($s) or @{$s->{"skipped"};} 1 3 4
Condition66%2/3
_is_notable($s) or @{$s->{"skipped"};}
l!l&&r!l&&!r
301
MC/DC50%1/2
_is_notable($s) or @{$s->{"skipped"};}
_is_notable($s) @{$s->{"skipped"};}
Truth table66%2/3
A or B
A= _is_notable($s)B= @{$s->{"skipped"};}
ABresult
1X1
011
000
98 0 my %skipped = map { ( $_->{key} => 1 ) } @{ $s->{skipped} };
99 3 push @lines, 'skilletor: '.$s->{scope}.' scope';
100 3 push @lines, ' + '.$_->{key}.' ('._activation_of($_).')' for @{ $s->{added} };
101 3 push @lines, ' ~ '.$_->{key}.' ('._activation_of($_).')' for @{ $s->{updated} };
102 3 ▶ push @lines, ' - '.$_->{key}.' ('.( $skipped{ $_->{key} } ? 'removed: renders empty' : 'removed' ).')' for @{ $s->{removed} };
Branch: 1 branch
BranchTrueFalseTotal
$skipped{$_->{'key'}} ? : 0 0 0
103 0 my %removed = map { ( $_->{key} => 1 ) } @{ $s->{removed} };
104 0 push @lines, ' · '.$_->{key}.' skipped (renders empty)' for grep { !$removed{ $_->{key} } } @{ $s->{skipped} };
105 3 push @lines, ' overwrote local change: '.$_->{path} for @{ $s->{overwritten} };
106 3 push @lines, ' conflict: '.$_->{path}.' '.conflict_hint($_) for @{ $s->{conflicts} };
107 3 push @lines, ' trust: source "'.$_->{name}.'" ('.backend_label($_).') — run: skilletor trust '.$_->{name} for @{ $s->{trustRequests} };
108 3 ▶ push @lines, ' '.$_.' updated — commit it' for @{ $s->{gitignoreUpdated} // [] };
Condition50%1/2
$s->{"gitignoreUpdated"} // []
l!l
03
MC/DC0%0/1
$s->{"gitignoreUpdated"} // []
$s->{"gitignoreUpdated"}
Truth table50%1/2
A
A= $s->{"gitignoreUpdated"}
Aresult
11
00
109 3 ▶ push @lines, ' '._settings_hint( $s->{settingsUpdated} ) if $s->{settingsUpdated};
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"settingsUpdated"} 0 3 3
110 3 push @lines, ' warning: '.$_ for @{ $s->{warnings} };
111 }
112 4 ▶ push @lines, 'skilletor: warning: '.$_ for @{ $r->{warnings} // [] };
Condition50%1/2
$r->{"warnings"} // []
l!l
04
MC/DC0%0/1
$r->{"warnings"} // []
$r->{"warnings"}
Truth table50%1/2
A
A= $r->{"warnings"}
Aresult
11
00
113 4 ▶ push @lines, 'skilletor: note: '.$_ for @{ $r->{notes} // [] };
Condition50%1/2
$r->{"notes"} // []
l!l
04
MC/DC0%0/1
$r->{"notes"} // []
$r->{"notes"}
Truth table50%1/2
A
A= $r->{"notes"}
Aresult
11
00
114 4 return join "\n", map { display_safe($_) } @lines;
115 }
116  
117 # The status report as `skilletor status` prints it.
118 1 ▶sub status_text {
Subroutine status_text: called CC=20 SCAR=35.3
Pod documented
119 1 my ( $r ) = @_;
120 1 ▶ return display_safe( 'skilletor: config error — '.$r->{error} ) if defined $r->{error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"error"} 0 1 1
121 1 my @lines;
122 1 for my $s ( @{ $r->{scopes} } ) {
123 1 my @t = @{ $s->{targets} };
124 1 ▶ my $claude_only = @t == 1 && $t[0] eq 'claude';
Condition33%1/3
@t == 1 && $t[0] eq 'claude'
!ll&&!rl&&r
001
MC/DC0%0/2
@t == 1 && $t[0] eq 'claude'
@t == 1 $t[0] eq 'claude'
Truth table33%1/3
A && B
A= @t == 1B= $t[0] eq 'claude'
ABresult
0X0
100
111
125 1 ▶ push @lines, $claude_only ? $s->{scope}.' scope:' : $s->{scope}.' scope ('.( @t ? join( ', ', @t ) : 'no targets' ).'):';
Branch: 2 branches
BranchTrueFalseTotal
$claude_only ? : 1 0 1
@t ? : 0 0 0
126 1 for my $d ( @{ $s->{declared} } ) {
127 2 ▶ my $mark = $d->{installed} ? '✓' : $d->{skipped} ? '-' : '·';
Branch: 2 branches
BranchTrueFalseTotal
$d->{'installed'} ? : 2 0 2
$d->{'skipped'} ? : 0 0 0
128 my $note = ( $d->{skipped} ? ' (skipped: renders empty)' : '' ).( $d->{partial} ? ' (partial: the last sync stopped midway)' : '' )
129 0 ▶ .( $d->{briefingMissing} ? ' (briefing skills not installed: '.join( ', ', @{ $d->{briefingMissing} } ).')' : '' );
Branch: 3 branches
BranchTrueFalseTotal
$d->{'skipped'} ? : 0 2 2
$d->{'partial'} ? : 0 2 2
$d->{'briefingMissing'} ? : 0 2 2
130 2 ▶ push @lines, ' '.$mark.' '.$d->{key}.' @'.$d->{source}.( defined $d->{via} ? ' via '.$d->{via} : '' ).$note;
Branch: 1 branch
BranchTrueFalseTotal
defined $d->{'via'} ? : 0 2 2
131 }
132 1 for my $w ( @{ $s->{wildcards} } ) {
133 0 ( my $pattern = substr( $w->{entry}, 0, rindex( $w->{entry}, '@' ) ) ) =~ s/\A[a-z]+://;
134 0 push @lines, ' * '.$w->{type}.'s/'.$pattern.' @'.$w->{source}.' ('.$w->{installed}.' installed)';
135 }
136 1 push @lines, ' * bundle:'.$_->{name}.'@'.$_->{source}.' ('.$_->{installed}.' installed)' for @{ $s->{bundles} };
137 1 push @lines, ' ? '.$_.' (in lock, not declared)' for @{ $s->{orphans} };
138 1 push @lines, ' trust: '.$_->{name}.' ('.backend_label($_).')' for @{ $s->{trustRequests} };
139 }
140 1 ▶ push @lines, 'project scope: none (the project directory is the home directory)' if $r->{projectIsHome};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"projectIsHome"} 0 1 1
141 1 ▶ push @lines, 'warning: '.$_ for @{ $r->{warnings} // [] };
Condition50%1/2
$r->{"warnings"} // []
l!l
01
MC/DC0%0/1
$r->{"warnings"} // []
$r->{"warnings"}
Truth table50%1/2
A
A= $r->{"warnings"}
Aresult
11
00
142 1 return join "\n", map { display_safe($_) } @lines;
143 }
144  
145 # The check verdict as `skilletor check` prints it.
146 2 ▶sub check_text {
Subroutine check_text: called CC=3 SCAR=11.7
Pod documented
147 2 my ( $r ) = @_;
148 2 ▶ return display_safe( 'skilletor: '.$r->{error} ) if defined $r->{error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"error"} 0 2 2
149 2 ▶ return $r->{changed} ? 'changed' : 'up to date';
Branch: 1 branch
BranchTrueFalseTotal
$r->{'changed'} ? : 2 0 2
150 }
151  
152 # The CLI's exit code for a report: 2 on an error; `check` 1 when a sync is due; else 0.
153 5 ▶sub exit_code {
Subroutine exit_code: called CC=4 SCAR=13.9
Pod documented
154 5 my ( $op, $r ) = @_;
155 5 ▶ return 2 if defined $r->{error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"error"} 1 4 5
156 4 ▶ return ( $op eq 'check' && $r->{changed} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$op eq 'check' && $r->{'changed'} ? : 2 2 4
Condition66%2/3
$op eq "check" and $r->{"changed"}
!ll&&!rl&&r
202
MC/DC50%1/2
$op eq "check" and $r->{"changed"}
$op eq "check" $r->{"changed"}
Truth table66%2/3
A and B
A= $op eq "check"B= $r->{"changed"}
ABresult
0X0
100
111
157 }
158  
159 31 1;
160  
161 __END__
« Skilletor/Spec.pm ↑ Summary Skilletor/JSON.pm »