bin/anyevent-mcp-askpermission

filter: Statementstmt 58.1% 157 / 270 Branchbran 42.7% 83 / 194 Conditioncond 38.8% 42 / 108 MC/DCmcdc 23.4% 15 / 64 Subroutinesub 80.0% 16 / 20 Podpod n/a totaltotal 47.7% 313 / 656 CC 142 SCAR 54.5
CC
142
Cov
49%
__ANON__
702.0
terminal
534.8
manage_rules
256.4
CRAP 231.7
« blib/lib/AnyEvent/MCP/Permissions/Ask.pm ↑ Summary bin/anyevent-mcp-form-elicitation »
1 #!/opt/bin/perl
2  
3 =head1 NAME
4  
5 anyevent-mcp-askpermission - graphical or terminal permission helper
6  
7 =head1 DESCRIPTION
8  
9 C<anyevent-mcp-askpermission> asks you whether an MCP tool may perform an
10 operation, such as reading a file or running a command. It shows the
11 requested operation and privileges, and lets you allow or deny it once,
12 or choose a rule for future requests.
13  
14 Servers using L<AnyEvent::MCP::Server::Permissions> normally start this
15 helper automatically when a permission check needs your decision. The
16 helper displays a local graphical dialog or asks in a terminal, then
17 returns your choice to the server. You do not normally run it yourself.
18 To change saved rules later, use C<anyevent-mcp manage-rules NAME> or
19 C<anyevent-mcp edit-rules NAME>.
20  
21 =head1 PERMISSION PROMPTS
22  
23 The helper tries YAD first, leaving display backend selection to GTK.
24 If YAD cannot start, it asks on C</dev/tty>. Closing a working dialog,
25 terminal EOF, or having neither interface available means deny once.
26  
27 Server, tool, action, current dimension values and reason are shown as read-only
28 GTK labels when present, including the multibroker alias when available.
29 The requested sandbox grants appear together on one line. The initial YAD
30 form also has a C<Denial reason (optional)> field above four choices:
31 C<Deny once>, C<Deny always...>, C<Allow always...>, C<Allow once>.
32 The persistent rule editor creates a selector for each named permission
33 dimension with multiple offered scopes, using the server's labels and matchers.
34 Single-choice scopes are applied automatically without a selector. For example,
35 the workdir dimension may offer this workdir or any configured workdir.
36 The scopes affect saved rule matching, not the current call's sandbox grants.
37 One-time decisions are on the outside; C<Deny once>
38 uses YAD's default OK response. Closing the dialog also denies once.
39 The persistent choices open a separate rule editor for grant and scope
40 settings, including exact requested-file scope on deny rules. Rules can last
41 indefinitely (the default), 900 seconds or 16 hours. Expired rules disappear
42 when the rules are read and are removed from disk on the next ordinary save.
43 The reason
44 is included in a denial result but is ignored on an allowance.
45  
46 Optional display-only request C<details> maps plain labels to Unicode text,
47 for example C<< { "View patch" => $diff } >>. Each entry appears as a size
48 summary and a button. YAD adds an ellipsis to the label and opens a separate,
49 read-only, resizable, monospace text window without dismissing the approval dialog.
50 Content is written to a private temporary UTF-8 file, never interpolated
51 into a command; control characters are escaped. The helper limits each
52 preview to 65536 Unicode characters and identifies incomplete previews.
53 Terminal and native MCP prompts include the same bounded text inline.
54 Display-only details never constrain or become part of persistent permission rules; an
55 C<allow-always> rule for C<perl -> permits future, different stdin scripts.
56  
57 YAD uses GTK, so you can select a dark theme externally by setting
58 C<GTK_THEME=Adwaita:dark> in the server's environment before starting it.
59 The permission helper inherits that setting and passes it to YAD; the
60 theme is not changed for unrelated applications.
61  
62 In a terminal, the four decisions are single-letter shortcuts and C<m>
63 edits the optional denial reason. Closing the dialog, cancelling or an unavailable
64 terminal denies once. Rule management remains separate:
65 C<anyevent-mcp manage-rules NAME> or C<anyevent-mcp edit-rules NAME>.
66  
67  
68 =head1 HELPER PROTOCOL
69  
70 The helper reads one permission request on stdin and writes one JSON
71 decision on stdout. Servers invoke it through
72 L<AnyEvent::MCP::Permissions::Ask>, which describes the helper interface
73 and how to select a replacement helper. YAD's stderr is suppressed;
74 startup failure is detected from its exit status.
75  
76 =head1 OPTIONS
77  
78 =over
79  
80 =item --manage-rules FILE
81  
82 Open YAD rule list for FILE in evaluation order. Delete or reorder selected
83 rules. File lock protects updates; changes fail if list changed elsewhere.
84 Cannot combine with C<--edit-rules> or prompt-mode flags.
85  
86 =item --edit-rules FILE
87  
88 Edit permission rules in FILE using C<$VISUAL>, C<$EDITOR>,
89 C<sensible-editor> or C<vi>. Does not validate or overwrite editor output.
90 Cannot combine with C<--manage-rules> or prompt-mode flags.
91  
92 =item --tty
93  
94 Prompt only on C</dev/tty>, without YAD fallback. Unavailable terminal
95 denies access. Cannot combine with C<--yad> or rule-management flags.
96  
97 =item --yad
98  
99 Prompt only with YAD, without terminal fallback. Unavailable YAD
100 denies access. Cannot combine with C<--tty> or rule-management flags.
101  
102 =item --help
103  
104 Print short usage synopsis and exit.
105  
106 =back
107  
108 Without explicit C<--tty> or C<--yad>, prompts try YAD first, then
109 C</dev/tty> only if YAD cannot start. Closing or declining a working
110 dialog never triggers fallback.
111  
112 =cut
113  
114 79 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 79 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
117 78 ▶use Text::ParseWords ();
Subroutine BEGIN: called CC=1 SCAR=0.0
118 79 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
119 79 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121 78 ▶use AnyEvent::MCP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
122 78 ▶use AnyEvent::MCP::Permissions::Ask ();
Subroutine BEGIN: called CC=1 SCAR=0.0
123 79 ▶use AnyEvent::MCP::Server::Permissions ();
Subroutine BEGIN: called CC=1 SCAR=0.0
124  
125 Getopt::Long::GetOptions (
126 "manage-rules=s" => \my $rules_file, "edit-rules=s" => \my $edit_file,
127 "tty" => \my $tty_only, "yad" => \my $yad_only, "help" => \my $help,
128 )
129 or exit 2;
130 die "Unexpected arguments\n" if @ARGV || defined $rules_file && defined $edit_file;
131 die "--tty and --yad are mutually exclusive\n" if $tty_only && $yad_only;
132 die "--tty/--yad select permission prompts, not rule management\n"
133 if ($tty_only || $yad_only) && (defined $rules_file || defined $edit_file);
134 if ($help) {
135 print "usage: $0 [--tty | --yad | --manage-rules FILE | --edit-rules FILE]\n";
136 exit;
137 }
138  
139 binmode STDIN;
140 binmode STDOUT;
141  
142 my $json = JSON::XS->new->canonical;
143 my $yad_pid;
144 0 ▶$SIG{TERM} = $SIG{INT} = sub {
Subroutine __ANON__: not called CC=2 SCAR=7.0
145 33 ▶ if ($yad_pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yad_pid) 33 0 33
146 33 kill TERM => $yad_pid;
147 33 waitpid $yad_pid, 0;
148 }
149 33 exit 1;
150 };
151  
152 101 ▶sub yad {
Subroutine yad: called CC=7 SCAR=19.5
153 101 my $pid = open my $fh, "-|";
154 102 ▶ return unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 1 101 102
155 101 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 44 58 102
156 44 ▶ open STDERR, ">", "/dev/null" or exit 127;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">", "/dev/null" or exit 127 44 1 45
157 44 exec "yad", "--no-markup", map AnyEvent::MCP::utf8enc $_, @_;
158 0 exit 127;
159 }
160 57 $yad_pid = $pid;
161 57 local $/;
162 57 my $output = <$fh>;
163 57 close $fh;
164 57 my $status = $?;
165 57 undef $yad_pid;
166  
167 # our buttons never use 1: GTK display failure is not user cancellation.
168 57 ▶ return if $status == 1 << 8 || $status == 127 << 8 || $status & 127;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 256 or $status == 32512 or $status & 127 3 55 58
Condition66%4/6
$status == 256 or $status == 32512 or $status & 127
l!l&&r!l&&!r
3055
$status == 256 or $status == 32512
l!l&&r!l&&!r
4054
MC/DC33%1/3
$status == 256 or $status == 32512 or $status & 127
$status == 256 $status == 32512 $status & 127
Truth table50%2/4
A or B or C
A= $status == 256B= $status == 32512C= $status & 127
ABCresult
1XX1
01X1
0011
0000
169 54 ($status >> 8, AnyEvent::MCP::utf8dec $output)
170 }
171  
172 0 ▶sub manage_rules {
Subroutine manage_rules: not called CC=18 SCAR=55.5
173 0 my ($file) = @_;
174  
175 0 my $permissions = AnyEvent::MCP::Server::Permissions->new;
176 0 $permissions->{file} = $file;
177  
178 0 while (1) {
179 0 my $rules = $permissions->rules;
180 my ($status, $output) = yad (
181 "--list", "--title=MCP permission rules", "--width=900", "--height=450",
182 "--text=$file\nRules are evaluated from top to bottom; the first match wins.",
183 "--column=Order:NUM", "--column=Decision", "--column=Action",
184 "--column=Dimensions", "--column=Sandbox grants", "--column=Expires",
185 "--no-click", "--print-column=1", "--separator=\x1f",
186 "--button=Close:0", "--button=Move up:4",
187 "--button=Move down:6", "--button=Delete selected:2",
188 map {
189 0 my $rule = $rules->[$_];
190 $_ + 1, $rule->{decision} || "ask",
191 (exists $rule->{action} ? $json->encode ($rule->{action}) : "(any)"),
192 0 ▶ (join ", ", map { "$_=" . $json->encode ($rule->{$_}) }
Branch: 2 branches
BranchTrueFalseTotal
exists $rule->{'sandbox-grants'} ? : 0 1 1
exists $rule->{'expires'} ? : 0 0 0
193 sort grep /^match\./, keys %$rule) || "(any)",
194 (exists $rule->{"sandbox-grants"} ? $json->encode ($rule->{"sandbox-grants"}) : "(any)"),
195 0 ▶ (exists $rule->{expires} ? scalar localtime $rule->{expires} : "Indefinite")
Branch: 1 branch
BranchTrueFalseTotal
exists $rule->{'action'} ? : 0 1 1
Condition33%2/6
$rule->{'decision'} || 'ask'
l!l
100
join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule)))) || '(any)'
l!l
100
MC/DC0%0/1
$rule->{'decision'} || 'ask'
$rule->{'decision'}
MC/DC0%0/1
join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule)))) || '(any)'
join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule))))
Truth table50%1/2
A
A= $rule->{'decision'}
Aresult
11
00
Truth table50%1/2
A
A= join(', ', map({"$_=" . $json->encode($rule->{$_});} sort(grep(/^match\./u, keys %$rule))))
Aresult
11
00
196 } 0 .. $#$rules,
197 );
198 0 ▶ die "YAD rule editor unavailable\n" unless defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 1 0 1
199 0 ▶ return unless grep $_ == $status, 2, 4, 6;
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($_ == $status), 2, 4, 6) 1 0 1
200 0 my ($index) = $output =~ /\A([1-9][0-9]*)\x1f?\s*\z/;
201 0 ▶ next unless $index && $index <= @$rules;
Branch: 1 branch
BranchTrueFalseTotal
unless $index and $index <= @$rules 0 0 0
Condition33%1/3
$index and $index <= @$rules
!ll&&!rl&&r
001
MC/DC0%0/2
$index and $index <= @$rules
$index $index <= @$rules
Truth table33%1/3
A and B
A= $indexB= $index <= @$rules
ABresult
0X0
100
111
202 0 ▶ next if $status == 4 && $index == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 4 and $index == 1 0 0 0
Condition0%0/3
$status == 4 and $index == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$status == 4 and $index == 1
$status == 4 $index == 1
Truth table0%0/3
A and B
A= $status == 4B= $index == 1
ABresult
0X0
100
111
203 0 ▶ next if $status == 6 && $index == @$rules;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 6 and $index == @$rules 0 0 0
Condition0%0/3
$status == 6 and $index == @$rules
!ll&&!rl&&r
000
MC/DC0%0/2
$status == 6 and $index == @$rules
$status == 6 $index == @$rules
Truth table0%0/3
A and B
A= $status == 6B= $index == @$rules
ABresult
0X0
100
111
204 0 my $expected = $json->encode ($rules);
205  
206 0 my $ok = eval {
207 0 my $lock = $permissions->_lock;
208 0 my $current = $permissions->rules;
209 0 ▶ die "Permission rules changed since selection\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $json->encode($current) eq $expected 0 0 0
210 unless $json->encode ($current) eq $expected;
211 0 ▶ if ($status == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 2) { } 0 0 0
212 0 splice @$current, $index - 1, 1;
213 } else {
214 0 ▶ my $other = $status == 4 ? $index - 2 : $index;
Branch: 1 branch
BranchTrueFalseTotal
$status == 4 ? : 0 0 0
215 0 @$current[$index - 1, $other] = @$current[$other, $index - 1];
216 }
217  
218 # deletion does not need the application's capability implications.
219 $permissions->{sandbox_grants} = {
220 0 map { map { $_ => [] } split /,/, $_->{"sandbox-grants"} } @$current
221 };
222 0 $permissions->_write ($current);
223 0 1
224 };
225 0 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
226 0 my $error = $@;
227 0 print STDERR $error;
228 0 yad "--title=MCP permission rules", "--text=$error", "--button=Close:0";
229 }
230 }
231 }
232  
233 1 ▶sub edit_rules {
Subroutine edit_rules: called CC=7 SCAR=20.3
234 1 my ($file) = @_;
235  
236 1 my $permissions = AnyEvent::MCP::Server::Permissions->new;
237 1 $permissions->{file} = $file;
238 1 my $lock = $permissions->_lock; # ensure the file exists and is private.
239 1 ▶ close $lock or die "Cannot unlock permission rules: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $lock or die "Cannot unlock permission rules: $!\n" 1 0 1
240  
241 1 ▶ for my $choice (grep { defined && /\S/ } @ENV{qw(VISUAL EDITOR)}, "sensible-editor", "vi") {
Condition33%1/3
defined $_ && /\S/u
!ll&&!rl&&r
004
MC/DC0%0/2
defined $_ && /\S/u
defined $_ /\S/u
Truth table33%1/3
A && B
A= defined $_B= /\S/u
ABresult
0X0
100
111
242 4 my @editor = Text::ParseWords::shellwords ($choice);
243 4 ▶ next unless @editor;
Branch: 1 branch
BranchTrueFalseTotal
unless @editor 0 4 4
244  
245 4 my $status = system { $editor[0] } @editor, AnyEvent::MCP::utf8enc ($file);
246 4 ▶ next if $status == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $status == -1 3 1 4
247  
248 1 ▶ $status == 0
Branch: 1 branch
BranchTrueFalseTotal
$status == 0 or die "Editor failed or was interrupted (status $status)\n" 1 0 1
249 or die "Editor failed or was interrupted (status $status)\n";
250  
251 return
252 1 }
253  
254 0 die "No editor found (VISUAL, EDITOR, sensible-editor, vi)\n"
255 }
256 if (defined $rules_file) {
257 eval { manage_rules AnyEvent::MCP::utf8dec $rules_file; 1 } or do {
258 print STDERR $@;
259 exit 1;
260 };
261 exit;
262 }
263  
264 if (defined $edit_file) {
265 eval { edit_rules AnyEvent::MCP::utf8dec $edit_file; 1 } or do {
266 print STDERR $@;
267 exit 1;
268 };
269 exit;
270 }
271  
272 my $request = do { local $/; JSON::XS::decode_json (scalar <STDIN>) };
273 die "Invalid permission request\n" unless $request->{version} == 1;
274 my $dimensions = $request->{dimensions} || {};
275 my @dimensions = sort keys %$dimensions;
276 my @selectable_dimensions = grep @{$dimensions->{$_}{choices}} > 1, @dimensions;
277 my %decisions = (d => "deny-once", n => "deny-always", o => "allow-once", a => "allow-always");
278 my $persistent = !grep !@{$dimensions->{$_}{choices}}, @dimensions;
279 my @deny_paths = grep defined && !ref, @{$request->{paths} || []};
280 my $unsandboxed = ($request->{sandbox_implementation} || "") =~ /\ANONE/;
281  
282 29 ▶sub rule_dialog {
Subroutine rule_dialog: called CC=32 SCAR=36.9
283 29 my ($choice, $message) = @_;
284  
285 29 my $allow = $choice eq "allow-always";
286 29 my %selected = map { $_ => 1 } @{$request->{sandbox_grants}};
287 my ($status, $output) = yad (
288 "--form", "--title=Create MCP permission rule",
289 "--width=650", "--separator=\x1f", "--item-separator=\x1f",
290 "--num-output", "--always-print-result", "--buttons-layout=edge",
291 "--text=Configure which future requests this rule covers."
292 . (!$allow ? "\nDenial reason: " . (length $message ? $message : "(none)") : ""),
293 "--button=Back:10", "--button=Save rule:8",
294 ($allow ? (map {
295 40 my $grant = $_;
296 40 my $description = $request->{sandbox_grant_descriptions}{$grant};
297 40 ▶ my $label = $grant . (defined $description && length $description ? " - $description" : "");
Branch: 1 branch
BranchTrueFalseTotal
defined $description && length $description ? : 38 2 40
Condition66%2/3
defined $description and length $description
!ll&&!rl&&r
2038
MC/DC50%1/2
defined $description and length $description
defined $description length $description
Truth table66%2/3
A and B
A= defined $descriptionB= length $description
ABresult
0X0
100
111
298 40 $label =~ s/\\/\\\\/g;
299 40 ▶ ("--field=$label:CHK", $selected{$grant} ? "TRUE" : "FALSE")
Branch: 1 branch
BranchTrueFalseTotal
$selected{$grant} ? : 19 21 40
300 19 } @{$request->{sandbox_grant_choices}}) : ()),
301 (map {
302 24 my $dim = $dimensions->{$_};
303 ("--field=$dim->{label} scope:CB", join "\x1f",
304 48 ▶ map { ($_ == 0 ? "^" : "") . ($_ + 1) . ": " . $json->encode ($dim->{choices}[$_]{label}) }
Branch: 1 branch
BranchTrueFalseTotal
$_ == 0 ? : 24 24 48
305 24 ▶ 0 .. $#{$dim->{choices}})
Branch: 1 branch
BranchTrueFalseTotal
!$allow && @deny_paths ? : 4 25 29
Condition100%3/3
not $allow and @deny_paths
!ll&&!rl&&r
1964
MC/DC100%2/2
not $allow and @deny_paths
not $allow @deny_paths
Truth table100%3/3
not(A) and B
A= not $allowB= @deny_paths
ABresult
0X0
100
111
306 } @selectable_dimensions),
307 (!$allow && @deny_paths ? ("--field=Deny file scope:CB", join "\x1f",
308 29 ▶ (map { ($_ == 0 ? "^" : "") . ($_ + 1) . ": Exact file " . $json->encode ($deny_paths[$_]) }
Branch: 4 branches
BranchTrueFalseTotal
!$allow ? : 10 19 29
length $message ? : 10 0 10
$allow ? : 19 10 29
$_ == 0 ? : 4 0 4
309 0 .. $#deny_paths),
310 (@deny_paths + 1) . ": All paths") : ()),
311 "--field=Rule lifetime:CB", "^Indefinite\x1f900 seconds\x1f16 hours",
312 );
313 15 ▶ return { decision => "back" } if $status == 10;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 10 2 13 15
314 13 ▶ return { decision => "deny-once" } unless $status == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 8 0 13 13
315 13 my @values = split /\x1f/, $output, -1;
316 13 ▶ my %answer = (decision => $choice, (!$allow && length $message ? (message => $message) : ()));
Branch: 1 branch
BranchTrueFalseTotal
!$allow && length $message ? : 5 8 13
Condition66%2/3
not $allow and length $message
!ll&&!rl&&r
805
MC/DC50%1/2
not $allow and length $message
not $allow length $message
Truth table66%2/3
not(A) and B
A= not $allowB= length $message
ABresult
0X0
100
111
317 13 ▶ if ($allow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow) 8 5 13
318 8 my @grants;
319 8 for (@{$request->{sandbox_grant_choices}}) {
320 17 my $value = shift @values;
321 17 ▶ die "Invalid YAD sandbox grant selection\n" unless defined $value && $value =~ /\A(?:TRUE|FALSE)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /\A(?:TRUE|FALSE)\z/iu 0 17 17
Condition33%1/3
defined $value and $value =~ /\A(?:TRUE|FALSE)\z/iu
!ll&&!rl&&r
0017
MC/DC0%0/2
defined $value and $value =~ /\A(?:TRUE|FALSE)\z/iu
defined $value $value =~ /\A(?:TRUE|FALSE)\z/iu
Truth table33%1/3
A and B
A= defined $valueB= $value =~ /\A(?:TRUE|FALSE)\z/iu
ABresult
0X0
100
111
322 17 ▶ push @grants, $_ if lc $value eq "true";
Branch: 1 branch
BranchTrueFalseTotal
if lc $value eq "true" 11 6 17
323 }
324 8 $answer{sandbox_grants} = \@grants;
325 }
326 13 for my $name (@selectable_dimensions) {
327 12 my $index = shift @values;
328 die "Invalid YAD dimension scope\n" unless defined $index && $index =~ /\A[1-9][0-9]*\z/
329 12 ▶ && $index <= @{$dimensions->{$name}{choices}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dimensions->{$name}{"choices"};} 0 12 12
Condition33%2/6
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dimensions->{$name}{"choices"};}
!ll&&!rl&&r
0012
defined $index and $index =~ /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
0012
MC/DC0%0/3
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dimensions->{$name}{"choices"};}
defined $index $index =~ /\A[1-9][0-9]*\z/u $index <= @{$dimensions->{$name}{"choices"};}
Truth table25%1/4
A and B and C
A= defined $indexB= $index =~ /\A[1-9][0-9]*\z/uC= $index <= @{$dimensions->{$name}{"choices"};}
ABCresult
0XX0
10X0
1100
1111
330 12 $answer{"dim_$name"} = $dimensions->{$name}{choices}[$index - 1]{match};
331 }
332 13 ▶ if (!$allow && @deny_paths) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $allow and @deny_paths) 2 11 13
Condition100%3/3
not $allow and @deny_paths
!ll&&!rl&&r
832
MC/DC100%2/2
not $allow and @deny_paths
not $allow @deny_paths
Truth table100%3/3
not(A) and B
A= not $allowB= @deny_paths
ABresult
0X0
100
111
333 2 my $index = shift @values;
334 2 ▶ die "Invalid YAD denial file scope\n" unless defined $index && $index =~ /\A[1-9][0-9]*\z/
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1 0 2 2
Condition33%2/6
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
!ll&&!rl&&r
002
defined $index and $index =~ /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
002
MC/DC0%0/3
defined $index and $index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
defined $index $index =~ /\A[1-9][0-9]*\z/u $index <= @deny_paths + 1
Truth table25%1/4
A and B and C
A= defined $indexB= $index =~ /\A[1-9][0-9]*\z/uC= $index <= @deny_paths + 1
ABCresult
0XX0
10X0
1100
1111
335 && $index <= @deny_paths + 1;
336 2 ▶ $answer{path} = $deny_paths[$index - 1] if $index <= @deny_paths;
Branch: 1 branch
BranchTrueFalseTotal
if $index <= @deny_paths 2 0 2
337 }
338 13 my $lifetime = shift @values;
339 13 ▶ defined $lifetime && $lifetime =~ /\A[123]\z/
Branch: 1 branch
BranchTrueFalseTotal
defined $lifetime and $lifetime =~ /\A[123]\z/u or die "Invalid YAD rule lifetime\n" 13 0 13
Condition33%1/3
defined $lifetime and $lifetime =~ /\A[123]\z/u
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $lifetime and $lifetime =~ /\A[123]\z/u
defined $lifetime $lifetime =~ /\A[123]\z/u
Truth table33%1/3
A and B
A= defined $lifetimeB= $lifetime =~ /\A[123]\z/u
ABresult
0X0
100
111
340 or die "Invalid YAD rule lifetime\n";
341 13 $answer{lifetime} = ("indefinite", "900", "57600")[$lifetime - 1];
342  
343 13 \%answer
344 }
345  
346 # display-only details are passed by filename, never through shell source text.
347 72 ▶sub shell_quote {
Subroutine shell_quote: called CC=1 SCAR=0.0
348 72 my $arg = shift;
349  
350 72 $arg =~ s/'/'\\''/g;
351 72 "'$arg'"
352 }
353  
354 78 ▶sub display_text {
Subroutine display_text: called CC=1 SCAR=0.0
355 78 my $text = shift;
356  
357 # render control and bidi characters explicitly, preserving tabs and newlines.
358 78 $text =~ s/([\x00-\x08\x0b-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge;
359 78 $text
360 }
361  
362 70 ▶sub detail_fields {
Subroutine detail_fields: called CC=8 SCAR=21.0
363 70 my @fields;
364  
365 70 ▶ for my $label (sort keys %{$request->{details} || {}}) {
Condition100%2/2
$request->{'details'} || {}
l!l
664
MC/DC100%1/1
$request->{'details'} || {}
$request->{'details'}
Truth table100%2/2
A
A= $request->{'details'}
Aresult
11
00
366 8 my $text = $request->{details}{$label};
367 8 ▶ defined $text && !ref $text
Branch: 1 branch
BranchTrueFalseTotal
defined $text and not ref $text or die "Invalid permission detail\n" 8 0 8
Condition33%1/3
defined $text and not ref $text
!ll&&!rl&&r
008
MC/DC0%0/2
defined $text and not ref $text
defined $text not ref $text
Truth table33%1/3
A and not(B)
A= defined $textB= not ref $text
ABresult
0X0
100
111
368 or die "Invalid permission detail\n";
369  
370 8 my $preview = AnyEvent::MCP::Permissions::Ask::detail_text $label, $text;
371 8 my $chars = length $text;
372 8 my $bytes = length AnyEvent::MCP::utf8enc $text;
373  
374 8 my ($fh, $filename) = File::Temp::tempfile (
375 "mcp-permission-XXXXXXXX", TMPDIR => 1, UNLINK => 1);
376 8 binmode $fh;
377 8 ▶ print {$fh} AnyEvent::MCP::utf8enc ($preview)
Branch: 1 branch
BranchTrueFalseTotal
print {$fh;} &AnyEvent::MCP::utf8enc($preview) or die "Cannot write permission detail: $!\n" 8 0 8
378 or die "Cannot write permission detail: $!\n";
379 8 ▶ close $fh or die "Cannot close permission detail: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Cannot close permission detail: $!\n" 8 0 8
380  
381 8 $label = display_text $label;
382 8 $label =~ s/[:\t\n]/sprintf "\\u{%X}", ord $&/ge;
383 8 ▶ my $info = "$label: $chars characters, $bytes UTF-8 bytes"
Branch: 1 branch
BranchTrueFalseTotal
$chars > 65536 ? : 2 6 8
384 . ($chars > 65536 ? " (incomplete preview)" : "");
385 8 $info =~ s/\\/\\\\/g;
386 8 my $button = $label;
387 8 $button =~ s/\\/\\\\/g;
388  
389 8 push @fields,
390 "--field=$info:LBL", "",
391 "--field=$button...:FBTN",
392 join " ", map shell_quote ($_),
393 ("yad", "--no-markup", "--text-info",
394 "--title=MCP permission: $label", "--width=900", "--height=650",
395 "--fontname=Monospace 11", "--filename=$filename",
396 "--button=Close:0");
397 }
398  
399 @fields
400 70 }
401  
402 76 ▶sub graphical {
Subroutine graphical: called CC=25 SCAR=32.4
403 76 ▶ if (($request->{_permission_stage} || "") eq "rule") {
Branch: 1 branch
BranchTrueFalseTotal
if (($request->{"_permission_stage"} || "") eq "rule") 6 70 76
Condition100%2/2
$request->{'_permission_stage'} || ''
l!l
1066
MC/DC100%1/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
Truth table100%2/2
A
A= $request->{'_permission_stage'}
Aresult
11
00
404 6 my $previous = $request->{_permission_selection};
405 6 ▶ return rule_dialog ($previous->{decision}, $previous->{message} // "");
Condition100%2/2
$previous->{"message"} // ""
l!l
42
MC/DC100%1/1
$previous->{"message"} // ""
$previous->{"message"}
Truth table100%2/2
A
A= $previous->{"message"}
Aresult
11
00
406 }
407  
408 my @details = map {
409 165 my $value = $request->{$_};
410 165 ▶ $value = $_ eq "reason" ? display_text ($value)
Branch: 2 branches
BranchTrueFalseTotal
$_ eq 'reason' ? : 70 95 165
ref $value || $value =~ /[\x00-\x1f\x7f]/u ? : 9 86 95
Condition66%2/3
ref $value or $value =~ /[\x00-\x1f\x7f]/u
l!l&&r!l&&!r
9086
MC/DC50%1/2
ref $value or $value =~ /[\x00-\x1f\x7f]/u
ref $value $value =~ /[\x00-\x1f\x7f]/u
Truth table66%2/3
A or B
A= ref $valueB= $value =~ /[\x00-\x1f\x7f]/u
ABresult
1X1
011
000
411 : ref $value || $value =~ /[\x00-\x1f\x7f]/ ? $json->encode ($value) : $value;
412 165 $value =~ s/\\/\\\\/g;
413 ({
414 name => "Server",
415 multibroker_alias => "Multibroker alias",
416 tool => "Tool",
417 action => "Action",
418 action_description => "Action description",
419 sandbox_implementation => "Sandbox",
420 paths => "Paths",
421 reason => "Reason",
422 165 ▶ }->{$_} || ucfirst $_) . ": $value"
Condition33%1/3
{'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_} || ucfirst $_
l!l&&r!l&&!r
16500
MC/DC0%0/2
{'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_} || ucfirst $_
{'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_} ucfirst $_
Truth table33%1/3
A || B
A= {'name', 'Server', 'multibroker_alias', 'Multibroker alias', 'tool', 'Tool', 'action', 'Action', 'action_description', 'Action description', 'sandbox_implementation', 'Sandbox', 'paths', 'Paths', 'reason', 'Reason'}->{$_}B= ucfirst $_
ABresult
1X1
011
000
423 70 } grep defined $request->{$_},
424 qw(name multibroker_alias tool action action_description
425 sandbox_implementation paths reason);
426 push @details, map {
427 70 my $dim = $dimensions->{$_};
428 "$dim->{label}: " . $json->encode ($dim->{value})
429 67 } @dimensions;
430  
431 70 my @view_fields = detail_fields;
432 70 ▶ my $message = $request->{_permission_selection}{message} // "";
Condition50%1/2
$request->{"_permission_selection"}{"message"} // ""
l!l
070
MC/DC0%0/1
$request->{"_permission_selection"}{"message"} // ""
$request->{"_permission_selection"}{"message"}
Truth table50%1/2
A
A= $request->{"_permission_selection"}{"message"}
Aresult
11
00
433 70 while (1) {
434 my ($status, $output) = yad (
435 "--form", ($unsandboxed ? "--title=UNSANDBOXED MCP permission required"
436 : "--title=MCP permission required"),
437 "--width=650", "--height=400", "--scroll",
438 "--text=" . ($unsandboxed
439 ? "WARNING: NO SANDBOX. Workers run with all privileges of the host user.\n"
440 : "")
441 72 ▶ . "Required grants: " . (join " ", @{$request->{sandbox_grants}}),
Branch: 2 branches
BranchTrueFalseTotal
$persistent ? : 72 0 72
$persistent ? : 72 0 72
442 "--separator=\x1f", "--item-separator=\x1f", "--num-output", "--always-print-result",
443 "--focus-field=" . (@details + @view_fields / 2 + 1),
444 "--buttons-layout=edge",
445 "--button=Deny once:0",
446 ($persistent ? ("--button=Deny always...:6") : ()),
447 ($persistent ? ("--button=Allow always...:8") : ()),
448 "--button=Allow once:4",
449 72 ▶ (map { ("--field=$_:LBL", "") } @details),
Branch: 2 branches
BranchTrueFalseTotal
$unsandboxed ? : 2 70 72
$unsandboxed ? : 2 70 72
450 @view_fields,
451 "--field=Denial reason (optional)", $message,
452 );
453 42 ▶ return unless defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 3 39 42
454 39 ▶ return { decision => "deny-once" } unless grep $_ == $status, 0, 4, 6, 8;
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($_ == $status), 0, 4, 6, 8) 2 37 39
455 37 $message = (split /\x1f/, $output, -1)[@details + @view_fields / 2];
456 37 ▶ die "Missing permission message field\n" unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 37 37
457 37 $message =~ s/\r?\n\z//;
458  
459 my $choice = {
460 0 => "deny-once",
461 4 => "allow-once",
462 6 => "deny-always",
463 8 => "allow-always",
464 37 }->{$status};
465 37 ▶ if ($choice =~ /-always\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($choice =~ /-always\z/u) 25 12 37
466 return { decision => $choice,
467 ($choice eq "deny-always" && length $message ? (message => $message) : ()),
468 25 ▶ } if ($request->{_permission_stage} || "") eq "choice";
Branch: 2 branches
BranchTrueFalseTotal
if ($request->{"_permission_stage"} || "") eq "choice" 2 23 25
$choice eq 'deny-always' && length $message ? : 1 1 2
Condition80%4/5
$request->{'_permission_stage'} || ''
l!l
223
$choice eq "deny-always" and length $message
!ll&&!rl&&r
101
MC/DC100%1/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
MC/DC50%1/2
$choice eq "deny-always" and length $message
$choice eq "deny-always" length $message
Truth table100%2/2
A
A= $request->{'_permission_stage'}
Aresult
11
00
Truth table66%2/3
A and B
A= $choice eq "deny-always"B= length $message
ABresult
0X0
100
111
469  
470 23 my $answer = rule_dialog ($choice, $message);
471 12 ▶ next if $answer->{decision} eq "back";
Branch: 1 branch
BranchTrueFalseTotal
if $answer->{"decision"} eq "back" 2 10 12
472 10 return $answer;
473 }
474 return {
475 decision => $choice,
476 ($status == 0 && length $message ? (message => $message) : ()),
477 12 ▶ ($status == 4 ? (sandbox_grants => [@{$request->{sandbox_grants}}]) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$status == 0 && length $message ? : 2 10 12
$status == 4 ? : 6 6 12
Condition100%3/3
$status == 0 and length $message
!ll&&!rl&&r
642
MC/DC100%2/2
$status == 0 and length $message
$status == 0 length $message
Truth table100%3/3
A and B
A= $status == 0B= length $message
ABresult
0X0
100
111
478 };
479 }
480 }
481  
482 3 ▶sub terminal {
Subroutine terminal: called CC=23 SCAR=62.8
483 3 ▶ open my $tty, "+<", "/dev/tty" or return { decision => "deny-once" };
Branch: 1 branch
BranchTrueFalseTotal
open my $tty, "+<", "/dev/tty" or return {"decision", "deny-once"} 0 3 3
484 0 binmode $tty, ":encoding(UTF-8)";
485 0 select ((select ($tty), $| = 1)[0]);
486  
487 0 ▶ my $ask = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
488 0 ▶ print {$tty} $_[0] or die "Permission terminal: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
print {$tty;} $_[0] or die "Permission terminal: $!\n" 0 0 0
489 0 my $answer = <$tty>;
490 0 ▶ $answer =~ s/\s+\z// if defined $answer;
Branch: 1 branch
BranchTrueFalseTotal
if defined $answer 0 0 0
491 0 $answer
492 0 };
493  
494 0 ▶ my $message = $request->{_permission_selection}{message} // "";
Condition0%0/2
$request->{"_permission_selection"}{"message"} // ""
l!l
00
MC/DC0%0/1
$request->{"_permission_selection"}{"message"} // ""
$request->{"_permission_selection"}{"message"}
Truth table0%0/2
A
A= $request->{"_permission_selection"}{"message"}
Aresult
11
00
495 0 ▶ my $rule = sub {
Subroutine __ANON__: not called CC=26 SCAR=65.5
496 0 my ($choice) = @_;
497  
498 0 ▶ print {$tty} "Denial reason: ", (length $message ? $message : "(none)"), "\n"
Branch: 2 branches
BranchTrueFalseTotal
if $choice eq "deny-always" 0 0 0
length $message ? : 0 0 0
499 if $choice eq "deny-always";
500 0 ▶ return { decision => "back" } if (($ask->("Configure future rule [Enter=continue, b=back]: ") // "b") eq "b");
Branch: 1 branch
BranchTrueFalseTotal
if (&$ask("Configure future rule [Enter=continue, b=back]: ") // "b") eq "b" 0 0 0
Condition0%0/2
&$ask("Configure future rule [Enter=continue, b=back]: ") // "b"
l!l
00
MC/DC0%0/1
&$ask("Configure future rule [Enter=continue, b=back]: ") // "b"
&$ask("Configure future rule [Enter=continue, b=back]: ")
Truth table0%0/2
A
A= &$ask("Configure future rule [Enter=continue, b=back]: ")
Aresult
11
00
501 0 ▶ my %answer = (decision => $choice,
Branch: 1 branch
BranchTrueFalseTotal
$choice eq 'deny-always' && length $message ? : 0 0 0
Condition0%0/3
$choice eq "deny-always" and length $message
!ll&&!rl&&r
000
MC/DC0%0/2
$choice eq "deny-always" and length $message
$choice eq "deny-always" length $message
Truth table0%0/3
A and B
A= $choice eq "deny-always"B= length $message
ABresult
0X0
100
111
502 ($choice eq "deny-always" && length $message ? (message => $message) : ()));
503 0 ▶ if ($choice eq "allow-always") {
Branch: 1 branch
BranchTrueFalseTotal
if ($choice eq "allow-always") 0 0 0
504 0 print {$tty} "Available grants: ", join (", ", @{$request->{sandbox_grant_choices}}), "\n";
505 0 my $caps = $ask->("Allowed grants [" . (join ",", @{$request->{sandbox_grants}}) . "]: ");
506 0 ▶ return { decision => "deny-once" } unless defined $caps;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $caps 0 0 0
507 $answer{sandbox_grants} = [length $caps
508 ? ($caps eq "-" ? () : split /\s*,\s*/, $caps, -1)
509 0 ▶ : @{$request->{sandbox_grants}}];
Branch: 2 branches
BranchTrueFalseTotal
length $caps ? : 0 0 0
$caps eq '-' ? : 0 0 0
510 }
511 0 for my $name (@selectable_dimensions) {
512 0 my $dim = $dimensions->{$name};
513 0 print {$tty} "$dim->{label} scope:\n",
514 0 map { ($_ + 1) . ": " . $json->encode ($dim->{choices}[$_]{label}) . "\n" }
515 0 0 .. $#{$dim->{choices}};
516 0 my $index = $ask->("$dim->{label} scope [1]: ");
517 0 ▶ return { decision => "deny-once" } unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 0 0
518 0 ▶ $index = 1 unless length $index;
Branch: 1 branch
BranchTrueFalseTotal
unless length $index 0 0 0
519 0 ▶ die "Invalid dimension scope\n" unless $index =~ /\A[1-9][0-9]*\z/ && $index <= @{$dim->{choices}};
Branch: 1 branch
BranchTrueFalseTotal
unless $index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dim->{"choices"};} 0 0 0
Condition0%0/3
$index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dim->{"choices"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$index =~ /\A[1-9][0-9]*\z/u and $index <= @{$dim->{"choices"};}
$index =~ /\A[1-9][0-9]*\z/u $index <= @{$dim->{"choices"};}
Truth table0%0/3
A and B
A= $index =~ /\A[1-9][0-9]*\z/uB= $index <= @{$dim->{"choices"};}
ABresult
0X0
100
111
520 0 $answer{"dim_$name"} = $dim->{choices}[$index - 1]{match};
521 }
522 0 ▶ if ($choice eq "deny-always" && @deny_paths) {
Branch: 1 branch
BranchTrueFalseTotal
if ($choice eq "deny-always" and @deny_paths) 0 0 0
Condition0%0/3
$choice eq "deny-always" and @deny_paths
!ll&&!rl&&r
000
MC/DC0%0/2
$choice eq "deny-always" and @deny_paths
$choice eq "deny-always" @deny_paths
Truth table0%0/3
A and B
A= $choice eq "deny-always"B= @deny_paths
ABresult
0X0
100
111
523 0 print {$tty} map { ($_ + 1) . ": " . $json->encode ($deny_paths[$_]) . "\n" }
524 0 .. $#deny_paths;
525 0 print {$tty} (@deny_paths + 1) . ": All paths\n";
526 0 my $index = $ask->("Deny file scope [1]: ");
527 0 ▶ return { decision => "deny-once" } unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 0 0
528 0 ▶ $index = 1 unless length $index;
Branch: 1 branch
BranchTrueFalseTotal
unless length $index 0 0 0
529 0 ▶ die "Invalid deny file scope\n" unless $index =~ /\A[1-9][0-9]*\z/
Branch: 1 branch
BranchTrueFalseTotal
unless $index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1 0 0 0
Condition0%0/3
$index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
!ll&&!rl&&r
000
MC/DC0%0/2
$index =~ /\A[1-9][0-9]*\z/u and $index <= @deny_paths + 1
$index =~ /\A[1-9][0-9]*\z/u $index <= @deny_paths + 1
Truth table0%0/3
A and B
A= $index =~ /\A[1-9][0-9]*\z/uB= $index <= @deny_paths + 1
ABresult
0X0
100
111
530 && $index <= @deny_paths + 1;
531 0 ▶ $answer{path} = $deny_paths[$index - 1] if $index <= @deny_paths;
Branch: 1 branch
BranchTrueFalseTotal
if $index <= @deny_paths 0 0 0
532 }
533 0 my $lifetime = $ask->("Rule lifetime [1=indefinite, 2=900 seconds, 3=16 hours; default 1]: ");
534 0 ▶ return { decision => "deny-once" } unless defined $lifetime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lifetime 0 0 0
535 0 ▶ $lifetime = 1 unless length $lifetime;
Branch: 1 branch
BranchTrueFalseTotal
unless length $lifetime 0 0 0
536 0 ▶ $lifetime =~ /\A[123]\z/ or die "Invalid rule lifetime\n";
Branch: 1 branch
BranchTrueFalseTotal
$lifetime =~ /\A[123]\z/u or die "Invalid rule lifetime\n" 0 0 0
537 0 $answer{lifetime} = ("indefinite", "900", "57600")[$lifetime - 1];
538  
539 0 \%answer
540 0 };
541  
542 0 ▶ if (($request->{_permission_stage} || "") eq "rule") {
Branch: 1 branch
BranchTrueFalseTotal
if (($request->{"_permission_stage"} || "") eq "rule") 0 0 0
Condition0%0/2
$request->{'_permission_stage'} || ''
l!l
00
MC/DC0%0/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
Truth table0%0/2
A
A= $request->{'_permission_stage'}
Aresult
11
00
543 0 return $rule->($request->{_permission_selection}{decision});
544 }
545  
546 0 print {$tty} "\n\n******** MCP PERMISSION REQUIRED ********\n\n",
547 AnyEvent::MCP::Permissions::Ask::message ($request),
548 "\n\nThis is an approval prompt. No decision has been made.\n";
549  
550 0 while (1) {
551 0 ▶ print {$tty} "\nDenial reason: ", (length $message ? $message : "(none)"), "\n",
Branch: 2 branches
BranchTrueFalseTotal
length $message ? : 0 0 0
$persistent ? : 0 0 0
552 " m edit denial reason\n",
553 " o allow once d deny once (default)\n",
554 ($persistent ? " a allow always... n deny always...\n" : "");
555 0 my $choice = $ask->("Choice [d]: ");
556 0 ▶ return { decision => "deny-once" } unless defined $choice;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $choice 0 0 0
557 0 ▶ $choice = "d" unless length $choice;
Branch: 1 branch
BranchTrueFalseTotal
unless length $choice 0 0 0
558  
559 0 ▶ if ($choice eq "m") {
Branch: 1 branch
BranchTrueFalseTotal
if ($choice eq "m") 0 0 0
560 0 my $text = $ask->("Denial reason (Enter clears): ");
561 0 ▶ return { decision => "deny-once" } unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
562 0 $message = $text;
563 0 next;
564 }
565  
566 0 ▶ next unless exists $decisions{$choice};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $decisions{$choice} 0 0 0
567 0 ▶ next if !$persistent && $choice =~ /[na]/;
Branch: 1 branch
BranchTrueFalseTotal
if not $persistent and $choice =~ /[na]/u 0 0 0
Condition0%0/3
not $persistent and $choice =~ /[na]/u
!ll&&!rl&&r
000
MC/DC0%0/2
not $persistent and $choice =~ /[na]/u
not $persistent $choice =~ /[na]/u
Truth table0%0/3
not(A) and B
A= not $persistentB= $choice =~ /[na]/u
ABresult
0X0
100
111
568 0 my $decision = $decisions{$choice};
569 0 ▶ if ($decision =~ /-always\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decision =~ /-always\z/u) 0 0 0
570 return { decision => $decision,
571 ($decision eq "deny-always" && length $message ? (message => $message) : ()),
572 0 ▶ } if ($request->{_permission_stage} || "") eq "choice";
Branch: 2 branches
BranchTrueFalseTotal
if ($request->{"_permission_stage"} || "") eq "choice" 0 0 0
$decision eq 'deny-always' && length $message ? : 0 0 0
Condition0%0/5
$request->{'_permission_stage'} || ''
l!l
00
$decision eq "deny-always" and length $message
!ll&&!rl&&r
000
MC/DC0%0/1
$request->{'_permission_stage'} || ''
$request->{'_permission_stage'}
MC/DC0%0/2
$decision eq "deny-always" and length $message
$decision eq "deny-always" length $message
Truth table0%0/2
A
A= $request->{'_permission_stage'}
Aresult
11
00
Truth table0%0/3
A and B
A= $decision eq "deny-always"B= length $message
ABresult
0X0
100
111
573  
574 0 my $answer = $rule->($decision);
575 0 ▶ next if $answer->{decision} eq "back";
Branch: 1 branch
BranchTrueFalseTotal
if $answer->{"decision"} eq "back" 0 0 0
576 0 return $answer;
577 }
578 return {
579 decision => $decision,
580 ($choice eq "d" && length $message ? (message => $message) : ()),
581 0 ▶ ($choice eq "o" ? (sandbox_grants => [@{$request->{sandbox_grants}}]) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$choice eq 'd' && length $message ? : 0 0 0
$choice eq 'o' ? : 0 0 0
Condition0%0/3
$choice eq "d" and length $message
!ll&&!rl&&r
000
MC/DC0%0/2
$choice eq "d" and length $message
$choice eq "d" length $message
Truth table0%0/3
A and B
A= $choice eq "d"B= length $message
ABresult
0X0
100
111
582 };
583 }
584 }
585  
586 my $decision = eval {
587 my $answer = $tty_only ? terminal : graphical;
588 $answer = $yad_only ? { decision => "deny-once" } : terminal unless $answer;
589 AnyEvent::MCP::Permissions::Ask::build ($request, $answer,
590 $request->{_permission_stage}, $request->{_permission_selection})
591 };
592 if ($@) {
593 print STDERR "Permission prompt failed; denied: $@";
594 $decision = { decision => "deny-once" };
595 }
596 print JSON::XS::encode_json ($decision), "\n";
« blib/lib/AnyEvent/MCP/Permissions/Ask.pm ↑ Summary bin/anyevent-mcp-form-elicitation »