view release on metacpan or search on metacpan
lib/Langertha/Raider/ACP/CLI.pm view on Meta::CPAN
my $c = Langertha::Raider::ACP::Client->new(host => $host, port => $port);
my $res = $c->initialize;
my $json = JSON::MaybeXS->new(pretty => 1, canonical => 1);
print $json->encode($res);
return 0;
}
sub run_prompt {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'raider=s', 'json', 'help');
return print_prompt_help() if $opt{help};
my $ep = shift @ARGV or die "Usage: raider acp prompt HOST:PORT TEXT...\n";
my ($host, $port) = _parse_endpoint($ep);
my $text = join ' ', @ARGV;
die "No prompt text given.\n" unless length $text;
my $c = Langertha::Raider::ACP::Client->new(host => $host, port => $port);
$c->initialize;
lib/Langertha/Raider/ACP/CLI.pm view on Meta::CPAN
incoming session/update notifications, exits on the final stopReason.
A session/request_permission of the agent is rejected (nobody to ask);
use connect to answer it.
EOF
exit 0;
}
sub run_connect {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'raider=s', 'json', 'help');
return print_connect_help() if $opt{help};
my $ep = shift @ARGV or die "Usage: raider acp connect HOST:PORT\n";
my ($host, $port) = _parse_endpoint($ep);
my $term;
my $c = Langertha::Raider::ACP::Client->new(host => $host, port => $port,
on_permission => sub { _ask_permission($term, @_) });
my $init = $c->initialize;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
install [DIR] Install systemd user unit
help Show this help
Run 'raider hall <subcommand> --help' for per-command options.
EOF
}
sub run_init {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'name=s', 'engine=s', 'provider=s', 'persona=s', 'help');
return print_init_help() if $opt{help};
if (my $why = provider_problem(\%opt)) { die 'raider hall init: '.$why."\n" }
my $name = $opt{name};
if (!$name) {
print "Raider name (e.g. Bjorn, Ragnar, Astrid, Ivar, Lagertha): ";
$name = <STDIN>;
chomp $name;
exit 1 unless length $name;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
$cfg_file->spew_utf8(YAML::PP->new->dump(\%yml));
print "Hall initialised in $dir with raider '$name'.\n";
print "Start with: raider hall start\n";
return 0;
}
sub run_add_raider {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt,
'engine=s', 'provider=s', 'persona=s', 'model=s', 'pack=s@', 'help');
return print_add_raider_help() if $opt{help};
my $name = shift @ARGV;
die "Usage: raider hall add-raider NAME [--engine E | --provider ALIAS] [--persona P] [--model M] [--pack X]...\n"
unless $name;
if (my $why = provider_problem(\%opt)) { die 'raider hall add-raider: '.$why."\n" }
my $dir = cwd;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
my $problem = Langertha::Raider::Hall->_provider_problem({
(defined $opt->{engine} ? ( engine => $opt->{engine} ) : ()),
(defined $opt->{provider} ? ( provider => $opt->{provider} ) : ()),
}) or return;
return $problem->{error};
}
sub run_start {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'daemon', 'acp-port=i', 'acp-host=s', 'help');
return print_start_help() if $opt{help};
@args = @ARGV;
my $dir = hall_dir(\@args);
$dir = path($dir);
# --acp-port wins over yml; persist nothing, pass through env.
if (defined $opt{'acp-port'}) {
$ENV{RAIDER_HALL_ACP_PORT} = $opt{'acp-port'};
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
$loop->run;
die "No response from hall\n" unless defined $result;
return $result;
}
sub run_spawn {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'attach', 'help');
return print_spawn_help() if $opt{help};
@args = @ARGV;
my $dir = hall_dir(\@args, 2);
die "Usage: raider hall spawn NAME MISSION [--attach]\n" unless @args >= 2;
my $name = shift @args;
my $mission = join ' ', @args;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
Spawn a raider with the given NAME and MISSION in DIR (default: cwd).
--attach then prints the run's event stream like 'attach' does; a
mission that waits in a queue has no run yet and is not attached.
EOF
exit 0;
}
sub run_attach {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'help');
return print_attach_help() if $opt{help};
@args = @ARGV;
my $dir = hall_dir(\@args, 1);
die "Usage: raider hall attach ID\n" unless @args;
my $id = shift @args;
my $socket = path($dir)->child('.raider-hall.socket');
die "Hall not running (no socket found)\n" unless -e $socket;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
Print the event stream of the running raider ID (its --stream-json
events, one JSON object per line) and keep printing new events until
the raider has exited. For an ended run, see 'logs'.
EOF
exit 0;
}
sub run_logs {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'follow', 'help');
return print_logs_help() if $opt{help};
@args = @ARGV;
my $dir = hall_dir(\@args, 1);
die "Usage: raider hall logs ID [--follow]\n" unless @args;
my $id = shift @args;
my $socket = path($dir)->child('.raider-hall.socket');
die "Hall not running (no socket found)\n" unless -e $socket;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
Fetch logs for a raider, also after its run has ended: the slot log, or
the run's result when the slot log no longer has it. --follow keeps
printing new output until the raider has exited.
EOF
exit 0;
}
sub run_kill {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'help');
return print_kill_help() if $opt{help};
@args = @ARGV;
my $dir = hall_dir(\@args, 1);
die "Usage: raider hall kill ID\n" unless @args;
my $id = shift @args;
my $socket = path($dir)->child('.raider-hall.socket');
die "Hall not running (no socket found)\n" unless -e $socket;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
raider hall kill [DIR] ID
Terminate a raider.
EOF
exit 0;
}
sub run_session {
my @args = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt, 'help');
return print_session_help() if $opt{help};
@args = @ARGV;
my $usage = "Usage: raider hall session reset [DIR] BINDING\n";
my $sub = shift @args // '';
die $usage unless $sub eq 'reset';
my $dir = hall_dir(\@args, 1);
die $usage unless @args == 1;
lib/Langertha/Raider/Hall/CLI.pm view on Meta::CPAN
key of .raider-hall/state/sessions.json, e.g. telegram:ops:42,
telegram:ops:-1001234:7, cron:nightly, slot:1bjorn. The old journal is
kept. In a Telegram chat, /new does the same for that chat.
EOF
exit 0;
}
sub run_install {
my (@args) = @_;
my %opt;
local @ARGV = @args;
Getopt::Long::GetOptions(\%opt,
'docker', 'host', 'image=s', 'name=s',
'acp-port=i', 'acp-host=s', 'stdout', 'help');
return print_install_help() if $opt{help};
my $dir = hall_dir(\@ARGV);
$dir = path($dir);
my $cwd = $dir->stringify;
my $unit_name = $opt{name} // 'raider-hall';
my $in_container = -f '/.dockerenv' || ($ENV{container} // '') ne '';