| 1 | package Langertha::Raider::CLI::Runner; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Internal runner of one raider CLI prompt, for a human or a machine | ||||||||||||||||||||||||||||||||
| 3 | 56 | our $VERSION = '0.503'; | |||||||||||||||||||||||||||||||
| 4 | 56 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 56 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 56 | ▶ | use Config; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 56 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 56 | ▶ | use POSIX qw( sigprocmask SIG_UNBLOCK WNOHANG ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 56 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 56 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 56 | has app => ( | |||||||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 15 | isa => 'Langertha::Raider::CLI', | ||||||||||||||||||||||||||||||||
| 16 | required => 1, | ||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 56 | has output => ( | |||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 21 | isa => 'Langertha::Raider::CLI::Output', | ||||||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | has err => ( | ||||||||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 27 | 31 | ▶ | default => sub { \*STDERR }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | 56 | ); | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | # The run in progress: { machine, t0 }. | ||||||||||||||||||||||||||||||||
| 31 | 56 | has _current => ( | |||||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 33 | init_arg => undef, | ||||||||||||||||||||||||||||||||
| 34 | clearer => '_clear_current', | ||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 134 | ▶ | sub run_prompt { | ||||||||||||||||||||||||||||||
|
Subroutine
run_prompt: called CC=8 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 39 | 134 | my ( $self, $text, %o ) = @_; | |||||||||||||||||||||||||||||||
| 40 | 134 | ▶ | return 1 unless defined $text && length $text; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and length $text
MC/DC50%1/2
defined $text and length $text
defined $text
length $text
Truth table66%2/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||||||
| 41 | 133 | my $app = $self->app; | |||||||||||||||||||||||||||||||
| 42 | 133 | my $out = $self->output; | |||||||||||||||||||||||||||||||
| 43 | 133 | my $machine = $o{machine}; | |||||||||||||||||||||||||||||||
| 44 | 133 | my $t0 = Time::HiRes::time(); | |||||||||||||||||||||||||||||||
| 45 | 133 | $self->_current({ machine => $machine, t0 => $t0 }); | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | # Handled right in the signal handler: a die from it would be swallowed | ||||||||||||||||||||||||||||||||
| 48 | # by whichever eval the run happens to be in (LWP, the raid loop). The | ||||||||||||||||||||||||||||||||
| 49 | # first SIGINT only cancels, so the run still ends by itself. | ||||||||||||||||||||||||||||||||
| 50 | 133 | my $cancelled_by; | |||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | local $SIG{INT} = $o{catch_signals} ? sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return $cancelled_by = 'INT' if !$cancelled_by && $self->cancel_run; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $cancelled_by and $self->cancel_run
MC/DC0%0/2
not $cancelled_by and $self->cancel_run
not $cancelled_by
$self->cancel_run
Truth table0%0/3
not(A) and B
A= not $cancelled_byB= $self->cancel_run
| |||||||||||||||||||||||||||||||||
| 53 | 0 | $self->interrupt(INT => $machine, $self->elapsed_since($t0)); | |||||||||||||||||||||||||||||||
| 54 | 133 | ▶ | } : $SIG{INT}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 133 | ▶ | local $SIG{TERM} = $o{catch_signals} ? sub { $self->interrupt(TERM => $machine, $self->elapsed_since($t0)) } : $SIG{TERM}; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | my $end = $app->run_prompt($text, | ||||||||||||||||||||||||||||||||
| 58 | ( $o{session} ? ( session => $o{session} ) : () ), | ||||||||||||||||||||||||||||||||
| 59 | 840 | ▶ | on_event => sub { $self->event(@_) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 60 | 133 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | # The run has ended: no signal may cut its outcome short any more. | ||||||||||||||||||||||||||||||||
| 62 | 132 | ▶ | $SIG{INT} = $SIG{TERM} = 'IGNORE' if $cancelled_by; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 132 | $self->_clear_current; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 132 | my $ok = $self->_report($machine, $end, $cancelled_by); | |||||||||||||||||||||||||||||||
| 66 | 132 | ▶ | return $ok unless $cancelled_by; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 0 | $out->out->flush; | |||||||||||||||||||||||||||||||
| 68 | 0 | return $self->die_of_signal($cancelled_by); | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | # Prints or writes the outcome of a run that ended (see run_prompt); true | ||||||||||||||||||||||||||||||||
| 72 | # for a completed run. | ||||||||||||||||||||||||||||||||
| 73 | 132 | ▶ | sub _report { | ||||||||||||||||||||||||||||||
|
Subroutine
_report: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||
| 74 | 132 | my ( $self, $machine, $end, $cancelled_by ) = @_; | |||||||||||||||||||||||||||||||
| 75 | 132 | my $app = $self->app; | |||||||||||||||||||||||||||||||
| 76 | 132 | my $out = $self->output; | |||||||||||||||||||||||||||||||
| 77 | 132 | ▶ | if ($end->{status} ne 'completed') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 21 | ▶ | unless ($machine) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | $end->{status} eq 'cancelled' | ||||||||||||||||||||||||||||||||
| 80 | ? $out->say_meta($cancelled_by ? 'cancelled (SIG'.$cancelled_by.')' : 'turn cancelled') | ||||||||||||||||||||||||||||||||
| 81 | 9 | ▶ | : $out->say_error($end->{error}); | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | 21 | return $self->_document($machine, $end); | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | 111 | ▶ | return $self->_document($machine, $end) if $machine; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 87 | $out->say_agent($end->{response}); | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 87 | my $r = $app->raider; | |||||||||||||||||||||||||||||||
| 90 | 87 | my $tok = $app->token_stats; | |||||||||||||||||||||||||||||||
| 91 | my $tok_part = $tok | ||||||||||||||||||||||||||||||||
| 92 | ? sprintf(' | tokens %d in / %d out / %d total', $tok->{prompt}, $tok->{completion}, $tok->{total}) | ||||||||||||||||||||||||||||||||
| 93 | 87 | ▶ | : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 87 | my $msgs = scalar @{$r->history}; | |||||||||||||||||||||||||||||||
| 95 | 87 | ▶ | my $last = $r->has_last_prompt_tokens ? $r->_last_prompt_tokens : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 87 | my $cap = $r->max_context_tokens; | |||||||||||||||||||||||||||||||
| 97 | 87 | ▶ | my $pct = $cap ? int(100 * $last / $cap) : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | $out->say_meta(sprintf('%ds | history %d msgs, %d/%d tok (%d%%)%s', | ||||||||||||||||||||||||||||||||
| 99 | 87 | $end->{elapsed}, $msgs, $last, $cap, $pct, $tok_part)); | |||||||||||||||||||||||||||||||
| 100 | 87 | return 1; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub interrupt { | ||||||||||||||||||||||||||||||
|
Subroutine
interrupt: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 105 | 0 | my ( $self, $signal, $machine, $elapsed ) = @_; | |||||||||||||||||||||||||||||||
| 106 | # A second signal must not cut the document short. | ||||||||||||||||||||||||||||||||
| 107 | 0 | local $SIG{INT} = 'IGNORE'; | |||||||||||||||||||||||||||||||
| 108 | 0 | local $SIG{TERM} = 'IGNORE'; | |||||||||||||||||||||||||||||||
| 109 | 0 | $self->terminate_children; | |||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if (ref $self && $self->_current) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $self and $self->_current
MC/DC0%0/2
ref $self and $self->_current
ref $self
$self->_current
Truth table0%0/3
A and B
A= ref $selfB= $self->_current
| |||||||||||||||||||||||||||||||||
| 111 | 0 | $self->abandon($signal); | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | elsif ($machine) { | ||||||||||||||||||||||||||||||||
| 114 | 0 | $machine->event('run.state', state => 'interrupted'); | |||||||||||||||||||||||||||||||
| 115 | 0 | $self->_document($machine, { status => 'interrupted', signal => $signal, elapsed => $elapsed }); | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | unless ($machine) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | 0 | $self->output->say_meta('interrupted (SIG'.$signal.')'); | |||||||||||||||||||||||||||||||
| 119 | 0 | $self->output->out->flush; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | 0 | return $self->die_of_signal($signal); | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 4 | ▶ | sub cancel_run { | ||||||||||||||||||||||||||||||
|
Subroutine
cancel_run: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 126 | 4 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 127 | 4 | ▶ | return 0 unless $self->_current && $self->app->cancel_run; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_current and $self->app->cancel_run
MC/DC0%0/2
$self->_current and $self->app->cancel_run
$self->_current
$self->app->cancel_run
Truth table33%1/3
A and B
A= $self->_currentB= $self->app->cancel_run
| |||||||||||||||||||||||||||||||||
| 128 | 4 | $self->terminate_children; | |||||||||||||||||||||||||||||||
| 129 | 4 | return 1; | |||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | sub abandon { | ||||||||||||||||||||||||||||||
|
Subroutine
abandon: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 134 | 3 | my ( $self, $signal ) = @_; | |||||||||||||||||||||||||||||||
| 135 | 3 | ▶ | my $current = $self->_current or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | # Still current, so the run.state of end_run reaches the stream. | ||||||||||||||||||||||||||||||||
| 137 | 1 | my $end = $self->app->end_run(interrupted => signal => $signal); | |||||||||||||||||||||||||||||||
| 138 | 1 | $self->_clear_current; | |||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | my $machine = $current->{machine} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | unless ($end) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 141 | # Interrupted before the application started the run. | ||||||||||||||||||||||||||||||||
| 142 | 0 | $end = { status => 'interrupted', signal => $signal, elapsed => $self->elapsed_since($current->{t0}) }; | |||||||||||||||||||||||||||||||
| 143 | 0 | $machine->event('run.state', state => 'interrupted'); | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | 0 | $self->_document($machine, $end); | |||||||||||||||||||||||||||||||
| 146 | 0 | return; | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 840 | ▶ | sub event { | ||||||||||||||||||||||||||||||
|
Subroutine
event: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 151 | 840 | my ( $self, $type, %payload ) = @_; | |||||||||||||||||||||||||||||||
| 152 | 840 | ▶ | my $current = $self->_current or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 840 | ▶ | my $machine = $current->{machine} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | 204 | ▶ | return if $type eq 'message' && ($payload{role} // '') eq 'user'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$type eq "message" and ($payload{"role"} // "") eq "user"
$payload{"role"} // ""
MC/DC50%1/2
$type eq "message" and ($payload{"role"} // "") eq "user"
$type eq "message"
$payload{"role"}
Truth table66%2/3
A and B
A= $type eq "message"B= $payload{"role"}
| |||||||||||||||||||||||||||||||||
| 155 | 168 | $machine->event($type, %payload); | |||||||||||||||||||||||||||||||
| 156 | 168 | return; | |||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | sub record { | ||||||||||||||||||||||||||||||
|
Subroutine
record: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 161 | 2 | my ( $self, $session, $type, %fields ) = @_; | |||||||||||||||||||||||||||||||
| 162 | 2 | return $self->app->record($session, $type, %fields); | |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | sub journal_error { | ||||||||||||||||||||||||||||||
|
Subroutine
journal_error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 167 | 4 | my ( $self, $session, $error ) = @_; | |||||||||||||||||||||||||||||||
| 168 | 4 | print { $self->err } 'warning: session '.$session->id.' not fully saved: '.$self->output->error_text($error)."\n"; | |||||||||||||||||||||||||||||||
| 169 | 4 | return; | |||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub die_of_signal { | ||||||||||||||||||||||||||||||
|
Subroutine
die_of_signal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 174 | 0 | my ( $self, $signal ) = @_; | |||||||||||||||||||||||||||||||
| 175 | 0 | my %number; | |||||||||||||||||||||||||||||||
| 176 | 0 | @number{ split ' ', $Config{sig_name} } = split ' ', $Config{sig_num}; | |||||||||||||||||||||||||||||||
| 177 | 0 | $SIG{$signal} = 'DEFAULT'; | |||||||||||||||||||||||||||||||
| 178 | # Perl blocks the signal while its handler runs; unblocked, the signal | ||||||||||||||||||||||||||||||||
| 179 | # takes effect right here instead of after exit has restored the handler. | ||||||||||||||||||||||||||||||||
| 180 | 0 | sigprocmask(SIG_UNBLOCK, POSIX::SigSet->new($number{$signal})); | |||||||||||||||||||||||||||||||
| 181 | 0 | kill $signal => $$; | |||||||||||||||||||||||||||||||
| 182 | 0 | exit 128 + $number{$signal}; | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | 4 | ▶ | sub terminate_grace { 2 } | ||||||||||||||||||||||||||||||
|
Subroutine
terminate_grace: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | 7 | ▶ | sub terminate_children { | ||||||||||||||||||||||||||||||
|
Subroutine
terminate_children: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 189 | 7 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 190 | 7 | ▶ | my @pids = $self->child_pids or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | 4 | $self->_signal_group_or_pid(TERM => $_) for @pids; | |||||||||||||||||||||||||||||||
| 192 | 4 | my %left = map { $_ => 1 } @pids; | |||||||||||||||||||||||||||||||
| 193 | 4 | my $deadline = Time::HiRes::time() + $self->terminate_grace; | |||||||||||||||||||||||||||||||
| 194 | 4 | ▶ | while (%left && Time::HiRes::time() < $deadline) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
%left and &Time::HiRes::time() < $deadline
MC/DC50%1/2
%left and &Time::HiRes::time() < $deadline
%left
&Time::HiRes::time() < $deadline
Truth table66%2/3
A and B
A= %leftB= &Time::HiRes::time() < $deadline
| |||||||||||||||||||||||||||||||||
| 195 | 8 | delete @left{ grep { waitpid($_, WNOHANG) != 0 } keys %left }; | |||||||||||||||||||||||||||||||
| 196 | 8 | ▶ | Time::HiRes::sleep(0.05) if %left; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | 4 | for my $pid (keys %left) { | |||||||||||||||||||||||||||||||
| 199 | 0 | $self->_signal_group_or_pid(KILL => $pid); | |||||||||||||||||||||||||||||||
| 200 | 0 | waitpid $pid, 0; | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | 4 | return; | |||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 7 | ▶ | sub child_pids { | ||||||||||||||||||||||||||||||
|
Subroutine
child_pids: called CC=11 SCAR=35.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 207 | 7 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 208 | 7 | my @children; | |||||||||||||||||||||||||||||||
| 209 | 7 | ▶ | if (-d '/proc/'.$$) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 210 | 7 | for my $dir (path('/proc')->children(qr/\A\d+\z/)) { | |||||||||||||||||||||||||||||||
| 211 | # "pid (comm) state ppid ...": comm may hold spaces and parens. | ||||||||||||||||||||||||||||||||
| 212 | 82 | ▶ | my $stat = eval { $dir->child('stat')->slurp } // next; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
eval { // (next)
MC/DC0%0/1
eval {
do {
$dir->child("stat")->slurp
}
} // (next)
eval {
do {
$dir->child("stat")->slurp
}
}
Truth table50%1/2
A
A= eval {
do {
$dir->child("stat")->slurp
}
}
| |||||||||||||||||||||||||||||||||
| 213 | 82 | ▶ | my ( $ppid ) = substr($stat, rindex($stat, ')') + 2) =~ /\A\S+ (\d+)/ or next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 214 | 82 | ▶ | push @children, 0 + $dir->basename if $ppid == $$; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||
| 216 | 7 | return @children; | |||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my $ps_pid = open(my $ps, '-|', 'ps', '-A', '-o', 'pid=', '-o', 'ppid=') or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | while (my $line = <$ps>) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my ( $pid, $ppid ) = $line =~ /(\d+)\s+(\d+)/ or next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | push @children, 0 + $pid if $ppid == $$ && $pid != $ps_pid; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ppid == $$ and $pid != $ps_pid
MC/DC0%0/2
$ppid == $$ and $pid != $ps_pid
$ppid == $$
$pid != $ps_pid
Truth table0%0/3
A and B
A= $ppid == $$B= $pid != $ps_pid
| |||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | 0 | close $ps; | |||||||||||||||||||||||||||||||
| 224 | 0 | return @children; | |||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | # The child's process group when it leads one, else the child alone. | ||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | sub _signal_group_or_pid { | ||||||||||||||||||||||||||||||
|
Subroutine
_signal_group_or_pid: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||
| 229 | 4 | my ( $self, $signal, $pid ) = @_; | |||||||||||||||||||||||||||||||
| 230 | 4 | ▶ | return kill($signal => -$pid) || kill($signal => $pid); | ||||||||||||||||||||||||||||||
|
Condition33%1/3
kill($signal, -$pid) || kill($signal, $pid)
MC/DC0%0/2
kill($signal, -$pid) || kill($signal, $pid)
kill($signal, -$pid)
kill($signal, $pid)
Truth table33%1/3
A || B
A= kill($signal, -$pid)B= kill($signal, $pid)
| |||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | sub elapsed_since { | ||||||||||||||||||||||||||||||
|
Subroutine
elapsed_since: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 235 | 0 | my ( $self, $t0 ) = @_; | |||||||||||||||||||||||||||||||
| 236 | 0 | return 0 + sprintf('%.3f', Time::HiRes::time() - $t0); | |||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | # The document of a run that ended ($end as from end_run, plus response | ||||||||||||||||||||||||||||||||
| 240 | # and metrics of a completed one) when there is a machine; true for a | ||||||||||||||||||||||||||||||||
| 241 | # completed run. | ||||||||||||||||||||||||||||||||
| 242 | 45 | ▶ | sub _document { | ||||||||||||||||||||||||||||||
|
Subroutine
_document: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 243 | 45 | my ( $self, $machine, $end ) = @_; | |||||||||||||||||||||||||||||||
| 244 | 45 | ▶ | if ($machine) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 245 | $machine->finish($machine->document($end->{status}, | ||||||||||||||||||||||||||||||||
| 246 | 36 | ▶ | map { exists $end->{$_} ? ( $_ => $end->{$_} ) : () } qw( response metrics error signal elapsed session ))); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||
| 248 | 45 | ▶ | return $end->{status} eq 'completed' ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | 56 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | 56 | 1; | |||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | __END__ | ||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | =pod | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | Langertha::Raider::CLI::Runner - Internal runner of one raider CLI prompt, for a human or a machine | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | version 0.503 | ||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||
| 269 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | # Internal to Langertha-Raider -- no API promise. | ||||||||||||||||||||||||||||||||
| 272 | my $runner = Langertha::Raider::CLI::Runner->new(app => $app, output => $out); | ||||||||||||||||||||||||||||||||
| 273 | my $ok = $runner->run_prompt('Summarize README.md'); | ||||||||||||||||||||||||||||||||
| 274 | $ok = $runner->run_prompt('Summarize README.md', machine => $machine); | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | B<Internal module.> Its interface may change without notice. | ||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||
| 280 | Runs one prompt through | ||||||||||||||||||||||||||||||||
| 281 | L<Langertha::Raider::Application/run_prompt>, which records the run in | ||||||||||||||||||||||||||||||||
| 282 | the session journal, and renders the outcome: the agent's answer plus a | ||||||||||||||||||||||||||||||||
| 283 | status line (elapsed seconds, history size against the context budget, | ||||||||||||||||||||||||||||||||
| 284 | token usage when tracing), or with a C<machine> | ||||||||||||||||||||||||||||||||
| 285 | (L<Langertha::Raider::CLI::Machine>) the run's document -- and, when that | ||||||||||||||||||||||||||||||||
| 286 | machine streams, the C<run.started>, C<run.state>, C<message> and tool | ||||||||||||||||||||||||||||||||
| 287 | events the application hands it. It also owns the signals of a run. | ||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | =head2 app | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | The L<Langertha::Raider::CLI> to run on. Required. | ||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | =head2 output | ||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | The L<Langertha::Raider::CLI::Output> to print to. Required. | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | =head2 err | ||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | Filehandle for warnings that must not end up in machine output (a | ||||||||||||||||||||||||||||||||
| 300 | session journal that cannot be written). Defaults to C<STDERR>. | ||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | =head2 run_prompt | ||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||
| 304 | my $ok = $runner->run_prompt($text, machine => $machine, session => $session, catch_signals => 1); | ||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | Returns true when the run finished, false when it failed (the error is | ||||||||||||||||||||||||||||||||
| 307 | printed, or with C<machine> is the C<failed> document). An empty prompt runs | ||||||||||||||||||||||||||||||||
| 308 | nothing and counts as finished. | ||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||
| 310 | With a C<session> (L<Langertha::Raider::Session>) the application records | ||||||||||||||||||||||||||||||||
| 311 | the run in its journal (L<Langertha::Raider::Application/run_prompt>), | ||||||||||||||||||||||||||||||||
| 312 | also when it failed or was interrupted; a machine document then names the | ||||||||||||||||||||||||||||||||
| 313 | session in C<session> (C<id>, C<path>). A journal write that fails is a | ||||||||||||||||||||||||||||||||
| 314 | warning (L</journal_error>); the run goes on. | ||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | With C<catch_signals>, a C<SIGINT> during the run cancels it (L</cancel_run>): | ||||||||||||||||||||||||||||||||
| 317 | it ends as C<cancelled> at its next safe point, its outcome is printed or | ||||||||||||||||||||||||||||||||
| 318 | written as always, and then the process dies of C<SIGINT> | ||||||||||||||||||||||||||||||||
| 319 | (L</die_of_signal>). A second C<SIGINT> while it is being cancelled, one | ||||||||||||||||||||||||||||||||
| 320 | before the application started the run, and a C<SIGTERM> end it as | ||||||||||||||||||||||||||||||||
| 321 | C<interrupted>: see L</interrupt>. | ||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | =head2 interrupt | ||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | $runner->interrupt(TERM => $machine, $elapsed); | ||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||
| 327 | Ends a run interrupted by the signal: ends the tool subprocesses still | ||||||||||||||||||||||||||||||||
| 328 | running (L</terminate_children>), ends the application's run as | ||||||||||||||||||||||||||||||||
| 329 | C<interrupted> (with the C<signal>), prints a note, or with a C<machine> | ||||||||||||||||||||||||||||||||
| 330 | writes the C<interrupted> document, then dies of that same signal through | ||||||||||||||||||||||||||||||||
| 331 | L</die_of_signal>. | ||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | With a C<machine> it also works as a class method, which | ||||||||||||||||||||||||||||||||
| 334 | L<Langertha::Raider::CLI::Main> uses for a signal during startup, before | ||||||||||||||||||||||||||||||||
| 335 | there is an app to run: the stream then has no C<run.started>, only the | ||||||||||||||||||||||||||||||||
| 336 | C<interrupted> state change and C<run.finished>. | ||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||
| 338 | =head2 cancel_run | ||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | my $cancelling = $runner->cancel_run; | ||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | Cancels the run in progress without leaving the process -- the REPL's | ||||||||||||||||||||||||||||||||
| 343 | first Ctrl-C, and the first C<SIGINT> of a one-shot run: asks the application to cancel it | ||||||||||||||||||||||||||||||||
| 344 | (L<Langertha::Raider::Application/cancel_run>), then ends the tool | ||||||||||||||||||||||||||||||||
| 345 | subprocesses still running (L</terminate_children>). The run ends as | ||||||||||||||||||||||||||||||||
| 346 | C<cancelled> at its next safe point and L</run_prompt> returns false, | ||||||||||||||||||||||||||||||||
| 347 | after C<turn cancelled> (or with a machine, the C<cancelled> document). | ||||||||||||||||||||||||||||||||
| 348 | Only records and signals, so the signal handler calls it. Returns false | ||||||||||||||||||||||||||||||||
| 349 | when no run is in progress. | ||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||
| 351 | =head2 abandon | ||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | $runner->abandon('TERM'); | ||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | Ends the run in progress, if there is one, as C<interrupted> by the | ||||||||||||||||||||||||||||||||
| 356 | signal -- its C<run.finished> in the session journal, and with a machine | ||||||||||||||||||||||||||||||||
| 357 | its document -- without leaving the process. The REPL calls it when it is | ||||||||||||||||||||||||||||||||
| 358 | left during a run. | ||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | =head2 event | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | $runner->event('tool.call', call => 'c1', name => 'bash', arguments => { ... }); | ||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||
| 364 | One event of the run in progress, as the application hands it on: into | ||||||||||||||||||||||||||||||||
| 365 | the machine stream (L<Langertha::Raider::CLI::Machine/event>), except the | ||||||||||||||||||||||||||||||||
| 366 | user's own input -- a stream C<message> is the agent's (ADR 0013). | ||||||||||||||||||||||||||||||||
| 367 | Outside a run it does nothing. | ||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | =head2 record | ||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | $runner->record($session, 'history.cleared'); | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | Appends one event outside a run to the session journal | ||||||||||||||||||||||||||||||||
| 374 | (L<Langertha::Raider::Application/record>). A write that fails is a | ||||||||||||||||||||||||||||||||
| 375 | warning (L</journal_error>) and returns false. | ||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | =head2 journal_error | ||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||
| 379 | $runner->journal_error($session, $error); | ||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||
| 381 | Reports a session journal that cannot be written on L</err>, C<warning: | ||||||||||||||||||||||||||||||||
| 382 | session ID not fully saved: ...>: the application's | ||||||||||||||||||||||||||||||||
| 383 | L<Langertha::Raider::Application/on_journal_error>, which reports only the | ||||||||||||||||||||||||||||||||
| 384 | first failure of a run. | ||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | =head2 die_of_signal | ||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||
| 388 | $runner->die_of_signal('TERM'); | ||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||
| 390 | Ends the process by the signal, restored to its default action: the parent | ||||||||||||||||||||||||||||||||
| 391 | sees a process killed by that signal (a shell reports 130 for C<INT>, 143 | ||||||||||||||||||||||||||||||||
| 392 | for C<TERM>; the Hall records the raider as C<signaled>). Should the | ||||||||||||||||||||||||||||||||
| 393 | process survive it, it exits with 128 plus the signal number. | ||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | =head2 terminate_children | ||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||
| 397 | $runner->terminate_children; | ||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | Ends the processes this raider started that still run -- a C<bash> | ||||||||||||||||||||||||||||||||
| 400 | command (L<MCP::Run::Bash> puts it into a process group of its own, so a | ||||||||||||||||||||||||||||||||
| 401 | signal aimed at raider alone never reaches it), a C<perl_eval> or | ||||||||||||||||||||||||||||||||
| 402 | C<perl_cpanm> child: C<SIGTERM> to each child's process group, or to the | ||||||||||||||||||||||||||||||||
| 403 | child when it leads none, and C<SIGKILL> to what is left after | ||||||||||||||||||||||||||||||||
| 404 | C<terminate_grace> seconds. | ||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | =head2 child_pids | ||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | The process IDs of this process's children, from F</proc>, or from C<ps> | ||||||||||||||||||||||||||||||||
| 409 | where there is none. | ||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | =head2 elapsed_since | ||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | my $elapsed = $runner->elapsed_since($t0); | ||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||
| 415 | Seconds since the L<Time::HiRes> time C<$t0>, to the millisecond: the | ||||||||||||||||||||||||||||||||
| 416 | C<elapsed> of a document. | ||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||
| 418 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | =over | ||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||
| 422 | =item * L<Langertha::Raider::CLI::Main> | ||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||
| 424 | =item * L<Langertha::Raider::Application> | ||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | =back | ||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | =head2 Issues | ||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||
| 433 | L<https://github.com/Getty/langertha-raider/issues>. | ||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||
| 435 | =head2 IRC | ||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||
| 437 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/> | ||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||
| 447 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||
| 449 | This software is copyright (c) 2026 by Torsten Raudssus. | ||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||
| 451 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 452 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | =cut | ||||||||||||||||||||||||||||||||