Agent/Query.pm

filter: Statementstmt 80.2% 586 / 730 Branchbran 70.6% 294 / 416 Conditioncond 57.8% 147 / 254 MC/DCmcdc 33.5% 51 / 152 Subroutinesub 74.5% 88 / 118 Podpod 94.7% 36 / 38 totaltotal 70.3% 1202 / 1708 CC 315 SCAR 30.6
CC
315
Cov
73%
_build_command
73.0
_handle_line
38.9
_start_process
31.3
CRAP 21.4
« Agent/DryRun.pm ↑ Summary Agent/Hook/Matcher.pm »
1 package Claude::Agent::Query;
2  
3 8 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Object::Proto ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use IO::Async::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use JSON::Lines;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use File::Which qw(which);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use Crypt::URandom ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶use Claude::Agent::Logger '$log';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use Claude::Agent::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use Claude::Agent::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use Claude::Agent::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶use Claude::Agent::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶use Claude::Agent::Permission;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 8 ▶use Claude::Agent::Hook::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 8 ▶use Claude::Agent::MCP::SDKBridge;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 ▶use Claude::Agent::DryRun qw(create_dry_run_hooks);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 8 our $MINIMUM_CLAUDE_CODE_VERSION = '2.1.0';
29 8 our $ENTRYPOINT = 'sdk-perl';
30  
31 sub DEMOLISH;
32  
33 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 8 Object::Proto::define('Claude::Agent::Query',
35 'prompt:predicate',
36 'options:lazy:builder(_build_options)',
37 'loop:predicate',
38 'persistent:Bool:default(0)',
39 'spawn:Bool:default(1)',
40 'writer:predicate',
41 'closer:predicate',
42 '_loop',
43 '_process',
44 '_stdin',
45 '_cli_path',
46 '_messages:ArrayRef:default([])',
47 '_pending_futures:ArrayRef:default([])',
48 '_session_id',
49 '_finished:Bool:default(0)',
50 '_error',
51 '_exit_future',
52 '_hook_registry',
53 '_sdk_bridges:HashRef:default({})',
54 '_request_counter:Int:default(0)',
55 '_pending_control:HashRef:default({})',
56 '_inflight_requests:HashRef:default({})',
57 '_init_result',
58 '_result_received:Bool:default(0)',
59 '_session_state',
60 '_run_end_timer',
61 '_turn_in_progress:Bool:default(0)',
62 '_stdin_closed:Bool:default(0)',
63 '_closed:Bool:default(0)',
64 '_processing_message:Bool:default(0)',
65 '_jsonl:lazy:builder(_build_jsonl)',
66 );
67 }
68  
69 8 my %CONSUMED = map { $_ => 1 } qw(keep_alive control_response control_request control_cancel_request);
70  
71 3 ▶sub _build_options { Claude::Agent::Options->new }
Subroutine _build_options: called CC=1 SCAR=0.0
72  
73 59 ▶sub _build_jsonl {
Subroutine _build_jsonl: called CC=1 SCAR=3.5
74 return JSON::Lines->new(
75 utf8 => 1,
76 0 ▶ error_cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 my ($action, $error) = @_;
78 0 $log->trace("JSON::Lines $action error: $error");
79 0 return;
80 },
81 59 );
82 }
83  
84 61 ▶sub BUILD {
Subroutine BUILD: called CC=19 SCAR=31.6
Pod undocumented
85 61 my ($self) = @_;
86  
87 61 ▶ $self->_loop($self->has_loop ? $self->loop : IO::Async::Loop->new);
Branch: 1 branch
BranchTrueFalseTotal
$self->has_loop ? : 60 1 61
88 61 $self->_exit_future($self->_loop->new_future);
89  
90 61 ▶ if ($self->has_prompt && ref $self->prompt && ref $self->prompt ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_prompt and ref $self->prompt and ref $self->prompt ne "ARRAY") 1 60 61
Condition100%6/6
$self->has_prompt and ref $self->prompt and ref $self->prompt ne "ARRAY"
!ll&&!rl&&r
5911
$self->has_prompt and ref $self->prompt
!ll&&!rl&&r
4552
MC/DC100%3/3
$self->has_prompt and ref $self->prompt and ref $self->prompt ne "ARRAY"
$self->has_prompt ref $self->prompt ref $self->prompt ne "ARRAY"
Truth table100%4/4
A and B and C
A= $self->has_promptB= ref $self->promptC= ref $self->prompt ne "ARRAY"
ABCresult
0XX0
10X0
1100
1111
91 1 Carp::croak("prompt must be a string or an array of content blocks");
92 }
93  
94 60 my $opts = $self->options;
95  
96 60 my %hooks;
97 60 ▶ if ($opts->has_hooks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->has_hooks) 3 57 60
98 3 ▶ $hooks{$_} = [ @{ $opts->hooks->{$_} // [] } ] for keys %{$opts->hooks};
Condition50%1/2
$opts->hooks->{$_} // []
l!l
30
MC/DC0%0/1
$opts->hooks->{$_} // []
$opts->hooks->{$_}
Truth table50%1/2
A
A= $opts->hooks->{$_}
Aresult
11
00
99 }
100 60 ▶ if ($opts->has_dry_run && $opts->dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->has_dry_run and $opts->dry_run) 0 60 60
Condition33%1/3
$opts->has_dry_run and $opts->dry_run
!ll&&!rl&&r
6000
MC/DC0%0/2
$opts->has_dry_run and $opts->dry_run
$opts->has_dry_run $opts->dry_run
Truth table33%1/3
A and B
A= $opts->has_dry_runB= $opts->dry_run
ABresult
0X0
100
111
101 0 ▶ my $dry = create_dry_run_hooks($opts->has_on_dry_run ? $opts->on_dry_run : undef);
Branch: 1 branch
BranchTrueFalseTotal
$opts->has_on_dry_run ? : 0 0 0
102 0 for my $event (keys %$dry) {
103 0 ▶ unshift @{ $hooks{$event} //= [] }, @{$dry->{$event}};
Condition0%0/2
$hooks{$event} //= []
l!l
00
MC/DC0%0/1
$hooks{$event} //= []
$hooks{$event}
Truth table0%0/2
A
A= $hooks{$event}
Aresult
11
00
104 }
105 0 $log->debug("Dry-run mode enabled");
106 }
107 60 ▶ if (%hooks) {
Branch: 1 branch
BranchTrueFalseTotal
if (%hooks) 3 57 60
108 3 $self->_hook_registry(Claude::Agent::Hook::Registry->new(
109 hooks => \%hooks,
110 loop => $self->_loop,
111 query => $self,
112 ));
113 3 $log->debug(sprintf("Hooks registered for: %s", join(', ', sort keys %hooks)));
114 }
115  
116 60 ▶ if ($opts->has_mcp_servers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->has_mcp_servers) 3 57 60
117 3 for my $name (sort keys %{$opts->mcp_servers}) {
118 5 my $server = $opts->mcp_servers->{$name};
119 5 ▶ next unless blessed($server) && $server->can('type') && $server->type eq 'sdk';
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($server) and $server->can("type") and $server->type eq "sdk" 3 2 5
Condition83%5/6
builtin::blessed($server) and $server->can("type") and $server->type eq "sdk"
!ll&&!rl&&r
122
builtin::blessed($server) and $server->can("type")
!ll&&!rl&&r
104
MC/DC66%2/3
builtin::blessed($server) and $server->can("type") and $server->type eq "sdk"
builtin::blessed($server) $server->can("type") $server->type eq "sdk"
Truth table75%3/4
A and B and C
A= builtin::blessed($server)B= $server->can("type")C= $server->type eq "sdk"
ABCresult
0XX0
10X0
1100
1111
120 2 $self->_sdk_bridges->{$name} = Claude::Agent::MCP::SDKBridge->new(
121 server => $server,
122 loop => $self->_loop,
123 );
124 }
125 }
126  
127 60 $self->_start_process;
128 59 return;
129 }
130  
131 20 ▶sub DEMOLISH {
Subroutine DEMOLISH: called CC=3 SCAR=14.2
Pod undocumented
132 20 my ($self) = @_;
133 20 ▶ return if $self->_finished || !$self->_process;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_finished or not $self->_process 20 0 20
Condition66%2/3
$self->_finished or not $self->_process
l!l&&r!l&&!r
6140
MC/DC0%0/2
$self->_finished or not $self->_process
$self->_finished not $self->_process
Truth table66%2/3
A or not(B)
A= $self->_finishedB= not $self->_process
ABresult
1X1
011
000
134 0 eval { $self->_process->kill('TERM') };
135 0 return;
136 }
137  
138 1 ▶sub _find_claude_cli {
Subroutine _find_claude_cli: called CC=10 SCAR=26.7
139 1 my ($self) = @_;
140  
141 1 ▶ return $self->options->cli_path if $self->options->has_cli_path;
Branch: 1 branch
BranchTrueFalseTotal
if $self->options->has_cli_path 0 1 1
142  
143 1 my $claude = which('claude');
144 1 ▶ return $claude if $claude;
Branch: 1 branch
BranchTrueFalseTotal
if $claude 0 1 1
145  
146 1 my @paths = ('/usr/local/bin/claude', '/opt/homebrew/bin/claude');
147 1 ▶ if ($ENV{HOME} && $ENV{HOME} =~ m{^/}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HOME"} and $ENV{"HOME"} =~ m[^/]u) 1 0 1
Condition33%1/3
$ENV{"HOME"} and $ENV{"HOME"} =~ m[^/]u
!ll&&!rl&&r
001
MC/DC0%0/2
$ENV{"HOME"} and $ENV{"HOME"} =~ m[^/]u
$ENV{"HOME"} $ENV{"HOME"} =~ m[^/]u
Truth table33%1/3
A and B
A= $ENV{"HOME"}B= $ENV{"HOME"} =~ m[^/]u
ABresult
0X0
100
111
148 1 require Cwd;
149 1 my $home = Cwd::abs_path($ENV{HOME});
150 1 ▶ if ($home && $home =~ m{^/} && -d $home) {
Branch: 1 branch
BranchTrueFalseTotal
if ($home and $home =~ m[^/]u and -d $home) 1 0 1
Condition33%2/6
$home and $home =~ m[^/]u and -d $home
!ll&&!rl&&r
001
$home and $home =~ m[^/]u
!ll&&!rl&&r
001
MC/DC0%0/3
$home and $home =~ m[^/]u and -d $home
$home $home =~ m[^/]u -d $home
Truth table25%1/4
A and B and C
A= $homeB= $home =~ m[^/]uC= -d $home
ABCresult
0XX0
10X0
1100
1111
151 1 push @paths, File::Spec->catfile($home, '.local', 'bin', 'claude');
152 1 push @paths, File::Spec->catfile($home, '.npm-global', 'bin', 'claude');
153 }
154 }
155 1 for my $path (@paths) {
156 4 ▶ return $path if -x $path;
Branch: 1 branch
BranchTrueFalseTotal
if -x $path 0 4 4
157 }
158  
159 Claude::Agent::Error::CLINotFound->throw(
160 1 message => "Could not find 'claude' CLI in PATH or common locations"
161 );
162 0 return;
163 }
164  
165 8 my %VERSION_CHECKED;
166  
167 5 ▶sub _check_claude_version {
Subroutine _check_claude_version: called CC=10 SCAR=23.1
168 5 my ($self, $cli) = @_;
169  
170 5 ▶ return if $ENV{CLAUDE_AGENT_SDK_SKIP_VERSION_CHECK};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"CLAUDE_AGENT_SDK_SKIP_VERSION_CHECK"} 1 4 5
171 4 ▶ return if exists $VERSION_CHECKED{$cli};
Branch: 1 branch
BranchTrueFalseTotal
if exists $VERSION_CHECKED{$cli} 1 3 4
172 3 $VERSION_CHECKED{$cli} = undef;
173  
174 3 my $future = $self->_loop->new_future;
175 3 my $ok = eval {
176 $self->_loop->run_child(
177 command => [$cli, '-v'],
178 3 ▶ on_finish => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
179 3 my ($pid, $exitcode, $stdout, $stderr) = @_;
180 3 ▶ $future->done($exitcode, $stdout, $stderr) unless $future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 3 0 3
181 },
182 3 );
183 3 1;
184 };
185 3 ▶ return unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 3 3
186 3 $self->_await($future, 2);
187 3 ▶ return unless $future->is_done;
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_done 0 3 3
188  
189 3 my (undef, $stdout) = $future->get;
190 3 ▶ return unless defined $stdout && $stdout =~ /(\d+)\.(\d+)\.(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stdout and $stdout =~ /(\d+)\.(\d+)\.(\d+)/u 1 2 3
Condition66%2/3
defined $stdout and $stdout =~ /(\d+)\.(\d+)\.(\d+)/u
!ll&&!rl&&r
012
MC/DC50%1/2
defined $stdout and $stdout =~ /(\d+)\.(\d+)\.(\d+)/u
defined $stdout $stdout =~ /(\d+)\.(\d+)\.(\d+)/u
Truth table66%2/3
A and B
A= defined $stdoutB= $stdout =~ /(\d+)\.(\d+)\.(\d+)/u
ABresult
0X0
100
111
191 2 my $version = "$1.$2.$3";
192 2 $VERSION_CHECKED{$cli} = $version;
193  
194 2 my @have = ($1, $2, $3);
195 2 my @need = split /\./, $MINIMUM_CLAUDE_CODE_VERSION;
196 2 for my $i (0 .. 2) {
197 3 ▶ last if $have[$i] > $need[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $have[$i] > $need[$i] 1 2 3
198 2 ▶ next if $have[$i] == $need[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $have[$i] == $need[$i] 1 1 2
199 1 my $text = "Claude Code $version at $cli is older than $MINIMUM_CLAUDE_CODE_VERSION; some features may not work";
200 1 $log->warning($text);
201 1 warn "$text\n";
202 1 last;
203 }
204 2 return;
205 }
206  
207 3 ▶sub cli_version {
Subroutine cli_version: called CC=3 SCAR=12.5
Pod documented
208 3 my ($self, $cli) = @_;
209 3 ▶ $cli //= $self->_cli_path;
Condition33%1/3
$cli //= $self->_cli_path
l!l&&r!l&&!r
300
MC/DC0%0/2
$cli //= $self->_cli_path
$cli $self->_cli_path
Truth table33%1/3
A //= B
A= $cliB= $self->_cli_path
ABresult
1X1
011
000
210 3 ▶ return defined $cli ? $VERSION_CHECKED{$cli} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $cli ? : 3 0 3
211 }
212  
213 6 ▶sub _encode_arg {
Subroutine _encode_arg: called CC=1 SCAR=0.0
214 6 my ($self, $data) = @_;
215 6 my $json = $self->_jsonl->encode([$data]);
216 6 chomp $json;
217 6 return $json;
218 }
219  
220 32 ▶sub _build_command {
Subroutine _build_command: called CC=69 SCAR=42.9
221 32 my ($self, $cli) = @_;
222  
223 32 my $o = $self->options;
224 32 my @cmd = ($cli, '--output-format', 'stream-json', '--verbose');
225  
226 32 ▶ if ($o->has_system_prompt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_system_prompt) 7 25 32
227 7 my $sp = $o->system_prompt;
228 7 ▶ if (!ref $sp) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $sp) { } 1 6 7
229 1 push @cmd, '--system-prompt', $sp;
230 }
231 else {
232 my $type = $sp->{type}
233 6 ▶ // (defined $sp->{preset} ? 'preset' : defined $sp->{path} ? 'file' : defined $sp->{prompt} ? 'custom' : '');
Branch: 3 branches
BranchTrueFalseTotal
defined $sp->{'preset'} ? : 1 0 1
defined $sp->{'path'} ? : 0 0 0
defined $sp->{'prompt'} ? : 0 0 0
Condition100%2/2
$sp->{"type"} // (defined $sp->{"preset"} ? "preset" : (defined $sp->{"path"} ? "file" : (defined $sp->{"prompt"} ? "custom" : "")))
l!l
51
MC/DC100%1/1
$sp->{"type"} // (defined $sp->{"preset"} ? "preset" : (defined $sp->{"path"} ? "file" : (defined $sp->{"prompt"} ? "custom" : "")))
$sp->{"type"}
Truth table100%2/2
A
A= $sp->{"type"}
Aresult
11
00
234 6 ▶ if ($type eq 'preset') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'preset') { } 3 3 6
elsif ($type eq 'custom') { } 1 2 3
elsif ($type eq 'file') { } 1 1 2
235 3 ▶ push @cmd, '--append-system-prompt', $sp->{append} if defined $sp->{append} && length $sp->{append};
Branch: 1 branch
BranchTrueFalseTotal
if defined $sp->{"append"} and length $sp->{"append"} 2 1 3
Condition66%2/3
defined $sp->{"append"} and length $sp->{"append"}
!ll&&!rl&&r
102
MC/DC50%1/2
defined $sp->{"append"} and length $sp->{"append"}
defined $sp->{"append"} length $sp->{"append"}
Truth table66%2/3
A and B
A= defined $sp->{"append"}B= length $sp->{"append"}
ABresult
0X0
100
111
236 }
237 elsif ($type eq 'custom') {
238 1 ▶ push @cmd, '--system-prompt', $sp->{prompt} // '';
Condition50%1/2
$sp->{"prompt"} // ""
l!l
10
MC/DC0%0/1
$sp->{"prompt"} // ""
$sp->{"prompt"}
Truth table50%1/2
A
A= $sp->{"prompt"}
Aresult
11
00
239 }
240 elsif ($type eq 'file') {
241 1 push @cmd, '--system-prompt-file', $sp->{path};
242 }
243 else {
244 1 Carp::croak("system_prompt hashref needs a type of preset, custom or file");
245 }
246 }
247 }
248  
249 31 ▶ if ($o->has_tools) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_tools) 3 28 31
250 3 my $tools = $o->tools;
251 3 ▶ if (ref $tools eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $tools eq 'ARRAY') { } 2 1 3
elsif (ref $tools eq 'HASH') { } 1 0 1
252 2 push @cmd, '--tools', join(',', @$tools);
253 }
254 elsif (ref $tools eq 'HASH') {
255 1 push @cmd, '--tools', 'default';
256 }
257 }
258  
259 1 push @cmd, '--allowedTools', join(',', @{$o->allowed_tools})
260 31 ▶ if $o->has_allowed_tools && @{$o->allowed_tools};
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_allowed_tools and @{$o->allowed_tools;} 1 30 31
Condition100%3/3
$o->has_allowed_tools and @{$o->allowed_tools;}
!ll&&!rl&&r
2911
MC/DC100%2/2
$o->has_allowed_tools and @{$o->allowed_tools;}
$o->has_allowed_tools @{$o->allowed_tools;}
Truth table100%3/3
A and B
A= $o->has_allowed_toolsB= @{$o->allowed_tools;}
ABresult
0X0
100
111
261 31 ▶ push @cmd, '--max-turns', int($o->max_turns) if $o->has_max_turns;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_max_turns 1 30 31
262 31 ▶ push @cmd, '--max-budget-usd', $o->max_budget_usd if $o->has_max_budget_usd;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_max_budget_usd 1 30 31
263 1 push @cmd, '--disallowedTools', join(',', @{$o->disallowed_tools})
264 31 ▶ if $o->has_disallowed_tools && @{$o->disallowed_tools};
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_disallowed_tools and @{$o->disallowed_tools;} 1 30 31
Condition66%2/3
$o->has_disallowed_tools and @{$o->disallowed_tools;}
!ll&&!rl&&r
3001
MC/DC50%1/2
$o->has_disallowed_tools and @{$o->disallowed_tools;}
$o->has_disallowed_tools @{$o->disallowed_tools;}
Truth table66%2/3
A and B
A= $o->has_disallowed_toolsB= @{$o->disallowed_tools;}
ABresult
0X0
100
111
265 31 ▶ push @cmd, '--model', $o->model if $o->has_model;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_model 1 30 31
266 31 ▶ push @cmd, '--fallback-model', $o->fallback_model if $o->has_fallback_model;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_fallback_model 1 30 31
267 31 ▶ push @cmd, '--betas', join(',', @{$o->betas}) if $o->has_betas && @{$o->betas};
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_betas and @{$o->betas;} 1 30 31
Condition66%2/3
$o->has_betas and @{$o->betas;}
!ll&&!rl&&r
3001
MC/DC50%1/2
$o->has_betas and @{$o->betas;}
$o->has_betas @{$o->betas;}
Truth table66%2/3
A and B
A= $o->has_betasB= @{$o->betas;}
ABresult
0X0
100
111
268  
269 31 ▶ if ($o->has_can_use_tool) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->has_can_use_tool) { } 1 30 31
elsif ($o->has_permission_prompt_tool_name) { } 1 29 30
270 1 push @cmd, '--permission-prompt-tool', 'stdio';
271 }
272 elsif ($o->has_permission_prompt_tool_name) {
273 1 push @cmd, '--permission-prompt-tool', $o->permission_prompt_tool_name;
274 }
275  
276 31 ▶ push @cmd, '--permission-mode', $o->permission_mode if $o->has_permission_mode;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_permission_mode 1 30 31
277 31 ▶ push @cmd, '--continue' if $o->has_continue_conversation && $o->continue_conversation;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_continue_conversation and $o->continue_conversation 1 30 31
Condition66%2/3
$o->has_continue_conversation and $o->continue_conversation
!ll&&!rl&&r
3001
MC/DC50%1/2
$o->has_continue_conversation and $o->continue_conversation
$o->has_continue_conversation $o->continue_conversation
Truth table66%2/3
A and B
A= $o->has_continue_conversationB= $o->continue_conversation
ABresult
0X0
100
111
278 31 ▶ push @cmd, '--resume=' . $o->resume if $o->has_resume;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_resume 1 30 31
279 31 ▶ push @cmd, '--session-id=' . $o->session_id if $o->has_session_id;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_session_id 1 30 31
280  
281 31 my $settings = $self->_settings_value;
282 31 ▶ push @cmd, '--settings', $settings if defined $settings;
Branch: 1 branch
BranchTrueFalseTotal
if defined $settings 5 26 31
283  
284 31 ▶ if ($o->has_add_dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_add_dirs) 1 30 31
285 1 push @cmd, '--add-dir', $_ for @{$o->add_dirs};
286 }
287  
288 31 ▶ if ($o->has_mcp_servers && %{$o->mcp_servers}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_mcp_servers and %{$o->mcp_servers;}) 1 30 31
Condition100%3/3
$o->has_mcp_servers and %{$o->mcp_servers;}
!ll&&!rl&&r
2911
MC/DC100%2/2
$o->has_mcp_servers and %{$o->mcp_servers;}
$o->has_mcp_servers %{$o->mcp_servers;}
Truth table100%3/3
A and B
A= $o->has_mcp_serversB= %{$o->mcp_servers;}
ABresult
0X0
100
111
289 1 my %servers;
290 1 for my $name (keys %{$o->mcp_servers}) {
291 4 my $server = $o->mcp_servers->{$name};
292 4 ▶ $servers{$name} = blessed($server) && $server->can('to_cli_config') ? $server->to_cli_config
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($server) && $server->can('to_cli_config') ? : 1 3 4
builtin::blessed($server) && $server->can('to_hash') ? : 2 1 3
Condition83%5/6
builtin::blessed($server) and $server->can("to_cli_config")
!ll&&!rl&&r
121
builtin::blessed($server) and $server->can("to_hash")
!ll&&!rl&&r
102
MC/DC100%2/2
builtin::blessed($server) and $server->can("to_cli_config")
builtin::blessed($server) $server->can("to_cli_config")
MC/DC50%1/2
builtin::blessed($server) and $server->can("to_hash")
builtin::blessed($server) $server->can("to_hash")
Truth table100%3/3
A and B
A= builtin::blessed($server)B= $server->can("to_cli_config")
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= builtin::blessed($server)B= $server->can("to_hash")
ABresult
0X0
100
111
293 : blessed($server) && $server->can('to_hash') ? $server->to_hash
294 : $server;
295 }
296 1 push @cmd, '--mcp-config', $self->_encode_arg({ mcpServers => \%servers });
297 }
298  
299 31 ▶ push @cmd, '--include-partial-messages' if $o->has_include_partial_messages && $o->include_partial_messages;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_include_partial_messages and $o->include_partial_messages 1 30 31
Condition66%2/3
$o->has_include_partial_messages and $o->include_partial_messages
!ll&&!rl&&r
3001
MC/DC50%1/2
$o->has_include_partial_messages and $o->include_partial_messages
$o->has_include_partial_messages $o->include_partial_messages
Truth table66%2/3
A and B
A= $o->has_include_partial_messagesB= $o->include_partial_messages
ABresult
0X0
100
111
300 31 ▶ push @cmd, '--include-hook-events' if $o->has_include_hook_events && $o->include_hook_events;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_include_hook_events and $o->include_hook_events 1 30 31
Condition66%2/3
$o->has_include_hook_events and $o->include_hook_events
!ll&&!rl&&r
3001
MC/DC50%1/2
$o->has_include_hook_events and $o->include_hook_events
$o->has_include_hook_events $o->include_hook_events
Truth table66%2/3
A and B
A= $o->has_include_hook_eventsB= $o->include_hook_events
ABresult
0X0
100
111
301 31 ▶ push @cmd, '--strict-mcp-config' if $o->has_strict_mcp_config && $o->strict_mcp_config;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_strict_mcp_config and $o->strict_mcp_config 1 30 31
Condition66%2/3
$o->has_strict_mcp_config and $o->strict_mcp_config
!ll&&!rl&&r
3001
MC/DC50%1/2
$o->has_strict_mcp_config and $o->strict_mcp_config
$o->has_strict_mcp_config $o->strict_mcp_config
Truth table66%2/3
A and B
A= $o->has_strict_mcp_configB= $o->strict_mcp_config
ABresult
0X0
100
111
302 31 ▶ push @cmd, '--fork-session' if $o->has_fork_session && $o->fork_session;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_fork_session and $o->fork_session 1 30 31
Condition66%2/3
$o->has_fork_session and $o->fork_session
!ll&&!rl&&r
3001
MC/DC50%1/2
$o->has_fork_session and $o->fork_session
$o->has_fork_session $o->fork_session
Truth table66%2/3
A and B
A= $o->has_fork_sessionB= $o->fork_session
ABresult
0X0
100
111
303 31 ▶ push @cmd, '--setting-sources=' . join(',', @{$o->setting_sources}) if $o->has_setting_sources;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_setting_sources 1 30 31
304  
305 31 ▶ if ($o->has_plugins) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_plugins) 1 30 31
306 1 push @cmd, '--plugin-dir', $_->{path} for @{$o->plugins};
307 }
308  
309 31 ▶ if ($o->has_extra_args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_extra_args) 1 30 31
310 1 my $extra = $o->extra_args;
311 1 for my $flag (sort keys %$extra) {
312 3 my $value = $extra->{$flag};
313 3 ▶ if (!defined $value) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value) { } 1 2 3
elsif ($value =~ /^-/u) { } 1 1 2
314 1 push @cmd, "--$flag";
315 }
316 elsif ($value =~ /^-/) {
317 1 push @cmd, "--$flag=$value";
318 }
319 else {
320 1 push @cmd, "--$flag", "$value";
321 }
322 }
323 }
324  
325 31 ▶ if ($o->has_thinking) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->has_thinking) { } 3 28 31
elsif ($o->has_max_thinking_tokens) { } 1 27 28
326 3 my $thinking = $o->thinking;
327 3 ▶ my $type = $thinking->{type} // '';
Condition50%1/2
$thinking->{"type"} // ""
l!l
30
MC/DC0%0/1
$thinking->{"type"} // ""
$thinking->{"type"}
Truth table50%1/2
A
A= $thinking->{"type"}
Aresult
11
00
328 3 ▶ if ($type eq 'adaptive') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'adaptive') { } 1 2 3
elsif ($type eq 'enabled') { } 1 1 2
elsif ($type eq 'disabled') { } 1 0 1
329 1 push @cmd, '--thinking', 'adaptive';
330 }
331 elsif ($type eq 'enabled') {
332 1 ▶ push @cmd, '--max-thinking-tokens', int($thinking->{budget_tokens} // 0);
Condition50%1/2
$thinking->{"budget_tokens"} // 0
l!l
10
MC/DC0%0/1
$thinking->{"budget_tokens"} // 0
$thinking->{"budget_tokens"}
Truth table50%1/2
A
A= $thinking->{"budget_tokens"}
Aresult
11
00
333 }
334 elsif ($type eq 'disabled') {
335 1 push @cmd, '--thinking', 'disabled';
336 }
337 }
338 elsif ($o->has_max_thinking_tokens) {
339 1 push @cmd, '--max-thinking-tokens', int($o->max_thinking_tokens);
340 }
341  
342 31 ▶ push @cmd, '--effort', $o->effort if $o->has_effort;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_effort 1 30 31
343  
344 31 ▶ if ($o->has_output_format && ref $o->output_format eq 'HASH' && $o->output_format->{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_output_format and ref $o->output_format eq "HASH" and $o->output_format->{"schema"}) 1 30 31
Condition66%4/6
$o->has_output_format and ref $o->output_format eq "HASH" and $o->output_format->{"schema"}
!ll&&!rl&&r
3001
$o->has_output_format and ref $o->output_format eq "HASH"
!ll&&!rl&&r
3001
MC/DC33%1/3
$o->has_output_format and ref $o->output_format eq "HASH" and $o->output_format->{"schema"}
$o->has_output_format ref $o->output_format eq "HASH" $o->output_format->{"schema"}
Truth table50%2/4
A and B and C
A= $o->has_output_formatB= ref $o->output_format eq "HASH"C= $o->output_format->{"schema"}
ABCresult
0XX0
10X0
1100
1111
345 1 push @cmd, '--json-schema', $self->_encode_arg($o->output_format->{schema});
346 }
347  
348 31 push @cmd, '--input-format', 'stream-json';
349 31 return @cmd;
350 }
351  
352 31 ▶sub _settings_value {
Subroutine _settings_value: called CC=14 SCAR=29.7
353 31 my ($self) = @_;
354 31 my $o = $self->options;
355 31 ▶ return unless $o->has_settings || $o->has_sandbox;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->has_settings or $o->has_sandbox 26 5 31
Condition100%3/3
$o->has_settings or $o->has_sandbox
l!l&&r!l&&!r
4126
MC/DC100%2/2
$o->has_settings or $o->has_sandbox
$o->has_settings $o->has_sandbox
Truth table100%3/3
A or B
A= $o->has_settingsB= $o->has_sandbox
ABresult
1X1
011
000
356  
357 5 ▶ my $settings = $o->has_settings ? $o->settings : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o->has_settings ? : 4 1 5
358 5 ▶ return ref $settings ? $self->_encode_arg($settings) : $settings
Branch: 2 branches
BranchTrueFalseTotal
unless $o->has_sandbox 2 3 5
ref $settings ? : 1 1 2
359 unless $o->has_sandbox;
360  
361 3 my %merged;
362 3 ▶ if (ref $settings eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $settings eq 'HASH') { } 1 2 3
elsif (defined $settings and $settings =~ /^\s*\{/u) { } 1 1 2
elsif (defined $settings and -f $settings) { } 0 2 2
363 1 %merged = %$settings;
364 }
365 ▶ elsif (defined $settings && $settings =~ /^\s*\{/) {
Condition66%2/3
defined $settings and $settings =~ /^\s*\{/u
!ll&&!rl&&r
101
MC/DC50%1/2
defined $settings and $settings =~ /^\s*\{/u
defined $settings $settings =~ /^\s*\{/u
Truth table66%2/3
A and B
A= defined $settingsB= $settings =~ /^\s*\{/u
ABresult
0X0
100
111
366 1 my ($decoded) = $self->_jsonl->decode($settings . "\n");
367 1 ▶ %merged = %$decoded if ref $decoded eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $decoded eq "HASH" 1 0 1
368 }
369 ▶ elsif (defined $settings && -f $settings) {
Condition33%1/3
defined $settings and -f $settings
!ll&&!rl&&r
100
MC/DC0%0/2
defined $settings and -f $settings
defined $settings -f $settings
Truth table33%1/3
A and B
A= defined $settingsB= -f $settings
ABresult
0X0
100
111
370 0 ▶ open my $fh, '<', $settings or Carp::croak("Cannot read settings file $settings: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $settings or Carp::croak("Cannot read settings file ${settings}: $!") 0 0 0
371 0 local $/;
372 0 my ($decoded) = $self->_jsonl->decode(scalar(<$fh>) . "\n");
373 0 close $fh;
374 0 ▶ %merged = %$decoded if ref $decoded eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $decoded eq "HASH" 0 0 0
375 }
376 3 $merged{sandbox} = $o->sandbox;
377 3 return $self->_encode_arg(\%merged);
378 }
379  
380 2 ▶sub _build_env {
Subroutine _build_env: called CC=7 SCAR=19.6
381 2 my ($self) = @_;
382 2 my $o = $self->options;
383  
384 2 my %env = %ENV;
385 2 delete $env{CLAUDECODE};
386 2 $env{CLAUDE_CODE_ENTRYPOINT} = $ENTRYPOINT;
387 2 ▶ %env = (%env, %{$o->env}) if $o->has_env;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_env 2 0 2
388 2 ▶ $env{CLAUDE_AGENT_SDK_VERSION} = $Claude::Agent::VERSION // 'dev';
Condition50%1/2
$Claude::Agent::VERSION // "dev"
l!l
20
MC/DC0%0/1
$Claude::Agent::VERSION // "dev"
$Claude::Agent::VERSION
Truth table50%1/2
A
A= $Claude::Agent::VERSION
Aresult
11
00
389 $env{CLAUDE_CODE_SDK_READS_SESSION_STATE} = '1'
390 2 ▶ unless exists $env{CLAUDE_CODE_SDK_READS_SESSION_STATE};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $env{"CLAUDE_CODE_SDK_READS_SESSION_STATE"} 1 1 2
391 2 ▶ $env{CLAUDE_CODE_ENABLE_SDK_FILE_CHECKPOINTING} = 'true'
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_enable_file_checkpointing and $o->enable_file_checkpointing 1 1 2
Condition66%2/3
$o->has_enable_file_checkpointing and $o->enable_file_checkpointing
!ll&&!rl&&r
101
MC/DC50%1/2
$o->has_enable_file_checkpointing and $o->enable_file_checkpointing
$o->has_enable_file_checkpointing $o->enable_file_checkpointing
Truth table66%2/3
A and B
A= $o->has_enable_file_checkpointingB= $o->enable_file_checkpointing
ABresult
0X0
100
111
392 if $o->has_enable_file_checkpointing && $o->enable_file_checkpointing;
393 2 ▶ $env{PWD} = $o->cwd if $o->has_cwd;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_cwd 1 1 2
394 2 return \%env;
395 }
396  
397 60 ▶sub _start_process {
Subroutine _start_process: called CC=6 SCAR=34.4
398 60 my ($self) = @_;
399  
400 60 ▶ unless ($self->spawn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->spawn) 59 1 60
401 59 $self->_initialize;
402 59 return;
403 }
404  
405 1 my $cli = $self->_find_claude_cli;
406 0 $self->_cli_path($cli);
407 0 $self->_check_claude_version($cli);
408  
409 0 my $o = $self->options;
410 0 ▶ if ($o->has_cwd && !-d $o->cwd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_cwd and not -d $o->cwd) 0 0 0
Condition0%0/3
$o->has_cwd and not -d $o->cwd
!ll&&!rl&&r
000
MC/DC0%0/2
$o->has_cwd and not -d $o->cwd
$o->has_cwd not -d $o->cwd
Truth table0%0/3
A and not(B)
A= $o->has_cwdB= not -d $o->cwd
ABresult
0X0
100
111
411 0 Claude::Agent::Error::ProcessError->throw(
412 message => "cwd '" . $o->cwd . "' is not a directory",
413 );
414 }
415  
416 0 my @cmd = $self->_build_command($cli);
417 0 my $env = $self->_build_env;
418 0 $log->debug(sprintf("Query: starting %s with %d arguments", $cli, scalar(@cmd) - 1));
419 0 $log->trace(sprintf("Query: argv: %s", join(' ', @cmd)));
420  
421 0 ▶ my $stderr = $o->has_stderr ? $o->stderr : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o->has_stderr ? : 0 0 0
422  
423 my $process = IO::Async::Process->new(
424 command => \@cmd,
425 setup => [
426 env => $env,
427 ($o->has_cwd ? (chdir => $o->cwd) : ()),
428 ],
429 stdin => { via => 'pipe_write' },
430 stdout => {
431 0 ▶ on_read => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
432 0 my ($stream, $buffref) = @_;
433 0 ▶ while ($$buffref =~ s/^([^\n]*)\n//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$buffref =~ s/^([^\n]*)\n//u) 0 0 0
434 0 $self->_handle_line($1);
435 }
436 0 return 0;
437 },
438 },
439 stderr => {
440 0 ▶ on_read => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
441 0 my ($stream, $buffref) = @_;
442 0 ▶ while ($$buffref =~ s/^([^\n]*)\n//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$buffref =~ s/^([^\n]*)\n//u) 0 0 0
443 0 my $line = $1;
444 0 ▶ if ($stderr) { $stderr->($line) } else { $log->debug("Claude CLI stderr: $line") }
Branch: 1 branch
BranchTrueFalseTotal
if ($stderr) { } 0 0 0
445 }
446 0 return 0;
447 },
448 },
449 0 ▶ on_finish => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
450 0 my ($proc, $exitcode) = @_;
451 0 my $status = $exitcode >> 8;
452 0 $log->debug(sprintf("Query: process finished with exit code %d", $status));
453 0 ▶ $self->_error("Claude CLI exited with code $status") if $status != 0 && !$self->_error;
Branch: 1 branch
BranchTrueFalseTotal
if $status != 0 and not $self->_error 0 0 0
Condition0%0/3
$status != 0 and not $self->_error
!ll&&!rl&&r
000
MC/DC0%0/2
$status != 0 and not $self->_error
$status != 0 not $self->_error
Truth table0%0/3
A and not(B)
A= $status != 0B= not $self->_error
ABresult
0X0
100
111
454 0 $self->_on_exit;
455 },
456 0 ▶ on_exception => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
457 0 my ($proc, $exception) = @_;
458 0 $log->debug(sprintf("Query: process exception: %s", $exception));
459 0 $self->_error("Claude CLI exception: $exception");
460 0 $self->_on_exit;
461 },
462 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$o->has_cwd ? : 0 0 0
463  
464 0 $self->_process($process);
465 0 $self->_stdin($process->stdin);
466 0 $self->_loop->add($process);
467  
468 0 $self->_initialize;
469 0 return;
470 }
471  
472 0 ▶sub _on_exit {
Subroutine _on_exit: not called CC=2 SCAR=17.9
473 0 my ($self) = @_;
474 0 $self->_finished(1);
475 0 $self->_stdin_closed(1);
476 0 $self->_clear_run_end_timer;
477 0 ▶ $self->_exit_future->done unless $self->_exit_future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_exit_future->is_ready 0 0 0
478 0 $self->_finish_pending;
479 0 return;
480 }
481  
482 6 ▶sub _finish_pending {
Subroutine _finish_pending: called CC=10 SCAR=25.4
483 6 my ($self) = @_;
484 6 ▶ my $why = $self->_error // 'Query finished';
Condition100%2/2
$self->_error // "Query finished"
l!l
15
MC/DC100%1/1
$self->_error // "Query finished"
$self->_error
Truth table100%2/2
A
A= $self->_error
Aresult
11
00
485 6 for my $id (keys %{$self->_pending_control}) {
486 4 my $entry = delete $self->_pending_control->{$id};
487 4 ▶ $entry->{timer}->cancel if $entry->{timer} && !$entry->{timer}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"timer"} and not $entry->{"timer"}->is_ready 4 0 4
Condition33%1/3
$entry->{"timer"} and not $entry->{"timer"}->is_ready
!ll&&!rl&&r
004
MC/DC0%0/2
$entry->{"timer"} and not $entry->{"timer"}->is_ready
$entry->{"timer"} not $entry->{"timer"}->is_ready
Truth table33%1/3
A and not(B)
A= $entry->{"timer"}B= not $entry->{"timer"}->is_ready
ABresult
0X0
100
111
488 4 ▶ $entry->{future}->fail($why) unless $entry->{future}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"future"}->is_ready 4 0 4
489 }
490 6 for my $id (keys %{$self->_inflight_requests}) {
491 0 my $future = delete $self->_inflight_requests->{$id};
492 0 ▶ $future->cancel unless $future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 0 0 0
493 }
494 6 ▶ while (my $future = shift @{$self->_pending_futures}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $future = shift @{$self->_pending_futures;}) 1 6 7
495 1 ▶ $future->done(undef) unless $future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 1 0 1
496 }
497 6 return;
498 }
499  
500 59 ▶sub _initialize {
Subroutine _initialize: called CC=10 SCAR=23.5
501 59 my ($self) = @_;
502  
503 59 my %request = (subtype => 'initialize');
504 59 ▶ $request{hooks} = $self->_hook_registry ? $self->_hook_registry->to_initialize_config : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_hook_registry ? : 3 56 59
505  
506 59 my $o = $self->options;
507 59 ▶ if ($o->has_agents && %{$o->agents}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->has_agents and %{$o->agents;}) 2 57 59
Condition66%2/3
$o->has_agents and %{$o->agents;}
!ll&&!rl&&r
5702
MC/DC50%1/2
$o->has_agents and %{$o->agents;}
$o->has_agents %{$o->agents;}
Truth table66%2/3
A and B
A= $o->has_agentsB= %{$o->agents;}
ABresult
0X0
100
111
508 $request{agents} = {
509 map {
510 2 my $agent = $o->agents->{$_};
511 2 ▶ $_ => (blessed($agent) && $agent->can('to_hash') ? $agent->to_hash : $agent)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($agent) && $agent->can('to_hash') ? : 2 0 2
Condition33%1/3
builtin::blessed($agent) and $agent->can("to_hash")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($agent) and $agent->can("to_hash")
builtin::blessed($agent) $agent->can("to_hash")
Truth table33%1/3
A and B
A= builtin::blessed($agent)B= $agent->can("to_hash")
ABresult
0X0
100
111
512 2 } keys %{$o->agents}
513 };
514 }
515 59 ▶ $request{forwardSubagentText} = \1 if $o->has_forward_subagent_text && $o->forward_subagent_text;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_forward_subagent_text and $o->forward_subagent_text 1 58 59
Condition66%2/3
$o->has_forward_subagent_text and $o->forward_subagent_text
!ll&&!rl&&r
5801
MC/DC50%1/2
$o->has_forward_subagent_text and $o->forward_subagent_text
$o->has_forward_subagent_text $o->forward_subagent_text
Truth table66%2/3
A and B
A= $o->has_forward_subagent_textB= $o->forward_subagent_text
ABresult
0X0
100
111
516  
517 59 ▶ my $timeout = ($ENV{CLAUDE_CODE_STREAM_CLOSE_TIMEOUT} // 0) / 1000;
Condition50%1/2
$ENV{"CLAUDE_CODE_STREAM_CLOSE_TIMEOUT"} // 0
l!l
059
MC/DC0%0/1
$ENV{"CLAUDE_CODE_STREAM_CLOSE_TIMEOUT"} // 0
$ENV{"CLAUDE_CODE_STREAM_CLOSE_TIMEOUT"}
Truth table50%1/2
A
A= $ENV{"CLAUDE_CODE_STREAM_CLOSE_TIMEOUT"}
Aresult
11
00
518 59 ▶ $timeout = 60 if $timeout < 60;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout < 60 59 0 59
519  
520 17 ▶ $self->_send_control_request(\%request, $timeout)->on_done(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
521 17 my ($result) = @_;
522 17 $self->_init_result($result);
523 17 $log->debug("Query: initialized");
524 17 $self->_send_prompt;
525 4 ▶ })->on_fail(sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
526 4 my ($err) = @_;
527 4 $log->debug(sprintf("Query: initialize failed: %s", $err));
528 4 ▶ $self->_error("initialize failed: $err") unless $self->_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_error 4 0 4
529 4 $self->close_async->retain;
530 59 })->retain;
531 59 return;
532 }
533  
534 17 ▶sub _send_prompt {
Subroutine _send_prompt: called CC=3 SCAR=11.0
535 17 my ($self) = @_;
536  
537 17 ▶ if ($self->has_prompt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_prompt) 16 1 17
538 16 $self->send_user_message($self->prompt);
539 }
540 17 ▶ $self->_end_input unless $self->_needs_stdin_open;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_needs_stdin_open 1 16 17
541 17 return;
542 }
543  
544 24 ▶sub _needs_stdin_open {
Subroutine _needs_stdin_open: called CC=5 SCAR=16.1
545 24 my ($self) = @_;
546 24 ▶ return 1 if $self->persistent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->persistent 7 17 24
547 17 ▶ return 1 if $self->_hook_registry;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_hook_registry 3 14 17
548 14 ▶ return 1 if %{$self->_sdk_bridges};
Branch: 1 branch
BranchTrueFalseTotal
if %{$self->_sdk_bridges;} 1 13 14
549 13 ▶ return 1 if $self->options->has_can_use_tool;
Branch: 1 branch
BranchTrueFalseTotal
if $self->options->has_can_use_tool 12 1 13
550 1 return 0;
551 }
552  
553 108 ▶sub _write {
Subroutine _write: called CC=8 SCAR=31.1
554 108 my ($self, $data) = @_;
555  
556 108 ▶ return 0 if $self->_stdin_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_stdin_closed 0 108 108
557 108 my $line = $self->_jsonl->encode([$data]);
558 108 ▶ return 0 unless defined $line && length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and length $line 0 108 108
Condition33%1/3
defined $line and length $line
!ll&&!rl&&r
00108
MC/DC0%0/2
defined $line and length $line
defined $line length $line
Truth table33%1/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
559  
560 108 ▶ if ($self->has_writer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_writer) 108 0 108
561 108 $self->writer->($line, $data);
562 108 return 1;
563 }
564 0 ▶ return 0 unless $self->_stdin;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_stdin 0 0 0
565 0 my $ok = eval { $self->_stdin->write($line); 1 };
566 0 ▶ $log->debug(sprintf("Query: write failed: %s", $@)) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
567 0 ▶ return $ok ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
568 }
569  
570 11 ▶sub _end_input {
Subroutine _end_input: called CC=4 SCAR=15.5
571 11 my ($self) = @_;
572 11 ▶ return if $self->_stdin_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_stdin_closed 0 11 11
573 11 $self->_stdin_closed(1);
574 11 $log->debug("Query: closing stdin");
575 11 ▶ if ($self->has_closer) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_closer) { } 11 0 11
elsif ($self->_stdin) { } 0 0 0
576 11 $self->closer->();
577 }
578 elsif ($self->_stdin) {
579 0 $self->_stdin->close_when_empty;
580 }
581 11 return;
582 }
583  
584 71 ▶sub _send_control_request {
Subroutine _send_control_request: called CC=8 SCAR=23.4
585 71 my ($self, $request, $timeout) = @_;
586  
587 71 ▶ $timeout //= 60;
Condition100%2/2
$timeout //= 60
l!l
6011
MC/DC100%1/1
$timeout //= 60
$timeout
Truth table100%2/2
A
A= $timeout
Aresult
11
00
588 71 ▶ my $subtype = $request->{subtype} // 'unknown';
Condition50%1/2
$request->{"subtype"} // "unknown"
l!l
710
MC/DC0%0/1
$request->{"subtype"} // "unknown"
$request->{"subtype"}
Truth table50%1/2
A
A= $request->{"subtype"}
Aresult
11
00
589  
590 71 ▶ return Future->fail('Query is not running') if $self->_finished || $self->_stdin_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_finished or $self->_stdin_closed 0 71 71
Condition33%1/3
$self->_finished or $self->_stdin_closed
l!l&&r!l&&!r
0071
MC/DC0%0/2
$self->_finished or $self->_stdin_closed
$self->_finished $self->_stdin_closed
Truth table33%1/3
A or B
A= $self->_finishedB= $self->_stdin_closed
ABresult
1X1
011
000
591  
592 71 my $counter = $self->_request_counter + 1;
593 71 $self->_request_counter($counter);
594 71 my $id = sprintf('req_%d_%s', $counter, unpack('H*', Crypt::URandom::urandom(4)));
595  
596 71 my $future = $self->_loop->new_future;
597 71 my $entry = { future => $future };
598 71 $self->_pending_control->{$id} = $entry;
599  
600 71 ▶ if ($timeout > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout > 0) 71 0 71
601 1 ▶ $entry->{timer} = $self->_loop->delay_future(after => $timeout)->on_done(sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
602 1 ▶ my $pending = delete $self->_pending_control->{$id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $pending = delete $self->_pending_control->{$id} or return 1 0 1
603 1 ▶ $pending->{future}->fail("Control request timeout: $subtype") unless $pending->{future}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $pending->{"future"}->is_ready 1 0 1
604 71 });
605 }
606  
607 27 ▶ $future->on_ready(sub {
Subroutine __ANON__: called CC=4 SCAR=17.9
608 27 my $pending = delete $self->_pending_control->{$id};
609 27 ▶ $pending->{timer}->cancel if $pending && $pending->{timer} && !$pending->{timer}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $pending and $pending->{"timer"} and not $pending->{"timer"}->is_ready 0 27 27
Condition33%2/6
$pending and $pending->{"timer"} and not $pending->{"timer"}->is_ready
!ll&&!rl&&r
2700
$pending and $pending->{"timer"}
!ll&&!rl&&r
2700
MC/DC0%0/3
$pending and $pending->{"timer"} and not $pending->{"timer"}->is_ready
$pending $pending->{"timer"} not $pending->{"timer"}->is_ready
Truth table25%1/4
A and B and not(C)
A= $pendingB= $pending->{"timer"}C= not $pending->{"timer"}->is_ready
ABCresult
0XX0
10X0
1100
1111
610 71 });
611  
612 71 $log->debug(sprintf("Query: control_request %s %s", $subtype, $id));
613 71 ▶ unless ($self->_write({ type => 'control_request', request_id => $id, request => $request })) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_write({"type", "control_request", "request_id", $id, "request", $request})) 0 71 71
614 0 ▶ $future->fail("Could not send control request: $subtype") unless $future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 0 0 0
615 }
616 71 return $future;
617 }
618  
619 22 ▶sub _on_control_response {
Subroutine _on_control_response: called CC=11 SCAR=26.6
620 22 my ($self, $data) = @_;
621  
622 22 my $response = $data->{response};
623 22 ▶ return unless ref $response eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response eq "HASH" 0 22 22
624 22 ▶ my $id = $response->{request_id} // '';
Condition50%1/2
$response->{"request_id"} // ""
l!l
220
MC/DC0%0/1
$response->{"request_id"} // ""
$response->{"request_id"}
Truth table50%1/2
A
A= $response->{"request_id"}
Aresult
11
00
625 22 ▶ my $entry = delete $self->_pending_control->{$id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $entry = delete $self->_pending_control->{$id} or return 22 0 22
626 22 ▶ $entry->{timer}->cancel if $entry->{timer} && !$entry->{timer}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"timer"} and not $entry->{"timer"}->is_ready 22 0 22
Condition33%1/3
$entry->{"timer"} and not $entry->{"timer"}->is_ready
!ll&&!rl&&r
0022
MC/DC0%0/2
$entry->{"timer"} and not $entry->{"timer"}->is_ready
$entry->{"timer"} not $entry->{"timer"}->is_ready
Truth table33%1/3
A and not(B)
A= $entry->{"timer"}B= not $entry->{"timer"}->is_ready
ABresult
0X0
100
111
627 22 ▶ return if $entry->{future}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $entry->{"future"}->is_ready 0 22 22
628  
629 22 ▶ if (($response->{subtype} // '') eq 'error') {
Branch: 1 branch
BranchTrueFalseTotal
if (($response->{'subtype'} // '') eq 'error') { } 2 20 22
Condition50%1/2
$response->{"subtype"} // ""
l!l
220
MC/DC0%0/1
$response->{"subtype"} // ""
$response->{"subtype"}
Truth table50%1/2
A
A= $response->{"subtype"}
Aresult
11
00
630 2 ▶ $entry->{future}->fail($response->{error} // 'unknown error');
Condition50%1/2
$response->{"error"} // "unknown error"
l!l
20
MC/DC0%0/1
$response->{"error"} // "unknown error"
$response->{"error"}
Truth table50%1/2
A
A= $response->{"error"}
Aresult
11
00
631 }
632 else {
633 20 my $result = $response->{response};
634 20 ▶ $entry->{future}->done(ref $result eq 'HASH' ? $result : {});
Branch: 1 branch
BranchTrueFalseTotal
ref $result eq 'HASH' ? : 20 0 20
635 }
636 22 return;
637 }
638  
639 19 ▶sub _on_control_request {
Subroutine _on_control_request: called CC=10 SCAR=23.6
640 19 my ($self, $data) = @_;
641  
642 19 ▶ my $request_id = $data->{request_id} // '';
Condition50%1/2
$data->{"request_id"} // ""
l!l
190
MC/DC0%0/1
$data->{"request_id"} // ""
$data->{"request_id"}
Truth table50%1/2
A
A= $data->{"request_id"}
Aresult
11
00
643 19 ▶ my $request = ref $data->{request} eq 'HASH' ? $data->{request} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $data->{'request'} eq 'HASH' ? : 19 0 19
644 19 ▶ my $subtype = $request->{subtype} // '';
Condition50%1/2
$request->{"subtype"} // ""
l!l
190
MC/DC0%0/1
$request->{"subtype"} // ""
$request->{"subtype"}
Truth table50%1/2
A
A= $request->{"subtype"}
Aresult
11
00
645  
646 19 $log->debug(sprintf("Query: control_request from CLI: %s %s", $subtype, $request_id));
647  
648 19 my $future;
649 19 my $ok = eval {
650 19 ▶ $future = $subtype eq 'can_use_tool' ? $self->_handle_can_use_tool($request)
Branch: 3 branches
BranchTrueFalseTotal
$subtype eq 'can_use_tool' ? : 9 10 19
$subtype eq 'hook_callback' ? : 3 7 10
$subtype eq 'mcp_message' ? : 6 1 7
651 : $subtype eq 'hook_callback' ? $self->_handle_hook_callback($request)
652 : $subtype eq 'mcp_message' ? $self->_handle_mcp_message($request)
653 : Future->fail("Unsupported control request subtype: $subtype");
654 19 1;
655 };
656 19 ▶ $future = Future->fail("$@") unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 19 19
657 19 ▶ $future = Future->done($future) unless blessed($future) && $future->isa('Future');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($future) and $future->isa("Future") 0 19 19
Condition33%1/3
builtin::blessed($future) and $future->isa("Future")
!ll&&!rl&&r
0019
MC/DC0%0/2
builtin::blessed($future) and $future->isa("Future")
builtin::blessed($future) $future->isa("Future")
Truth table33%1/3
A and B
A= builtin::blessed($future)B= $future->isa("Future")
ABresult
0X0
100
111
658  
659 19 $self->_inflight_requests->{$request_id} = $future;
660 19 ▶ $future->on_ready(sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
661 19 my ($f) = @_;
662 19 ▶ return unless delete $self->_inflight_requests->{$request_id};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $self->_inflight_requests->{$request_id} 1 18 19
663 18 ▶ return if $f->is_cancelled;
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_cancelled 0 18 18
664 18 ▶ if ($f->is_failed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->is_failed) { } 6 12 18
665 6 my ($err) = $f->failure;
666 6 $log->debug(sprintf("Query: control_request %s failed: %s", $request_id, $err));
667 6 $self->_write({
668 type => 'control_response',
669 response => { subtype => 'error', request_id => $request_id, error => "$err" },
670 });
671 }
672 else {
673 12 my ($result) = $f->get;
674 12 ▶ $self->_write({
Condition50%1/2
$result // {}
l!l
120
MC/DC0%0/1
$result // {}
$result
Truth table50%1/2
A
A= $result
Aresult
11
00
675 type => 'control_response',
676 response => { subtype => 'success', request_id => $request_id, response => $result // {} },
677 });
678 }
679 19 })->retain;
680 19 return;
681 }
682  
683 1 ▶sub _on_control_cancel {
Subroutine _on_control_cancel: called CC=4 SCAR=14.5
684 1 my ($self, $data) = @_;
685 1 ▶ my $id = $data->{request_id} // '';
Condition50%1/2
$data->{"request_id"} // ""
l!l
10
MC/DC0%0/1
$data->{"request_id"} // ""
$data->{"request_id"}
Truth table50%1/2
A
A= $data->{"request_id"}
Aresult
11
00
686 1 ▶ my $future = delete $self->_inflight_requests->{$id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $future = delete $self->_inflight_requests->{$id} or return 1 0 1
687 1 $log->debug(sprintf("Query: control_request %s cancelled", $id));
688 1 ▶ $future->cancel unless $future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 1 0 1
689 1 return;
690 }
691  
692 9 ▶sub _handle_can_use_tool {
Subroutine _handle_can_use_tool: called CC=8 SCAR=20.8
693 9 my ($self, $request) = @_;
694  
695 9 my $o = $self->options;
696 9 ▶ return Future->fail('can_use_tool callback is not provided') unless $o->has_can_use_tool;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->has_can_use_tool 1 8 9
697  
698 8 ▶ my $tool_name = $request->{tool_name} // '';
Condition50%1/2
$request->{"tool_name"} // ""
l!l
80
MC/DC0%0/1
$request->{"tool_name"} // ""
$request->{"tool_name"}
Truth table50%1/2
A
A= $request->{"tool_name"}
Aresult
11
00
699 8 ▶ my $input = ref $request->{input} eq 'HASH' ? $request->{input} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $request->{'input'} eq 'HASH' ? : 8 0 8
700  
701 my $context = Claude::Agent::Permission::Context->new(
702 tool_name => $tool_name,
703 tool_input => $input,
704 Claude::Agent::Types::defined_args(
705 session_id => $self->_session_id,
706 cwd => ($o->has_cwd ? $o->cwd : undef),
707 tool_use_id => $request->{tool_use_id},
708 agent_id => $request->{agent_id},
709 suggestions => $request->{permission_suggestions},
710 blocked_path => $request->{blocked_path},
711 decision_reason => $request->{decision_reason},
712 title => $request->{title},
713 display_name => $request->{display_name},
714 description => $request->{description},
715 8 ▶ query => $self,
Branch: 1 branch
BranchTrueFalseTotal
$o->has_cwd ? : 6 2 8
716 ),
717 );
718  
719 8 my $result;
720 8 my $ok = eval { $result = $o->can_use_tool->($tool_name, $input, $context); 1 };
721 8 ▶ return Future->fail("$@") unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 7 8
722  
723 7 ▶ my $future = blessed($result) && $result->isa('Future') ? $result : Future->done($result);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($result) && $result->isa('Future') ? : 2 5 7
Condition100%3/3
builtin::blessed($result) and $result->isa("Future")
!ll&&!rl&&r
232
MC/DC100%2/2
builtin::blessed($result) and $result->isa("Future")
builtin::blessed($result) $result->isa("Future")
Truth table100%3/3
A and B
A= builtin::blessed($result)B= $result->isa("Future")
ABresult
0X0
100
111
724 6 ▶ return $future->then(sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
725 6 my ($answer) = @_;
726 6 ▶ my $permission = Claude::Agent::Permission->coerce($answer)
Branch: 1 branch
BranchTrueFalseTotal
my $permission = "Claude::Agent::Permission"->coerce($answer) or return "Future"->fail("can_use_tool must return a Claude::Agent::Permission result") 5 1 6
727 or return Future->fail('can_use_tool must return a Claude::Agent::Permission result');
728 5 my $hash = $permission->to_hash;
729 5 ▶ $hash->{updatedInput} = $input if $hash->{behavior} eq 'allow' && !exists $hash->{updatedInput};
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"behavior"} eq "allow" and not exists $hash->{"updatedInput"} 2 3 5
Condition100%3/3
$hash->{"behavior"} eq "allow" and not exists $hash->{"updatedInput"}
!ll&&!rl&&r
212
MC/DC100%2/2
$hash->{"behavior"} eq "allow" and not exists $hash->{"updatedInput"}
$hash->{"behavior"} eq "allow" not exists $hash->{"updatedInput"}
Truth table100%3/3
A and not(B)
A= $hash->{"behavior"} eq "allow"B= not exists $hash->{"updatedInput"}
ABresult
0X0
100
111
730 5 $log->debug(sprintf("Query: can_use_tool %s -> %s", $tool_name, $hash->{behavior}));
731 5 return Future->done($hash);
732 7 });
733 }
734  
735 3 ▶sub _handle_hook_callback {
Subroutine _handle_hook_callback: called CC=3 SCAR=11.1
736 3 my ($self, $request) = @_;
737 3 ▶ my $registry = $self->_hook_registry
Branch: 1 branch
BranchTrueFalseTotal
my $registry = $self->_hook_registry or return "Future"->fail("No hooks are registered") 2 1 3
738 or return Future->fail('No hooks are registered');
739 2 ▶ return $registry->run($request->{callback_id} // '', $request->{input}, $request->{tool_use_id});
Condition50%1/2
$request->{"callback_id"} // ""
l!l
20
MC/DC0%0/1
$request->{"callback_id"} // ""
$request->{"callback_id"}
Truth table50%1/2
A
A= $request->{"callback_id"}
Aresult
11
00
740 }
741  
742 6 ▶sub _handle_mcp_message {
Subroutine _handle_mcp_message: called CC=4 SCAR=14.2
743 6 my ($self, $request) = @_;
744  
745 6 ▶ my $name = $request->{server_name} // '';
Condition50%1/2
$request->{"server_name"} // ""
l!l
60
MC/DC0%0/1
$request->{"server_name"} // ""
$request->{"server_name"}
Truth table50%1/2
A
A= $request->{"server_name"}
Aresult
11
00
746 6 my $message = $request->{message};
747 6 ▶ my $id = ref $message eq 'HASH' ? $message->{id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $message eq 'HASH' ? : 6 0 6
748  
749 6 ▶ my $bridge = $self->_sdk_bridges->{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $bridge = $self->_sdk_bridges->{$name} or return "Future"->done({"mcp_response", {"jsonrpc", "2.0", "id", $id, "error", {"code", -32601, "message", "Server '${name}' not found"}}}) 5 1 6
750 or return Future->done({ mcp_response => {
751 jsonrpc => '2.0', id => $id,
752 error => { code => -32601, message => "Server '$name' not found" },
753 } });
754  
755 5 ▶ return $bridge->handle($message)->then(sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
756 5 my ($reply) = @_;
757 5 ▶ $reply //= { jsonrpc => '2.0', result => {} };
Condition100%2/2
$reply //= {"jsonrpc", "2.0", "result", {}}
l!l
41
MC/DC100%1/1
$reply //= {"jsonrpc", "2.0", "result", {}}
$reply
Truth table100%2/2
A
A= $reply
Aresult
11
00
758 5 return Future->done({ mcp_response => $reply });
759 0 ▶ })->else(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
760 0 my ($err) = @_;
761 0 return Future->done({ mcp_response => {
762 jsonrpc => '2.0', id => $id,
763 error => { code => -32603, message => "$err" },
764 } });
765 5 });
766 }
767  
768 70 ▶sub feed_line {
Subroutine feed_line: called CC=1 SCAR=0.0
Pod documented
769 70 my ($self, $line) = @_;
770 70 return $self->_handle_line($line);
771 }
772  
773 70 ▶sub _handle_line {
Subroutine _handle_line: called CC=31 SCAR=36.6
774 70 my ($self, $line) = @_;
775  
776 70 ▶ return unless defined $line && length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line and length $line 0 70 70
Condition33%1/3
defined $line and length $line
!ll&&!rl&&r
0070
MC/DC0%0/2
defined $line and length $line
defined $line length $line
Truth table33%1/3
A and B
A= defined $lineB= length $line
ABresult
0X0
100
111
777  
778 70 my @decoded = $self->_jsonl->decode($line);
779 70 ▶ $log->trace(sprintf("Raw line: %s", $line)) if $log->is_trace;
Branch: 1 branch
BranchTrueFalseTotal
if $Claude::Agent::Query::log->is_trace 0 70 70
780  
781 70 my $limit = $ENV{CLAUDE_AGENT_JSONL_BUFFER_MAX};
782 70 ▶ $limit = 1_000_000 unless defined $limit && $limit =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $limit and $limit =~ /^\d+$/u 70 0 70
Condition33%1/3
defined $limit and $limit =~ /^\d+$/u
!ll&&!rl&&r
7000
MC/DC0%0/2
defined $limit and $limit =~ /^\d+$/u
defined $limit $limit =~ /^\d+$/u
Truth table33%1/3
A and B
A= defined $limitB= $limit =~ /^\d+$/u
ABresult
0X0
100
111
783 70 ▶ $limit = 100_000 if $limit < 100_000;
Branch: 1 branch
BranchTrueFalseTotal
if $limit < 100000 0 70 70
784 70 ▶ $limit = 10_000_000 if $limit > 10_000_000;
Branch: 1 branch
BranchTrueFalseTotal
if $limit > 10000000 0 70 70
785 70 ▶ if ($self->_jsonl->remaining && length($self->_jsonl->remaining) > $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_jsonl->remaining and length $self->_jsonl->remaining > $limit) 0 70 70
Condition33%1/3
$self->_jsonl->remaining and length $self->_jsonl->remaining > $limit
!ll&&!rl&&r
7000
MC/DC0%0/2
$self->_jsonl->remaining and length $self->_jsonl->remaining > $limit
$self->_jsonl->remaining length $self->_jsonl->remaining > $limit
Truth table33%1/3
A and B
A= $self->_jsonl->remainingB= length $self->_jsonl->remaining > $limit
ABresult
0X0
100
111
786 0 $log->debug("JSON::Lines buffer overflow, reinitializing");
787 0 $self->_jsonl($self->_build_jsonl);
788 }
789  
790 70 for my $data (@decoded) {
791 69 ▶ next unless ref $data eq 'HASH' && defined $data->{type};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" and defined $data->{"type"} 1 68 69
Condition66%2/3
ref $data eq "HASH" and defined $data->{"type"}
!ll&&!rl&&r
0168
MC/DC50%1/2
ref $data eq "HASH" and defined $data->{"type"}
ref $data eq "HASH" defined $data->{"type"}
Truth table66%2/3
A and B
A= ref $data eq "HASH"B= defined $data->{"type"}
ABresult
0X0
100
111
792 68 my $type = $data->{type};
793 68 ▶ $log->debug(sprintf("Query: received %s%s", $type, defined $data->{subtype} ? "/$data->{subtype}" : ''));
Branch: 1 branch
BranchTrueFalseTotal
defined $data->{'subtype'} ? : 18 50 68
794  
795 68 ▶ if ($type eq 'control_response') { $self->_on_control_response($data); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "control_response") 22 46 68
796 46 ▶ if ($type eq 'control_request') { $self->_on_control_request($data); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "control_request") 19 27 46
797 27 ▶ if ($type eq 'control_cancel_request') { $self->_on_control_cancel($data); next }
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "control_cancel_request") 1 26 27
798 26 ▶ next if $CONSUMED{$type};
Branch: 1 branch
BranchTrueFalseTotal
if $CONSUMED{$type} 1 25 26
799  
800 25 ▶ if ($type eq 'system' && ($data->{subtype} // '') eq 'session_state_changed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "system" and ($data->{"subtype"} // "") eq "session_state_changed") 7 18 25
Condition80%4/5
$type eq "system" and ($data->{"subtype"} // "") eq "session_state_changed"
!ll&&!rl&&r
1447
$data->{"subtype"} // ""
l!l
110
MC/DC50%1/2
$type eq "system" and ($data->{"subtype"} // "") eq "session_state_changed"
$type eq "system" $data->{"subtype"}
Truth table66%2/3
A and B
A= $type eq "system"B= $data->{"subtype"}
ABresult
0X0
100
111
801 7 $self->_on_session_state($data->{state});
802 7 ▶ next if $data->{sdk_host_only};
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"sdk_host_only"} 7 0 7
803 }
804  
805 18 my $msg = eval { Claude::Agent::Message->from_json($data) };
806 18 ▶ unless ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($msg) 0 18 18
807 0 $log->debug(sprintf("Query: could not parse %s message: %s", $type, $@));
808 0 next;
809 }
810  
811 18 ▶ if ($type eq 'system' && $msg->subtype eq 'init') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'system' and $msg->subtype eq 'init') { } 3 15 18
elsif ($type eq 'result') { } 7 8 15
elsif ($type eq 'assistant' || $type eq 'stream_event' and not $msg->has_parent_tool_use_id) { } 3 10 13
Condition100%3/3
$type eq "system" and $msg->subtype eq "init"
!ll&&!rl&&r
1413
MC/DC100%2/2
$type eq "system" and $msg->subtype eq "init"
$type eq "system" $msg->subtype eq "init"
Truth table100%3/3
A and B
A= $type eq "system"B= $msg->subtype eq "init"
ABresult
0X0
100
111
812 3 $self->_session_id($msg->get_session_id);
813 3 ▶ $log->debug(sprintf("Query: session %s", $self->_session_id // 'none'));
Condition50%1/2
$self->_session_id // "none"
l!l
30
MC/DC0%0/1
$self->_session_id // "none"
$self->_session_id
Truth table50%1/2
A
A= $self->_session_id
Aresult
11
00
814 }
815 elsif ($type eq 'result') {
816 7 $self->_on_result;
817 }
818 ▶ elsif (($type eq 'assistant' || $type eq 'stream_event') && !$msg->has_parent_tool_use_id) {
Condition83%5/6
$type eq "assistant" || $type eq "stream_event" and not $msg->has_parent_tool_use_id
!ll&&!rl&&r
503
$type eq "assistant" or $type eq "stream_event"
l!l&&r!l&&!r
215
MC/DC66%2/3
$type eq "assistant" || $type eq "stream_event" and not $msg->has_parent_tool_use_id
$type eq "assistant" $type eq "stream_event" not $msg->has_parent_tool_use_id
Truth table60%3/5
A or B and not(C)
A= $type eq "assistant"B= $type eq "stream_event"C= not $msg->has_parent_tool_use_id
ABCresult
00X0
1X00
0100
1X11
0111
819 3 ▶ if ($self->_result_received) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_result_received) 1 2 3
820 1 $self->_result_received(0);
821 1 $self->_clear_run_end_timer;
822 }
823 3 $self->_turn_in_progress(1);
824 }
825  
826 18 $self->_deliver($msg);
827 }
828 70 return;
829 }
830  
831 18 ▶sub _deliver {
Subroutine _deliver: called CC=3 SCAR=11.3
832 18 my ($self, $msg) = @_;
833  
834 18 ▶ if ($self->_processing_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_processing_message) 0 18 18
835 0 push @{$self->_messages}, $msg;
836 0 return;
837 }
838 18 $self->_processing_message(1);
839 18 ▶ if (@{$self->_pending_futures}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->_pending_futures;}) { } 1 17 18
840 1 my $future = shift @{$self->_pending_futures};
841 1 $future->done($msg);
842 }
843 else {
844 17 push @{$self->_messages}, $msg;
845 }
846 18 $self->_processing_message(0);
847 18 return;
848 }
849  
850 7 ▶sub _on_result {
Subroutine _on_result: called CC=6 SCAR=18.0
851 7 my ($self) = @_;
852 7 $self->_result_received(1);
853 7 $self->_turn_in_progress(0);
854 7 ▶ return if $self->persistent || !$self->_needs_stdin_open;
Branch: 1 branch
BranchTrueFalseTotal
if $self->persistent or not $self->_needs_stdin_open 2 5 7
Condition66%2/3
$self->persistent or not $self->_needs_stdin_open
l!l&&r!l&&!r
205
MC/DC50%1/2
$self->persistent or not $self->_needs_stdin_open
$self->persistent not $self->_needs_stdin_open
Truth table66%2/3
A or not(B)
A= $self->persistentB= not $self->_needs_stdin_open
ABresult
1X1
011
000
855  
856 5 my $state = $self->_session_state;
857 5 ▶ if (!defined $state || $state eq 'idle') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $state or $state eq 'idle') { } 2 3 5
elsif ($state ne 'requires_action') { } 3 0 3
Condition100%3/3
not defined $state or $state eq "idle"
l!l&&r!l&&!r
113
MC/DC100%2/2
not defined $state or $state eq "idle"
not defined $state $state eq "idle"
Truth table100%3/3
not(A) or B
A= not defined $stateB= $state eq "idle"
ABresult
1X1
011
000
858 2 $self->_end_run;
859 }
860 elsif ($state ne 'requires_action') {
861 3 $self->_arm_run_end_ceiling;
862 }
863 5 return;
864 }
865  
866 7 ▶sub _on_session_state {
Subroutine _on_session_state: called CC=9 SCAR=23.3
867 7 my ($self, $state) = @_;
868 7 $self->_session_state($state);
869 7 ▶ return unless $self->_result_received && !$self->_turn_in_progress;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_result_received and not $self->_turn_in_progress 4 3 7
Condition66%2/3
$self->_result_received and not $self->_turn_in_progress
!ll&&!rl&&r
403
MC/DC50%1/2
$self->_result_received and not $self->_turn_in_progress
$self->_result_received not $self->_turn_in_progress
Truth table66%2/3
A and not(B)
A= $self->_result_receivedB= not $self->_turn_in_progress
ABresult
0X0
100
111
870 3 ▶ return if $self->persistent || !$self->_needs_stdin_open;
Branch: 1 branch
BranchTrueFalseTotal
if $self->persistent or not $self->_needs_stdin_open 1 2 3
Condition66%2/3
$self->persistent or not $self->_needs_stdin_open
l!l&&r!l&&!r
102
MC/DC50%1/2
$self->persistent or not $self->_needs_stdin_open
$self->persistent not $self->_needs_stdin_open
Truth table66%2/3
A or not(B)
A= $self->persistentB= not $self->_needs_stdin_open
ABresult
1X1
011
000
871 2 ▶ $state //= '';
Condition50%1/2
$state //= ""
l!l
20
MC/DC0%0/1
$state //= ""
$state
Truth table50%1/2
A
A= $state
Aresult
11
00
872 2 ▶ if ($state eq 'idle') {
Branch: 3 branches
BranchTrueFalseTotal
if ($state eq 'idle') { } 1 1 2
elsif ($state eq 'requires_action') { } 1 0 1
elsif ($state eq 'running') { } 0 0 0
873 1 $self->_end_run;
874 }
875 elsif ($state eq 'requires_action') {
876 1 $self->_clear_run_end_timer;
877 }
878 elsif ($state eq 'running') {
879 0 $self->_arm_run_end_ceiling;
880 }
881 2 return;
882 }
883  
884 3 ▶sub _run_end_ceiling_ms {
Subroutine _run_end_ceiling_ms: called CC=5 SCAR=16.2
885 3 my ($self) = @_;
886 3 my $o = $self->options;
887 3 ▶ my $ms = $o->has_env ? $o->env->{CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$o->has_env ? : 1 2 3
888 3 ▶ $ms //= $ENV{CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS};
Condition66%2/3
$ms //= $ENV{"CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS"}
l!l&&r!l&&!r
102
MC/DC50%1/2
$ms //= $ENV{"CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS"}
$ms $ENV{"CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS"}
Truth table66%2/3
A //= B
A= $msB= $ENV{"CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS"}
ABresult
1X1
011
000
889 3 ▶ $ms = 600_000 unless defined $ms && $ms =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ms and $ms =~ /^\d+$/u 2 1 3
Condition66%2/3
defined $ms and $ms =~ /^\d+$/u
!ll&&!rl&&r
201
MC/DC50%1/2
defined $ms and $ms =~ /^\d+$/u
defined $ms $ms =~ /^\d+$/u
Truth table66%2/3
A and B
A= defined $msB= $ms =~ /^\d+$/u
ABresult
0X0
100
111
890 3 return $ms;
891 }
892  
893 3 ▶sub _arm_run_end_ceiling {
Subroutine _arm_run_end_ceiling: called CC=2 SCAR=7.0
894 3 my ($self) = @_;
895 3 $self->_clear_run_end_timer;
896 3 my $ms = $self->_run_end_ceiling_ms;
897 3 ▶ return if $ms == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ms == 0 0 3 3
898 1 ▶ $self->_run_end_timer($self->_loop->delay_future(after => $ms / 1000)->on_done(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
899 1 $log->debug("Query: run end ceiling reached, closing stdin");
900 1 $self->_end_run;
901 3 }));
902 3 return;
903 }
904  
905 34 ▶sub _clear_run_end_timer {
Subroutine _clear_run_end_timer: called CC=3 SCAR=11.0
906 34 my ($self) = @_;
907 34 ▶ my $timer = $self->_run_end_timer or return;
Branch: 1 branch
BranchTrueFalseTotal
my $timer = $self->_run_end_timer or return 3 31 34
908 3 ▶ $timer->cancel unless $timer->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $timer->is_ready 2 1 3
909 3 $self->_run_end_timer(undef);
910 3 return;
911 }
912  
913 4 ▶sub _end_run {
Subroutine _end_run: called CC=1 SCAR=0.0
914 4 my ($self) = @_;
915 4 $self->_clear_run_end_timer;
916 4 $self->_end_input;
917 4 return;
918 }
919  
920 9 ▶sub _await {
Subroutine _await: called CC=5 SCAR=16.4
921 9 my ($self, $future, $timeout) = @_;
922 9 ▶ $timeout //= 60;
Condition50%1/2
$timeout //= 60
l!l
90
MC/DC0%0/1
$timeout //= 60
$timeout
Truth table50%1/2
A
A= $timeout
Aresult
11
00
923 9 my $deadline = Time::HiRes::time() + $timeout;
924 9 ▶ while (!$future->is_ready && Time::HiRes::time() < $deadline) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $future->is_ready and &Time::HiRes::time() < $deadline) 9 9 18
Condition66%2/3
not $future->is_ready and &Time::HiRes::time() < $deadline
!ll&&!rl&&r
909
MC/DC50%1/2
not $future->is_ready and &Time::HiRes::time() < $deadline
not $future->is_ready &Time::HiRes::time() < $deadline
Truth table66%2/3
not(A) and B
A= not $future->is_readyB= &Time::HiRes::time() < $deadline
ABresult
0X0
100
111
925 9 $self->_loop->loop_once(0.05);
926 }
927 9 ▶ $future->cancel unless $future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 0 9 9
928 9 return $future;
929 }
930  
931 0 ▶sub _sync {
Subroutine _sync: not called CC=3 SCAR=24.8
932 0 my ($self, $future, $timeout) = @_;
933 0 $self->_await($future, $timeout);
934 0 ▶ return $future->get if $future->is_done;
Branch: 1 branch
BranchTrueFalseTotal
if $future->is_done 0 0 0
935 0 ▶ $log->debug(sprintf("Query: request failed: %s", $future->is_failed ? scalar $future->failure : 'timed out'));
Branch: 1 branch
BranchTrueFalseTotal
$future->is_failed ? : 0 0 0
936 0 return;
937 }
938  
939 20 ▶sub send_user_message {
Subroutine send_user_message: called CC=4 SCAR=13.9
Pod documented
940 20 my ($self, $content, %args) = @_;
941  
942 20 ▶ return 0 if $self->_finished;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_finished 1 19 20
943 my $ok = $self->_write({
944 type => 'user',
945 19 ▶ session_id => $args{session_id} // '',
Condition100%2/2
$args{"session_id"} // ""
l!l
316
MC/DC100%1/1
$args{"session_id"} // ""
$args{"session_id"}
Truth table100%2/2
A
A= $args{"session_id"}
Aresult
11
00
946 message => { role => 'user', content => $content },
947 parent_tool_use_id => undef,
948 });
949 19 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 19 0 19
950 19 $self->_result_received(0);
951 19 $self->_turn_in_progress(1);
952 19 $self->_clear_run_end_timer;
953 }
954 19 return $ok;
955 }
956  
957 1 ▶sub interrupt_async {
Subroutine interrupt_async: called CC=1 SCAR=0.0
Pod documented
958 1 my ($self) = @_;
959 1 return $self->_send_control_request({ subtype => 'interrupt' });
960 }
961  
962 2 ▶sub set_permission_mode_async {
Subroutine set_permission_mode_async: called CC=1 SCAR=0.0
Pod documented
963 2 my ($self, $mode) = @_;
964 2 return $self->_send_control_request({ subtype => 'set_permission_mode', mode => $mode });
965 }
966  
967 1 ▶sub set_model_async {
Subroutine set_model_async: called CC=1 SCAR=0.0
Pod documented
968 1 my ($self, $model) = @_;
969 1 return $self->_send_control_request({ subtype => 'set_model', model => $model });
970 }
971  
972 1 ▶sub set_max_thinking_tokens_async {
Subroutine set_max_thinking_tokens_async: called CC=1 SCAR=0.0
Pod documented
973 1 my ($self, $tokens) = @_;
974 1 return $self->_send_control_request({ subtype => 'set_max_thinking_tokens', max_thinking_tokens => $tokens });
975 }
976  
977 1 ▶sub rewind_files_async {
Subroutine rewind_files_async: called CC=1 SCAR=0.0
Pod documented
978 1 my ($self, $user_message_uuid) = @_;
979 1 return $self->_send_control_request({ subtype => 'rewind_files', user_message_id => $user_message_uuid });
980 }
981  
982 3 ▶sub mcp_status_async {
Subroutine mcp_status_async: called CC=1 SCAR=0.0
Pod documented
983 3 my ($self) = @_;
984 3 return $self->_send_control_request({ subtype => 'mcp_status' });
985 }
986  
987 1 ▶sub get_context_usage_async {
Subroutine get_context_usage_async: called CC=1 SCAR=0.0
Pod documented
988 1 my ($self) = @_;
989 1 return $self->_send_control_request({ subtype => 'get_context_usage' });
990 }
991  
992 0 ▶sub reconnect_mcp_server_async {
Subroutine reconnect_mcp_server_async: not called CC=1 SCAR=6.9
Pod documented
993 0 my ($self, $name) = @_;
994 0 return $self->_send_control_request({ subtype => 'mcp_reconnect', serverName => $name });
995 }
996  
997 1 ▶sub toggle_mcp_server_async {
Subroutine toggle_mcp_server_async: called CC=2 SCAR=7.2
Pod documented
998 1 my ($self, $name, $enabled) = @_;
999 1 ▶ return $self->_send_control_request({ subtype => 'mcp_toggle', serverName => $name, enabled => ($enabled ? \1 : \0) });
Branch: 1 branch
BranchTrueFalseTotal
$enabled ? : 0 1 1
1000 }
1001  
1002 0 ▶sub stop_task_async {
Subroutine stop_task_async: not called CC=1 SCAR=6.9
Pod documented
1003 0 my ($self, $task_id) = @_;
1004 0 return $self->_send_control_request({ subtype => 'stop_task', task_id => $task_id });
1005 }
1006  
1007 0 ▶sub interrupt { my $self = shift; return $self->_sync($self->interrupt_async(@_)) }
Subroutine interrupt: not called CC=1 SCAR=6.9
Pod documented
1008 0 ▶sub set_permission_mode { my $self = shift; return $self->_sync($self->set_permission_mode_async(@_)) }
Subroutine set_permission_mode: not called CC=1 SCAR=6.9
Pod documented
1009 0 ▶sub set_model { my $self = shift; return $self->_sync($self->set_model_async(@_)) }
Subroutine set_model: not called CC=1 SCAR=6.9
Pod documented
1010 0 ▶sub set_max_thinking_tokens { my $self = shift; return $self->_sync($self->set_max_thinking_tokens_async(@_)) }
Subroutine set_max_thinking_tokens: not called CC=1 SCAR=6.9
Pod documented
1011 0 ▶sub rewind_files { my $self = shift; return $self->_sync($self->rewind_files_async(@_)) }
Subroutine rewind_files: not called CC=1 SCAR=6.9
Pod documented
1012 0 ▶sub mcp_status { my $self = shift; return $self->_sync($self->mcp_status_async(@_)) }
Subroutine mcp_status: not called CC=1 SCAR=6.9
Pod documented
1013 0 ▶sub get_context_usage { my $self = shift; return $self->_sync($self->get_context_usage_async(@_)) }
Subroutine get_context_usage: not called CC=1 SCAR=6.9
Pod documented
1014 0 ▶sub reconnect_mcp_server { my $self = shift; return $self->_sync($self->reconnect_mcp_server_async(@_)) }
Subroutine reconnect_mcp_server: not called CC=1 SCAR=6.9
Pod documented
1015 0 ▶sub toggle_mcp_server { my $self = shift; return $self->_sync($self->toggle_mcp_server_async(@_)) }
Subroutine toggle_mcp_server: not called CC=1 SCAR=6.9
Pod documented
1016 0 ▶sub stop_task { my $self = shift; return $self->_sync($self->stop_task_async(@_)) }
Subroutine stop_task: not called CC=1 SCAR=6.9
Pod documented
1017  
1018 2 ▶sub server_info {
Subroutine server_info: called CC=1 SCAR=0.0
Pod documented
1019 2 my ($self) = @_;
1020 2 return $self->_init_result;
1021 }
1022  
1023 1 ▶sub supported_commands {
Subroutine supported_commands: called CC=3 SCAR=12.5
Pod documented
1024 1 my ($self) = @_;
1025 1 ▶ my $info = $self->_init_result or return;
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->_init_result or return 1 0 1
1026 1 ▶ return $info->{commands} // $info->{supportedCommands};
Condition33%1/3
$info->{"commands"} // $info->{"supportedCommands"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$info->{"commands"} // $info->{"supportedCommands"}
$info->{"commands"} $info->{"supportedCommands"}
Truth table33%1/3
A // B
A= $info->{"commands"}B= $info->{"supportedCommands"}
ABresult
1X1
011
000
1027 }
1028  
1029 1 ▶sub supported_models {
Subroutine supported_models: called CC=3 SCAR=12.5
Pod documented
1030 1 my ($self) = @_;
1031 1 ▶ my $info = $self->_init_result or return;
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->_init_result or return 1 0 1
1032 1 ▶ return $info->{models} // $info->{supportedModels};
Condition33%1/3
$info->{"models"} // $info->{"supportedModels"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$info->{"models"} // $info->{"supportedModels"}
$info->{"models"} $info->{"supportedModels"}
Truth table33%1/3
A // B
A= $info->{"models"}B= $info->{"supportedModels"}
ABresult
1X1
011
000
1033 }
1034  
1035 1 ▶sub output_style {
Subroutine output_style: called CC=3 SCAR=12.5
Pod documented
1036 1 my ($self) = @_;
1037 1 ▶ my $info = $self->_init_result or return;
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->_init_result or return 1 0 1
1038 1 ▶ return $info->{output_style} // $info->{outputStyle};
Condition33%1/3
$info->{"output_style"} // $info->{"outputStyle"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$info->{"output_style"} // $info->{"outputStyle"}
$info->{"output_style"} $info->{"outputStyle"}
Truth table33%1/3
A // B
A= $info->{"output_style"}B= $info->{"outputStyle"}
ABresult
1X1
011
000
1039 }
1040  
1041 0 ▶sub available_output_styles {
Subroutine available_output_styles: not called CC=3 SCAR=24.8
Pod documented
1042 0 my ($self) = @_;
1043 0 ▶ my $info = $self->_init_result or return;
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->_init_result or return 0 0 0
1044 0 ▶ return $info->{available_output_styles} // $info->{availableOutputStyles};
Condition0%0/3
$info->{"available_output_styles"} // $info->{"availableOutputStyles"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{"available_output_styles"} // $info->{"availableOutputStyles"}
$info->{"available_output_styles"} $info->{"availableOutputStyles"}
Truth table0%0/3
A // B
A= $info->{"available_output_styles"}B= $info->{"availableOutputStyles"}
ABresult
1X1
011
000
1045 }
1046  
1047 1 ▶sub session_id { $_[0]->_session_id }
Subroutine session_id: called CC=1 SCAR=0.0
Pod documented
1048 0 ▶sub is_finished { $_[0]->_finished }
Subroutine is_finished: not called CC=1 SCAR=6.9
Pod documented
1049 1 ▶sub error { $_[0]->_error }
Subroutine error: called CC=1 SCAR=0.0
Pod documented
1050  
1051 11 ▶sub next {
Subroutine next: called CC=10 SCAR=28.6
Pod documented
1052 11 my ($self) = @_;
1053  
1054 11 ▶ return shift @{$self->_messages} if @{$self->_messages};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->_messages;} 10 1 11
1055  
1056 1 ▶ my $timeout = $self->options->query_timeout // 600;
Condition50%1/2
$self->options->query_timeout // 600
l!l
10
MC/DC0%0/1
$self->options->query_timeout // 600
$self->options->query_timeout
Truth table50%1/2
A
A= $self->options->query_timeout
Aresult
11
00
1057 1 ▶ $timeout = 600 if $timeout <= 0 || $timeout > 3600;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout <= 0 or $timeout > 3600 0 1 1
Condition33%1/3
$timeout <= 0 or $timeout > 3600
l!l&&r!l&&!r
001
MC/DC0%0/2
$timeout <= 0 or $timeout > 3600
$timeout <= 0 $timeout > 3600
Truth table33%1/3
A or B
A= $timeout <= 0B= $timeout > 3600
ABresult
1X1
011
000
1058 1 my $deadline = Time::HiRes::time() + $timeout;
1059  
1060 1 ▶ while (!@{$self->_messages} && !$self->_finished && Time::HiRes::time() < $deadline) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$self->_messages;} || $self->_finished and &Time::HiRes::time() < $deadline) 0 1 1
Condition33%2/6
not @{$self->_messages;} || $self->_finished and &Time::HiRes::time() < $deadline
!ll&&!rl&&r
100
@{$self->_messages;} || $self->_finished
l!l&&r!l&&!r
010
MC/DC0%0/3
not @{$self->_messages;} || $self->_finished and &Time::HiRes::time() < $deadline
@{$self->_messages;} $self->_finished &Time::HiRes::time() < $deadline
Truth table25%1/4
not(A || B) and C
A= @{$self->_messages;}B= $self->_finishedC= &Time::HiRes::time() < $deadline
ABCresult
1XX0
01X0
0000
0011
1061 0 $self->_loop->loop_once(0.1);
1062 }
1063  
1064 0 ▶ return shift @{$self->_messages} if @{$self->_messages};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->_messages;} 0 1 1
1065 1 ▶ return if $self->_finished;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_finished 1 0 1
1066  
1067 0 $self->_error("Query timed out after $timeout seconds");
1068 0 $log->debug(sprintf("Query: timed out after %d seconds", $timeout));
1069 0 return;
1070 }
1071  
1072 2 ▶sub next_async {
Subroutine next_async: called CC=3 SCAR=11.3
Pod documented
1073 2 my ($self) = @_;
1074  
1075 0 ▶ return Future->done(shift @{$self->_messages}) if @{$self->_messages};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->_messages;} 0 2 2
1076 2 ▶ return Future->done(undef) if $self->_finished;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_finished 0 2 2
1077  
1078 2 my $future = $self->_loop->new_future;
1079 2 push @{$self->_pending_futures}, $future;
1080 2 return $future;
1081 }
1082  
1083 11 ▶sub close_async {
Subroutine close_async: called CC=4 SCAR=22.6
Pod documented
1084 11 my ($self) = @_;
1085  
1086 11 ▶ return Future->done if $self->_closed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_closed 5 6 11
1087 6 $self->_closed(1);
1088 6 $self->_clear_run_end_timer;
1089  
1090 6 ▶ if (!$self->_process || $self->_finished) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_process or $self->_finished) 6 0 6
Condition33%1/3
not $self->_process or $self->_finished
l!l&&r!l&&!r
600
MC/DC0%0/2
not $self->_process or $self->_finished
not $self->_process $self->_finished
Truth table33%1/3
not(A) or B
A= not $self->_processB= $self->_finished
ABresult
1X1
011
000
1091 6 $self->_end_input;
1092 6 $self->_finished(1);
1093 6 $self->_finish_pending;
1094 6 return Future->done;
1095 }
1096  
1097 0 my $loop = $self->_loop;
1098 0 ▶ my $wait = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1099 0 my ($secs) = @_;
1100 0 ▶ return Future->done if $self->_finished;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_finished 0 0 0
1101 0 return Future->wait_any($self->_exit_future, $loop->delay_future(after => $secs));
1102 0 };
1103 0 ▶ my $signal = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1104 0 my ($sig) = @_;
1105 0 ▶ return if $self->_finished;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_finished 0 0 0
1106 0 $log->debug("Query: sending SIG$sig");
1107 0 eval { $self->_process->kill($sig) };
1108 0 return;
1109 0 };
1110  
1111 return $self->_send_control_request({ subtype => 'interrupt' }, 2)
1112 0 ▶ ->else(sub { Future->done })
Subroutine __ANON__: not called CC=1 SCAR=6.9
1113 0 ▶ ->then(sub { $self->_end_input; $wait->(5) })
Subroutine __ANON__: not called CC=1 SCAR=6.9
1114 0 ▶ ->then(sub { $signal->('INT'); $wait->(5) })
Subroutine __ANON__: not called CC=1 SCAR=6.9
1115 0 ▶ ->then(sub { $signal->('TERM'); $wait->(5) })
Subroutine __ANON__: not called CC=1 SCAR=6.9
1116 0 ▶ ->then(sub { $signal->('KILL'); $wait->(1) })
Subroutine __ANON__: not called CC=1 SCAR=6.9
1117 0 ▶ ->then(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1118 0 $self->_finish_pending;
1119 0 return Future->done;
1120 0 });
1121 }
1122  
1123 6 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
1124 6 my ($self) = @_;
1125 6 $self->_await($self->close_async, 20);
1126 6 return;
1127 }
1128  
1129 1 ▶sub cleanup {
Subroutine cleanup: called CC=1 SCAR=0.0
Pod documented
1130 1 my ($self) = @_;
1131 1 return $self->close;
1132 }
1133  
1134 8 1;
1135  
1136 __END__
« Agent/DryRun.pm ↑ Summary Agent/Hook/Matcher.pm »