blib/lib/Langertha/Raider/CLI/Main.pm

filter: Statementstmt 93.0% 429 / 461 Branchbran 89.5% 215 / 240 Conditioncond 82.3% 112 / 136 MC/DCmcdc 63.8% 46 / 72 Subroutinesub 92.8% 52 / 56 Podpod 60.0% 15 / 25 totaltotal 87.7% 869 / 990 CC 179 SCAR 38.3
CC
179
Cov
90%
run
104.1
parse_options
22.3
migrate_command
19.3
CRAP 46.3
↑ Summary blib/lib/Langertha/Raider/Hall/MCP.pm »
1 package Langertha::Raider::CLI::Main;
2 # ABSTRACT: Internal command-line entry point behind bin/raider
3 55 our $VERSION = '0.503';
4 55 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 55 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 55 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 55 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 55 ▶use IO::Prompt::Tiny qw( prompt );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 55 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 55 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 55 ▶use Langertha;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 55 ▶use Langertha::Raider;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 55 ▶use Langertha::Raider::ACP::CLI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 55 ▶use Langertha::Raider::CLI;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 55 ▶use Langertha::Raider::CLI::Machine;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 55 ▶use Langertha::Raider::CLI::Output;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 55 ▶use Langertha::Raider::CLI::Provider;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 55 ▶use Langertha::Raider::CLI::REPL;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 55 ▶use Langertha::Raider::CLI::Runner;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 55 ▶use Langertha::Raider::CLI::Sessions;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 55 ▶use Langertha::Raider::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 55 ▶use Langertha::Raider::Config::Migrate;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 55 ▶use Langertha::Raider::Hall::CLI;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 55 ▶use Langertha::Raider::SessionStore;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 55 ▶use Langertha::Raider::Skill;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 55 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 55 EXIT_OK => 0,
30 EXIT_RUN_ERROR => 1,
31 EXIT_USAGE => 2,
32 EXIT_CONFIG => 3,
33 EXIT_SESSION_IN_USE => 4,
34 55 };
35  
36 # The machine output flags (ADR 0013): flag => [ format, stream ].
37 55 my %MACHINE_FLAG = (
38 json => [ json => 0 ],
39 msgpack => [ msgpack => 0 ],
40 yaml => [ yaml => 0 ],
41 'stream-json' => [ json => 1 ],
42 'stream-msgpack' => [ msgpack => 1 ],
43 'stream-yaml' => [ yaml => 1 ],
44 );
45  
46  
47 has output => (
48 is => 'ro',
49 isa => 'Langertha::Raider::CLI::Output',
50 lazy => 1,
51 18 ▶ default => sub { Langertha::Raider::CLI::Output->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 55 );
53  
54 has err => (
55 is => 'ro',
56 31 ▶ default => sub { \*STDERR },
Subroutine __ANON__: called CC=1 SCAR=0.0
57 55 );
58  
59 has in => (
60 is => 'ro',
61 72 ▶ default => sub { \*STDIN },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 55 );
63  
64 40 ▶sub app_class { 'Langertha::Raider::CLI' }
Subroutine app_class: called CC=1 SCAR=0.0
Pod undocumented
65 144 ▶sub config_class { 'Langertha::Raider::Config' }
Subroutine config_class: called CC=1 SCAR=0.0
Pod undocumented
66 17 ▶sub migrate_class { 'Langertha::Raider::Config::Migrate' }
Subroutine migrate_class: called CC=1 SCAR=0.0
Pod undocumented
67 122 ▶sub machine_class { 'Langertha::Raider::CLI::Machine' }
Subroutine machine_class: called CC=1 SCAR=0.0
Pod undocumented
68 0 ▶sub provider_class { 'Langertha::Raider::CLI::Provider' }
Subroutine provider_class: not called CC=1 SCAR=6.9
Pod undocumented
69 27 ▶sub repl_class { 'Langertha::Raider::CLI::REPL' }
Subroutine repl_class: called CC=1 SCAR=0.0
Pod undocumented
70 100 ▶sub runner_class { 'Langertha::Raider::CLI::Runner' }
Subroutine runner_class: called CC=1 SCAR=0.0
Pod undocumented
71 40 ▶sub session_store_class { 'Langertha::Raider::SessionStore' }
Subroutine session_store_class: called CC=1 SCAR=0.0
Pod undocumented
72 28 ▶sub sessions_class { 'Langertha::Raider::CLI::Sessions' }
Subroutine sessions_class: called CC=1 SCAR=0.0
Pod undocumented
73 7 ▶sub skill_class { 'Langertha::Raider::Skill' }
Subroutine skill_class: called CC=1 SCAR=0.0
Pod undocumented
74  
75 124 ▶sub _warn {
Subroutine _warn: called CC=1 SCAR=0.0
76 124 my ( $self, @text ) = @_;
77 124 print { $self->err } @text;
78 124 return;
79 }
80  
81  
82 7 ▶sub usage { <<'USAGE' }
Subroutine usage: called CC=1 SCAR=0.0
Pod documented
83 Usage: raider [options] [prompt...]
84 raider config explain [options] show each setting and its source
85 raider config migrate [--dry-run] move .raider.yml / .raider.md to
86 .raider/ (see its --help)
87 raider session list [options] the project's sessions, newest first
88 raider session show ID [--json] one session, event by event
89 raider session resume ID [options] continue a session in the REPL
90 raider session fork ID [--json] a new session with its history
91 raider session rm ID [--json] delete a session
92 raider provider inspect HOST [--json] [--allow-internal]
93 fetch, validate and show a
94 provider's manifest
95  
96 Options:
97 -e, --engine NAME anthropic, openai, deepseek, groq, mistral, gemini,
98 minimax, cerebras, openrouter, ollama
99 (default: auto-detected from available *_API_KEY
100 env var — anthropic > openai > deepseek > ...)
101 -m, --model NAME Model identifier (engine-specific cheap default)
102 -k, --api-key KEY API key (overrides *_API_KEY env var)
103 --provider HOST[:PORT] | https://HOST[:PORT]
104 Run on the model endpoint the provider's
105 manifest (/.well-known/langertha.json) declares;
106 nothing is stored. -m picks one of its models
107 (a must when it lists several); the key comes
108 only from -k, never from the config file or
109 the environment. Not with -e, -o engine= or -o url=
110 --allow-internal With --provider: allow a loopback, private,
111 link-local or reserved provider address
112 -o, --option KEY=VALUE Engine attribute (repeatable), e.g.
113 -o temperature=0.2 -o response_size=4096
114 Merged over the config file (.raider/config.yml,
115 else .raider.yml); CLI wins. raider's own
116 config keys (perl, packs=a,b, skills=a,b,
117 no_detect=a,b, detect=false,
118 preferred_lib_target, engine) configure raider.
119 -r, --root DIR Working directory (default: cwd). File tools are
120 confined to this directory.
121 -M, --mission TEXT Instructions: replaces the default persona and
122 the instructions file (.raider/instructions.md,
123 else .raider.md); skills, packs and the tool
124 description still apply
125 --bare Isolated context: no instructions file, skills,
126 packs:, default packs or detection (--pack NAME
127 and /pack NAME still work)
128 -i, --interactive REPL mode (default when stdin is a TTY with no
129 prompt argv and no pipe; forces it otherwise)
130 --json[=N] Print one JSON document for the run and exit
131 (format version N; 1 is the only one)
132 --msgpack[=N] The same document as MessagePack
133 --yaml[=N] The same document as YAML
134 --stream-json[=N] Print the run as JSON Lines events as it happens,
135 ending with the document (run.finished)
136 --stream-msgpack[=N] The same events as MessagePack objects
137 --stream-yaml[=N] The same events as YAML documents
138 --no-session Do not record the run(s) in a session journal
139 (default: a new one in .raider/sessions/)
140 --session ID Continue session ID: its conversation is replayed
141 and the run(s) recorded in it (one-shot or REPL)
142 --continue The same with the newest session of the project
143 --max-iterations N Hard safety cap on tool rounds per raid
144 (default: 10000 — effectively unlimited)
145 --no-color Disable ANSI colors
146 --trace / --no-trace Show / hide live tool-call progress output
147 (default: shown when stdout is a terminal;
148 with a machine output flag --trace sends it
149 to stderr)
150 --perl Enable perl_eval / perl_check / perl_cpanm tools
151 --pack NAME Enable a bundled pack (repeatable)
152 --no-pack NAME Switch a pack off, also a detected or default
153 one (repeatable)
154 --no-detect Do not activate packs by workspace detection
155 (--detect forces it on over detect: false)
156 --customize-prompt Launch the prompt-builder at startup
157 --claude Load Claude Code layout: CLAUDE.md +
158 .claude/skills/*/SKILL.md.
159 --openai / --codex Load AGENTS.md (the OpenAI Codex / cross-tool
160 convention).
161 --skills DIR Load *.md files from DIR as skills (repeatable).
162 --export-skill [PATH]
163 Write a plain-markdown "how to use raider" doc
164 (default: ./RAIDER-SKILL.md) and exit.
165 --export-claude-skill [PATH]
166 Write a Claude Code SKILL.md with frontmatter
167 (default: .claude/skills/raider/SKILL.md)
168 and exit.
169 --version Show the versions of raider and Langertha
170 -h, --help Show this help
171  
172 If no prompt is given and not interactive, reads the prompt from STDIN.
173 A session ID may be shortened to a unique start of it or to its last four
174 hex digits (3f2a).
175  
176 Exit status: 0 success, 1 the run failed, 2 usage error,
177 3 configuration error, 4 the session is in use.
178 USAGE
179  
180  
181 2 ▶sub version_line {
Subroutine version_line: called CC=1 SCAR=0.0
Pod documented
182 2 my ( $self ) = @_;
183 2 return 'raider '.Langertha::Raider->VERSION.' (Langertha '.Langertha->VERSION.")\n";
184 }
185  
186  
187 252 ▶sub parse_options {
Subroutine parse_options: called CC=22 SCAR=31.1
Pod documented
188 252 my ( $self, @argv ) = @_;
189 252 my %opt = ( packs => [], no_packs => [], skill_dirs => [] );
190 252 my @raw_engine_opts;
191 # --json=N and friends. Only the =N form carries a version: an optional
192 # Getopt::Long value would also take the next word (raider --json 3 ...).
193 252 my ( %machine_flag, %machine_version );
194 252 for my $arg (@argv) {
195 1792 ▶ last if $arg eq '--';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "--" 7 1785 1792
196 1785 ▶ next unless $arg =~ /\A--([a-z-]+)=(.*)\z/s && $MACHINE_FLAG{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg =~ /\A--([a-z-]+)=(.*)\z/s and $MACHINE_FLAG{$1} 1778 7 1785
Condition100%3/3
$arg =~ /\A--([a-z-]+)=(.*)\z/s and $MACHINE_FLAG{$1}
!ll&&!rl&&r
177177
MC/DC100%2/2
$arg =~ /\A--([a-z-]+)=(.*)\z/s and $MACHINE_FLAG{$1}
$arg =~ /\A--([a-z-]+)=(.*)\z/s $MACHINE_FLAG{$1}
Truth table100%3/3
A and B
A= $arg =~ /\A--([a-z-]+)=(.*)\z/sB= $MACHINE_FLAG{$1}
ABresult
0X0
100
111
197 7 $machine_version{$1} = $2;
198 7 $arg = '--'.$1;
199 }
200 252 my $parser = Getopt::Long::Parser->new(config => [qw( no_ignore_case bundling )]);
201 252 my $ok = do {
202 252 ▶ local $SIG{__WARN__} = sub { $self->_warn(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
203 $parser->getoptionsfromarray(\@argv,
204 'e|engine=s' => \$opt{engine},
205 'provider=s' => \$opt{provider},
206 'allow-internal' => \$opt{allow_internal},
207 'm|model=s' => \$opt{model},
208 'r|root=s' => \$opt{root},
209 'M|mission=s' => \$opt{mission},
210 'bare' => \$opt{bare},
211 'k|api-key=s' => \$opt{api_key},
212 'o|option=s@' => \@raw_engine_opts,
213 'i|interactive' => \$opt{interactive},
214 1512 ( map { $_ => \$machine_flag{$_} } sort keys %MACHINE_FLAG ),
215 'max-iterations=i' => \$opt{max_iterations},
216 'no-color' => \$opt{no_color},
217 'trace!' => \$opt{trace},
218 'perl' => \$opt{perl},
219 'pack=s@' => $opt{packs},
220 'no-pack=s@' => $opt{no_packs},
221 'detect!' => \$opt{detect},
222 'customize-prompt' => \$opt{customize_prompt},
223 'claude' => \$opt{profile_claude},
224 'openai|codex' => \$opt{profile_openai},
225 'skills=s@' => $opt{skill_dirs},
226 'export-skill:s' => \$opt{export_skill},
227 'export-claude-skill:s' => \$opt{export_claude_skill},
228 'no-session' => \$opt{no_session},
229 'session=s' => \$opt{session},
230 'continue' => \$opt{continue},
231 'version' => \$opt{version},
232 'h|help' => \$opt{help},
233 252 );
234 };
235 252 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 4 248 252
236 4 $self->_warn("Bad options. Try --help.\n");
237 4 return;
238 }
239  
240 248 ▶ if (defined $opt{session} && !$self->session_store_class->is_ref($opt{session})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"session"} and not $self->session_store_class->is_ref($opt{"session"})) 1 247 248
Condition100%3/3
defined $opt{"session"} and not $self->session_store_class->is_ref($opt{"session"})
!ll&&!rl&&r
237101
MC/DC100%2/2
defined $opt{"session"} and not $self->session_store_class->is_ref($opt{"session"})
defined $opt{"session"} not $self->session_store_class->is_ref($opt{"session"})
Truth table100%3/3
A and not(B)
A= defined $opt{"session"}B= not $self->session_store_class->is_ref($opt{"session"})
ABresult
0X0
100
111
241 1 $self->_warn("--session: not a session id: '".$opt{session}."'\n");
242 1 return;
243 }
244 247 my @session_flags = grep { $opt{ $_->[0] } } [ session => '--session' ], [ continue => '--continue' ],
245 [ no_session => '--no-session' ];
246 247 ▶ if (@session_flags > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@session_flags > 1) 1 246 247
247 1 $self->_warn(join(', ', map { $_->[1] } @session_flags).": only one of them at a time\n");
248 1 return;
249 }
250  
251 246 my @machine = grep { $machine_flag{$_} } sort keys %MACHINE_FLAG;
252 246 ▶ if (@machine > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@machine > 1) 3 243 246
253 3 $self->_warn(join(', ', map { '--'.$_ } @machine).": only one machine output format at a time\n");
254 3 return;
255 }
256 243 ▶ if (my ( $flag ) = @machine) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($flag) = @machine) 69 174 243
257 69 ▶ if ($opt{interactive}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"interactive"}) 2 67 69
258 2 $self->_warn('--'.$flag.": no machine output in the REPL (-i)\n");
259 2 return;
260 }
261 67 ▶ my $version = $machine_version{$flag} // 1;
Condition100%2/2
$machine_version{$flag} // 1
l!l
760
MC/DC100%1/1
$machine_version{$flag} // 1
$machine_version{$flag}
Truth table100%2/2
A
A= $machine_version{$flag}
Aresult
11
00
262 67 ▶ unless ($version =~ /\A\d+\z/ && grep { $_ == $version } $self->machine_class->versions) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($version =~ /\A\d+\z/ and grep {$_ == $version;} $self->machine_class->versions) 3 64 67
Condition100%3/3
$version =~ /\A\d+\z/ and grep {$_ == $version;} $self->machine_class->versions
!ll&&!rl&&r
1264
MC/DC100%2/2
$version =~ /\A\d+\z/ and grep {$_ == $version;} $self->machine_class->versions
$version =~ /\A\d+\z/ grep {$_ == $version;} $self->machine_class->versions
Truth table100%3/3
A and B
A= $version =~ /\A\d+\z/B= grep {$_ == $version;} $self->machine_class->versions
ABresult
0X0
100
111
263 3 $self->_warn("unknown --".$flag." version '".$version."' (known: "
264 .join(', ', $self->machine_class->versions).")\n");
265 3 return;
266 }
267 64 my ( $format, $stream ) = @{ $MACHINE_FLAG{$flag} };
268 64 $opt{machine} = { format => $format, stream => $stream, version => 0 + $version };
269 }
270  
271 238 my %engine_opts;
272 238 for my $pair (@raw_engine_opts) {
273 20 my ( $k, $v ) = split /=/, $pair, 2;
274 20 ▶ unless (defined $k && defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $k and defined $v) 1 19 20
Condition66%2/3
defined $k and defined $v
!ll&&!rl&&r
0119
MC/DC50%1/2
defined $k and defined $v
defined $k defined $v
Truth table66%2/3
A and B
A= defined $kB= defined $v
ABresult
0X0
100
111
275 1 $self->_warn("bad -o spec '".$pair."' (expected key=value)\n");
276 1 return;
277 }
278 # Auto-coerce simple numerics so temperature=0.2 lands as a number.
279 19 ▶ if ($v =~ /\A-?\d+\z/) { $v = 0 + $v }
Branch: 4 branches
BranchTrueFalseTotal
if ($v =~ /\A-?\d+\z/) { } 0 19 19
elsif ($v =~ /\A-?\d*\.\d+(?:[eE]-?\d+)?\z/) { } 0 19 19
elsif ($v eq 'true') { } 0 19 19
elsif ($v eq 'false') { } 0 19 19
280 0 elsif ($v =~ /\A-?\d*\.\d+(?:[eE]-?\d+)?\z/) { $v = 0 + $v }
281 0 elsif ($v eq 'true') { $v = 1 }
282 0 elsif ($v eq 'false') { $v = 0 }
283 19 $engine_opts{$k} = $v;
284 }
285 237 $opt{engine_options} = \%engine_opts;
286 237 return ( \%opt, @argv );
287 }
288  
289  
290 155 ▶sub app_args {
Subroutine app_args: called CC=12 SCAR=24.9
Pod documented
291 155 my ( $self, $opt ) = @_;
292 155 my %args;
293 155 for my $key (qw( engine model root mission api_key trace perl detect max_iterations bare )) {
294 1550 ▶ $args{$key} = $opt->{$key} if defined $opt->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$opt{$key} 598 952 1550
295 }
296 155 ▶ $args{trace} = 0 if $opt->{machine} && !defined $opt->{trace};
Branch: 1 branch
BranchTrueFalseTotal
if $$opt{"machine"} and not defined $$opt{"trace"} 9 146 155
Condition100%3/3
$$opt{"machine"} and not defined $$opt{"trace"}
!ll&&!rl&&r
111359
MC/DC100%2/2
$$opt{"machine"} and not defined $$opt{"trace"}
$$opt{"machine"} not defined $$opt{"trace"}
Truth table100%3/3
A and not(B)
A= $$opt{"machine"}B= not defined $$opt{"trace"}
ABresult
0X0
100
111
297 155 ▶ $args{trace_out} = $self->err if $opt->{machine};
Branch: 1 branch
BranchTrueFalseTotal
if $$opt{"machine"} 44 111 155
298 155 ▶ $args{pack_names} = $opt->{packs} if @{ $opt->{packs} // [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$opt{"packs"} // [];} 2 153 155
Condition50%1/2
$$opt{"packs"} // []
l!l
1550
MC/DC0%0/1
$$opt{"packs"} // []
$$opt{"packs"}
Truth table50%1/2
A
A= $$opt{"packs"}
Aresult
11
00
299 155 ▶ $args{no_pack_names} = $opt->{no_packs} if @{ $opt->{no_packs} // [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$opt{"no_packs"} // [];} 1 154 155
Condition50%1/2
$$opt{"no_packs"} // []
l!l
1550
MC/DC0%0/1
$$opt{"no_packs"} // []
$$opt{"no_packs"}
Truth table50%1/2
A
A= $$opt{"no_packs"}
Aresult
11
00
300 155 ▶ $args{engine_options} = $opt->{engine_options} if %{ $opt->{engine_options} // {} };
Branch: 1 branch
BranchTrueFalseTotal
if %{$$opt{"engine_options"} // {};} 16 139 155
Condition50%1/2
$$opt{"engine_options"} // {}
l!l
1550
MC/DC0%0/1
$$opt{"engine_options"} // {}
$$opt{"engine_options"}
Truth table50%1/2
A
A= $$opt{"engine_options"}
Aresult
11
00
301 155 return %args;
302 }
303  
304  
305 243 ▶sub run {
Subroutine run: called CC=90 SCAR=46.5
Pod documented
306 243 my ( $self, @argv ) = @_;
307  
308 243 ▶ if (@argv && $argv[0] eq 'hall') {
Branch: 1 branch
BranchTrueFalseTotal
if (@argv and $argv[0] eq "hall") 0 243 243
Condition33%1/3
@argv and $argv[0] eq "hall"
!ll&&!rl&&r
02430
MC/DC0%0/2
@argv and $argv[0] eq "hall"
@argv $argv[0] eq "hall"
Truth table33%1/3
A and B
A= @argvB= $argv[0] eq "hall"
ABresult
0X0
100
111
309 0 shift @argv;
310 0 Langertha::Raider::Hall::CLI->main(@argv);
311 0 return EXIT_OK;
312 }
313 243 ▶ if (@argv && $argv[0] eq 'acp') {
Branch: 1 branch
BranchTrueFalseTotal
if (@argv and $argv[0] eq "acp") 0 243 243
Condition33%1/3
@argv and $argv[0] eq "acp"
!ll&&!rl&&r
02430
MC/DC0%0/2
@argv and $argv[0] eq "acp"
@argv $argv[0] eq "acp"
Truth table33%1/3
A and B
A= @argvB= $argv[0] eq "acp"
ABresult
0X0
100
111
314 0 shift @argv;
315 0 Langertha::Raider::ACP::CLI->main(@argv);
316 0 return EXIT_OK;
317 }
318  
319 # raider provider inspect TARGET [options]. Only these two words make the
320 # subcommand; "raider provider is down?" stays a prompt.
321 243 ▶ if (@argv >= 2 && $argv[0] eq 'provider' && $argv[1] eq 'inspect') {
Branch: 1 branch
BranchTrueFalseTotal
if (@argv >= 2 and $argv[0] eq "provider" and $argv[1] eq "inspect") 25 218 243
Condition83%5/6
@argv >= 2 and $argv[0] eq "provider" and $argv[1] eq "inspect"
!ll&&!rl&&r
218025
@argv >= 2 and $argv[0] eq "provider"
!ll&&!rl&&r
521325
MC/DC66%2/3
@argv >= 2 and $argv[0] eq "provider" and $argv[1] eq "inspect"
@argv >= 2 $argv[0] eq "provider" $argv[1] eq "inspect"
Truth table75%3/4
A and B and C
A= @argv >= 2B= $argv[0] eq "provider"C= $argv[1] eq "inspect"
ABCresult
0XX0
10X0
1100
1111
322 25 splice @argv, 0, 2;
323 25 return $self->provider_command(inspect => @argv);
324 }
325  
326 # raider config explain [options]: prints where each setting comes from
327 # and exits without writing the config file or building an engine.
328 218 my $config_cmd;
329 # raider config migrate [--dry-run] [options] writes files, so it is the
330 # subcommand only in front of the options.
331 218 ▶ if (@argv && $argv[0] eq 'config') {
Branch: 1 branch
BranchTrueFalseTotal
if (@argv and $argv[0] eq "config") 34 184 218
Condition66%2/3
@argv and $argv[0] eq "config"
!ll&&!rl&&r
018434
MC/DC50%1/2
@argv and $argv[0] eq "config"
@argv $argv[0] eq "config"
Truth table66%2/3
A and B
A= @argvB= $argv[0] eq "config"
ABresult
0X0
100
111
332 34 shift @argv;
333 34 ▶ $config_cmd = shift(@argv) // '';
Condition50%1/2
shift @argv // ""
l!l
340
MC/DC0%0/1
shift @argv // ""
shift @argv
Truth table50%1/2
A
A= shift @argv
Aresult
11
00
334 34 ▶ return $self->migrate_command(@argv) if $config_cmd eq 'migrate';
Branch: 1 branch
BranchTrueFalseTotal
if $config_cmd eq "migrate" 22 12 34
335 12 ▶ unless ($config_cmd eq 'explain') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config_cmd eq "explain") 3 9 12
336 3 $self->_warn("Usage: raider config explain [options] | raider config migrate [--dry-run] [options]\n");
337 3 return EXIT_USAGE;
338 }
339 }
340  
341 # raider session list | show ID | resume ID | fork ID | rm ID [options].
342 # Only these words make the subcommand; any other prompt starting with
343 # "session" (raider session is lost?) stays a prompt.
344 193 my ( $session_cmd, $session_id );
345 193 ▶ if (!$config_cmd && @argv >= 2 && $argv[0] eq 'session' && $argv[1] =~ /\A(?:list|show|resume|fork|rm)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $config_cmd and @argv >= 2 and $argv[0] eq "session" and $argv[1] =~ /\A(?:list|show|resume|fork|rm)\z/) 23 170 193
Condition100%9/9
not $config_cmd and @argv >= 2 and $argv[0] eq "session" and $argv[1] =~ /\A(?:list|show|resume|fork|rm)\z/
!ll&&!rl&&r
169123
not $config_cmd and @argv >= 2 and $argv[0] eq "session"
!ll&&!rl&&r
1415524
not $config_cmd and @argv >= 2
!ll&&!rl&&r
95179
MC/DC100%4/4
not $config_cmd and @argv >= 2 and $argv[0] eq "session" and $argv[1] =~ /\A(?:list|show|resume|fork|rm)\z/
not $config_cmd @argv >= 2 $argv[0] eq "session" $argv[1] =~ /\A(?:list|show|resume|fork|rm)\z/
Truth table100%5/5
not(A) and B and C and D
A= not $config_cmdB= @argv >= 2C= $argv[0] eq "session"D= $argv[1] =~ /\A(?:list|show|resume|fork|rm)\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
346 23 ( undef, $session_cmd ) = splice @argv, 0, 2;
347 }
348  
349 193 ▶ my ( $opt, @prompt ) = $self->parse_options(@argv) or return EXIT_USAGE;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->parse_options(@argv) or return 2 180 13 193
350  
351 # Behind options (raider -e openai config explain) only the exact words
352 # "config explain" are the subcommand; any other prompt starting with
353 # "config" stays a prompt. The same for "session list" and "session
354 # show|resume|fork|rm ID" with a word shaped like a session id.
355 180 ▶ if (!$config_cmd && @prompt == 2 && $prompt[0] eq 'config' && $prompt[1] eq 'explain') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $config_cmd and @prompt == 2 and $prompt[0] eq "config" and $prompt[1] eq "explain") 17 163 180
Condition88%8/9
not $config_cmd and @prompt == 2 and $prompt[0] eq "config" and $prompt[1] eq "explain"
!ll&&!rl&&r
163017
not $config_cmd and @prompt == 2 and $prompt[0] eq "config"
!ll&&!rl&&r
160317
not $config_cmd and @prompt == 2
!ll&&!rl&&r
915120
MC/DC75%3/4
not $config_cmd and @prompt == 2 and $prompt[0] eq "config" and $prompt[1] eq "explain"
not $config_cmd @prompt == 2 $prompt[0] eq "config" $prompt[1] eq "explain"
Truth table80%4/5
not(A) and B and C and D
A= not $config_cmdB= @prompt == 2C= $prompt[0] eq "config"D= $prompt[1] eq "explain"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
356 17 $config_cmd = 'explain';
357 17 @prompt = ();
358 }
359 180 ▶ if (!$config_cmd && !$session_cmd && @prompt >= 2 && $prompt[0] eq 'session'
Branch: 1 branch
BranchTrueFalseTotal
if (not $config_cmd || $session_cmd and @prompt >= 2 and $prompt[0] eq "session" and @prompt == 2 && $prompt[1] eq "list" || @prompt == 3 && $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/ && $self->session_store_class->is_ref($prompt[2])) 5 175 180
Condition91%22/24
not $config_cmd || $session_cmd and @prompt >= 2 and $prompt[0] eq "session" and @prompt == 2 && $prompt[1] eq "list" || @prompt == 3 && $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/ && $self->session_store_class->is_ref($prompt[2])
!ll&&!rl&&r
17055
not $config_cmd || $session_cmd and @prompt >= 2 and $prompt[0] eq "session"
!ll&&!rl&&r
165510
not $config_cmd || $session_cmd and @prompt >= 2
!ll&&!rl&&r
4911615
$config_cmd || $session_cmd
l!l&&r!l&&!r
2623131
@prompt == 2 and $prompt[1] eq "list" or @prompt == 3 and $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/ and $self->session_store_class->is_ref($prompt[2])
l!l&&r!l&&!r
145
@prompt == 2 and $prompt[1] eq "list"
!ll&&!rl&&r
901
@prompt == 3 and $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/ and $self->session_store_class->is_ref($prompt[2])
!ll&&!rl&&r
324
@prompt == 3 and $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/
!ll&&!rl&&r
036
MC/DC77%7/9
not $config_cmd || $session_cmd and @prompt >= 2 and $prompt[0] eq "session" and @prompt == 2 && $prompt[1] eq "list" || @prompt == 3 && $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/ && $self->session_store_class->is_ref($prompt[2])
$config_cmd $session_cmd @prompt >= 2 $prompt[0] eq "session" @prompt == 2 $prompt[1] eq "list" @prompt == 3 $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/ $self->session_store_class->is_ref($prompt[2])
Truth table61%8/13
not(A || B) and C and D and E and F or G and H and I
A= $config_cmdB= $session_cmdC= @prompt >= 2D= $prompt[0] eq "session"E= @prompt == 2F= $prompt[1] eq "list"G= @prompt == 3H= $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/I= $self->session_store_class->is_ref($prompt[2])
ABCDEFGHIresult
1XXXXXXXX0
01XXXXXXX0
000XXXXXX0
0010XXXXX0
00110X0XX0
00110X10X0
00110X1100
0011100XX0
00111010X0
0011101100
001111XXX1
00110X1111
0011101111
360 && ( (@prompt == 2 && $prompt[1] eq 'list')
361 || (@prompt == 3 && $prompt[1] =~ /\A(?:show|resume|fork|rm)\z/ && $self->session_store_class->is_ref($prompt[2])) )) {
362 5 ( undef, $session_cmd ) = splice @prompt, 0, 2;
363 }
364 180 ▶ if ($session_cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session_cmd) 28 152 180
365 28 my $wants_id = $session_cmd ne 'list';
366 28 ▶ $session_id = shift @prompt if $wants_id;
Branch: 1 branch
BranchTrueFalseTotal
if $wants_id 23 5 28
367 28 ▶ if (@prompt || ($wants_id && !$self->session_store_class->is_ref($session_id))) {
Branch: 1 branch
BranchTrueFalseTotal
if (@prompt or $wants_id and not $self->session_store_class->is_ref($session_id)) 4 24 28
Condition100%6/6
@prompt or $wants_id and not $self->session_store_class->is_ref($session_id)
l!l&&r!l&&!r
1324
$wants_id and not $self->session_store_class->is_ref($session_id)
!ll&&!rl&&r
4203
MC/DC100%3/3
@prompt or $wants_id and not $self->session_store_class->is_ref($session_id)
@prompt $wants_id not $self->session_store_class->is_ref($session_id)
Truth table100%4/4
A or B and not(C)
A= @promptB= $wants_idC= not $self->session_store_class->is_ref($session_id)
ABCresult
1XX1
0111
00X0
0100
368 4 $self->_warn("Usage: raider session list | show ID | resume ID | fork ID | rm ID [options]\n");
369 4 return EXIT_USAGE;
370 }
371 }
372  
373 176 ▶ $ENV{ANSI_COLORS_DISABLED} = 1 if $opt->{no_color} || $opt->{machine};
Branch: 1 branch
BranchTrueFalseTotal
if $$opt{"no_color"} or $$opt{"machine"} 50 126 176
Condition100%3/3
$$opt{"no_color"} or $$opt{"machine"}
l!l&&r!l&&!r
446126
MC/DC100%2/2
$$opt{"no_color"} or $$opt{"machine"}
$$opt{"no_color"} $$opt{"machine"}
Truth table100%3/3
A or B
A= $$opt{"no_color"}B= $$opt{"machine"}
ABresult
1X1
011
000
374  
375 176 ▶ if ($opt->{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"help"}) 3 173 176
376 3 $self->output->emit($self->usage);
377 3 return EXIT_OK;
378 }
379 173 ▶ if ($opt->{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"version"}) 2 171 173
380 2 $self->output->emit($self->version_line);
381 2 return EXIT_OK;
382 }
383  
384 171 ▶ if ($session_cmd && $session_cmd ne 'resume') {
Branch: 1 branch
BranchTrueFalseTotal
if ($session_cmd and $session_cmd ne "resume") 21 150 171
Condition100%3/3
$session_cmd and $session_cmd ne "resume"
!ll&&!rl&&r
147321
MC/DC100%2/2
$session_cmd and $session_cmd ne "resume"
$session_cmd $session_cmd ne "resume"
Truth table100%3/3
A and B
A= $session_cmdB= $session_cmd ne "resume"
ABresult
0X0
100
111
385 21 return $self->session_command($session_cmd, $session_id, $opt);
386 }
387 150 ▶ if (my $problem = $self->provider_usage_error($opt, $config_cmd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $problem = $self->provider_usage_error($opt, $config_cmd)) 5 145 150
388 5 $self->_warn($problem."\n");
389 5 return EXIT_USAGE;
390 }
391 145 ▶ if ($session_cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session_cmd) 3 142 145
392 # resume ID is the REPL on that session.
393 3 for my $flag (grep { $opt->{$_->[0]} } [ machine => 'a machine output format' ],
394 [ session => '--session' ], [ continue => '--continue' ], [ no_session => '--no-session' ]) {
395 1 $self->_warn('raider session resume: not with '.$flag->[1]."\n");
396 1 return EXIT_USAGE;
397 }
398 2 $opt->{session} = $session_id;
399 2 $opt->{interactive} = 1;
400 }
401  
402 144 my %args = $self->app_args($opt);
403 my $machine = $opt->{machine}
404 144 ▶ ? $self->machine_class->new(%{ $opt->{machine} }, out => $self->output->out)
Branch: 1 branch
BranchTrueFalseTotal
$$opt{'machine'} ? : 38 106 144
405 : undef;
406 # The runner, made once the app exists, reports a session journal that
407 # cannot be written.
408 144 my $runner;
409 144 ▶ $args{on_journal_error} = sub { $runner->journal_error(@_) if $runner };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
if $runner 4 0 4
410  
411 # A machine consumer gets its interrupted document also for a signal
412 # during startup (configuration, reading the prompt); the runner takes
413 # the signals over once the run starts.
414 144 my $t0 = Time::HiRes::time();
415 144 ▶ local $SIG{INT} = $machine ? sub { $self->interrupt_startup(INT => $machine, $t0) } : $SIG{INT};
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$machine ? : 38 106 144
416 144 ▶ local $SIG{TERM} = $machine ? sub { $self->interrupt_startup(TERM => $machine, $t0) } : $SIG{TERM};
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
$machine ? : 38 106 144
417  
418 # The one reader/writer of the project config (.raider/config.yml, else
419 # .raider.yml) and of the home config under it (~/.raider/config.yml).
420 # Both parsed up front so a broken file stops raider here, with its path
421 # in the message, and so does an invalid project_tools of the home file.
422 # A legacy file next to the new one is not loaded, and said so (ADR 0011).
423 144 ▶ my $config = $self->config_class->new(root => $opt->{root} // Path::Tiny->cwd->stringify);
Condition66%2/3
$$opt{"root"} // "Path::Tiny"->cwd->stringify
l!l&&r!l&&!r
14220
MC/DC0%0/2
$$opt{"root"} // "Path::Tiny"->cwd->stringify
$$opt{"root"} "Path::Tiny"->cwd->stringify
Truth table66%2/3
A // B
A= $$opt{"root"}B= "Path::Tiny"->cwd->stringify
ABresult
1X1
011
000
424 144 ▶ unless (eval { $config->data; $config->home_data; $config->project_tools; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $config->data; $config->home_data; $config->project_tools; 1 } }) 9 135 144
425 9 $self->_warn($self->output->error_text($@)."\n");
426 9 return EXIT_CONFIG;
427 }
428 135 $self->_warn('warning: ignoring '.$_->{file}.': '.$_->{reason}."\n") for $config->ignored_files;
429 135 $args{config} = $config;
430  
431 # --provider: the manifest decides engine, model and URL before anything
432 # is built or saved.
433 135 ▶ if (defined $opt->{provider}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$opt{"provider"}) 11 124 135
434 11 my $cli_opts = $opt->{engine_options};
435 my ( $exit, $activation ) = $self->provider_class->new(output => $self->output, err => $self->err)->activate(
436 $opt->{provider},
437 allow_internal => $opt->{allow_internal},
438 model => $opt->{model} // $cli_opts->{model},
439 11 ▶ has_api_key => length($opt->{api_key} // $cli_opts->{api_key} // '') ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
length(($$opt{'api_key'} // $$cli_opts{'api_key'}) // '') ? : 7 4 11
Condition100%8/8
$$opt{"model"} // $$cli_opts{"model"}
l!l&&r!l&&!r
119
($$opt{"api_key"} // $$cli_opts{"api_key"}) // ""
l!l
74
$$opt{"api_key"} // $$cli_opts{"api_key"}
l!l&&r!l&&!r
614
MC/DC100%2/2
$$opt{"model"} // $$cli_opts{"model"}
$$opt{"model"} $$cli_opts{"model"}
MC/DC100%2/2
($$opt{"api_key"} // $$cli_opts{"api_key"}) // ""
$$opt{"api_key"} $$cli_opts{"api_key"}
Truth table100%3/3
A // B
A= $$opt{"model"}B= $$cli_opts{"model"}
ABresult
1X1
011
000
Truth table100%3/3
A // B
A= $$opt{"api_key"}B= $$cli_opts{"api_key"}
ABresult
1X1
011
000
440 );
441 11 ▶ return $exit if defined $exit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exit 6 5 11
442 5 $args{provider} = $activation;
443 }
444  
445 129 my ( @skill_specs, @cli_profiles );
446 129 ▶ if ($opt->{profile_claude}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"profile_claude"}) 6 123 129
447 6 push @skill_specs, @{ $Langertha::Raider::CLI::AGENT_PROFILES{claude} };
448 6 push @cli_profiles, 'claude';
449 }
450 129 ▶ if ($opt->{profile_openai}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"profile_openai"}) 2 127 129
451 2 push @skill_specs, @{ $Langertha::Raider::CLI::AGENT_PROFILES{openai} };
452 2 push @cli_profiles, 'openai';
453 }
454 129 my @persist_skills = @cli_profiles;
455 129 for my $dir (@{ $opt->{skill_dirs} }) {
456 2 my $spec = { type => 'dir', path => $dir };
457 2 push @skill_specs, $spec;
458 # A directory named like a profile keyword is saved as a spec, so it is
459 # not read back as that profile.
460 2 ▶ push @persist_skills, ($dir =~ /\A(?:claude|openai|codex|agents)\z/ ? $spec : $dir);
Branch: 1 branch
BranchTrueFalseTotal
$dir =~ /\A(?:claude|openai|codex|agents)\z/ ? : 0 2 2
461 }
462 129 ▶ $args{cli_skill_sources} = \@skill_specs if @skill_specs;
Branch: 1 branch
BranchTrueFalseTotal
if @skill_specs 8 121 129
463  
464 # Persist --claude / --openai / --skills to the config file so the user doesn't
465 # need to retype them every invocation. Track which profiles were freshly
466 # persisted this run for the banner "(saved)" hint.
467 my %saved_now = $config_cmd ? ()
468 129 ▶ : map { $_ => 1 } grep { !ref } $config->add_skills(@persist_skills);
Branch: 1 branch
BranchTrueFalseTotal
$config_cmd ? : 19 110 129
469  
470 # Unknown engine or an invalid detection rule: stop before anything runs.
471 129 my $app = $self->app_class->new(%args);
472 129 ▶ unless (eval { $app->_engine_class; $app->packs; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $app->_engine_class; $app->packs; 1 } }) 5 124 129
473 5 $self->_warn($self->output->error_text($@)."\n");
474 5 return EXIT_CONFIG;
475 }
476 # A legacy .raider.md next to .raider/instructions.md is not used, and
477 # said so (ADR 0011), like the config file above.
478 124 $self->_warn('warning: ignoring '.$_->{file}.': '.$_->{reason}."\n") for $app->instructions->ignored_files;
479  
480 124 ▶ if ($config_cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_cmd) 17 107 124
481 17 $self->output->config_report($app->explain_config);
482 17 return EXIT_OK;
483 }
484  
485 # One-shot skill export paths. Empty string means "use default path".
486 107 ▶ if (defined $opt->{export_skill}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$opt{"export_skill"}) 7 100 107
487 my $path = length $opt->{export_skill}
488 ? $opt->{export_skill}
489 7 ▶ : path($app->root)->child('RAIDER-SKILL.md')->stringify;
Branch: 1 branch
BranchTrueFalseTotal
length $$opt{'export_skill'} ? : 7 0 7
490 7 my $p = $self->skill_class->new(app => $app)->write_markdown($path);
491 7 $self->_warn('wrote '.$p."\n");
492 7 return EXIT_OK;
493 }
494 100 ▶ if (defined $opt->{export_claude_skill}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$opt{"export_claude_skill"}) 0 100 100
495 0 my $skill = $self->skill_class->new(app => $app);
496 0 ▶ my $p = $skill->write_claude_skill(length $opt->{export_claude_skill} ? $opt->{export_claude_skill} : undef);
Branch: 1 branch
BranchTrueFalseTotal
length $$opt{'export_claude_skill'} ? : 0 0 0
497 0 $self->_warn('wrote '.$p."\n");
498 0 ▶ if (my $old = $skill->legacy_claude_skill) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = $skill->legacy_claude_skill) 0 0 0
499 0 $self->_warn('note: '.$old." is left over from an older raider, remove it\n");
500 }
501 0 return EXIT_OK;
502 }
503  
504 # Default to interactive REPL when stdin is a terminal and no prompt was
505 # given on argv / piped in / requested as one-shot machine output.
506 100 my $in = $self->in;
507 100 ▶ my $interactive = $opt->{interactive} || (!$opt->{machine} && !@prompt && -t $in);
Condition77%7/9
$$opt{'interactive'} || !($$opt{'machine'} || @prompt) && -t $in
l!l&&r!l&&!r
28072
not $$opt{"machine"} || @prompt and -t $in
!ll&&!rl&&r
7020
$$opt{'machine'} || @prompt
l!l&&r!l&&!r
36342
MC/DC25%1/4
$$opt{'interactive'} || !($$opt{'machine'} || @prompt) && -t $in
$$opt{'interactive'} $$opt{'machine'} @prompt -t $in
Truth table80%4/5
A || not(B || C) and D
A= $$opt{'interactive'}B= $$opt{'machine'}C= @promptD= -t $in
ABCDresult
1XXX1
00011
01XX0
001X0
00000
508 100 $runner = $self->runner_class->new(app => $app, output => $self->output, err => $self->err);
509 100 ▶ my $store = $opt->{no_session} ? undef : $app->session_store;
Branch: 1 branch
BranchTrueFalseTotal
$$opt{'no_session'} ? : 9 91 100
510  
511 # --session ID, --continue, session resume ID: the session is locked
512 # and replayed before anything runs.
513 100 my ( $session, @notes );
514 100 ▶ if (defined $opt->{session} || $opt->{continue}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$opt{"session"} or $$opt{"continue"}) 15 85 100
Condition100%3/3
defined $$opt{"session"} or $$opt{"continue"}
l!l&&r!l&&!r
12385
MC/DC100%2/2
defined $$opt{"session"} or $$opt{"continue"}
defined $$opt{"session"} $$opt{"continue"}
Truth table100%3/3
A or B
A= defined $$opt{"session"}B= $$opt{"continue"}
ABresult
1X1
011
000
515 15 ( my $exit, $session, @notes ) = $self->resume_session($app, $opt->{session});
516 15 ▶ return $exit if defined $exit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exit 6 9 15
517 }
518  
519 94 ▶ if ($interactive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interactive) 27 67 94
520 27 my %seen;
521 $self->repl_class->new(
522 app => $app,
523 output => $self->output,
524 in => $in,
525 runner => $runner,
526 $store ? ( session_store => $store ) : (),
527 0 ▶ active_profiles => [ grep { !$seen{$_}++ } @cli_profiles, $config->profiles($app->engine_name) ],
Branch: 2 branches
BranchTrueFalseTotal
$$opt{'customize_prompt'} ? : 0 27 27
$session ? : 2 25 27
528 saved_profiles => \%saved_now,
529 27 ▶ customize_prompt => $opt->{customize_prompt} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$store ? : 26 1 27
530 $session ? ( session => $session ) : (),
531 notes => \@notes,
532 )->run(@prompt);
533 21 return EXIT_OK;
534 }
535  
536 67 my $text;
537 67 ▶ if (@prompt) {
Branch: 2 branches
BranchTrueFalseTotal
if (@prompt) { } 65 2 67
elsif (-t $in) { } 0 2 2
538 65 $text = join ' ', @prompt;
539 }
540 elsif (-t $in) {
541 # Interactive terminal but no -i and no argv: ask once.
542 0 $text = prompt($self->output->c(prompt => 'raider>'));
543 }
544 else {
545 2 local $/;
546 2 $text = <$in>;
547 }
548 67 ▶ unless (defined $text && length $text) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text and length $text) 1 66 67
Condition66%2/3
defined $text and length $text
!ll&&!rl&&r
0166
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
ABresult
0X0
100
111
549 1 $self->_warn("No prompt given.\n");
550 1 return EXIT_USAGE;
551 }
552 66 ▶ if ($session) {
Branch: 2 branches
BranchTrueFalseTotal
if ($session) { } 7 59 66
elsif ($store) { } 51 8 59
553 7 $self->_warn($_."\n") for @notes;
554 }
555 elsif ($store) {
556 51 $session = $self->new_session($app, $machine);
557 }
558 66 ▶ return $runner->run_prompt($text, machine => $machine, session => $session, catch_signals => 1)
Branch: 1 branch
BranchTrueFalseTotal
$runner->run_prompt($text, 'machine', $machine, 'session', $session, 'catch_signals', 1) ? : 52 14 66
559 ? EXIT_OK : EXIT_RUN_ERROR;
560 }
561  
562  
563 15 ▶sub resume_session {
Subroutine resume_session: called CC=8 SCAR=21.3
Pod documented
564 15 my ( $self, $app, $ref ) = @_;
565 15 my $store = $app->session_store;
566 15 ▶ my $id = defined $ref ? $self->resolve_session($store, $ref) : $store->latest;
Branch: 1 branch
BranchTrueFalseTotal
defined $ref ? : 12 3 15
567 15 ▶ unless (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id) 3 12 15
568 3 ▶ $self->_warn('no session to continue in '.$store->dir."\n") unless defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 1 2 3
569 3 return EXIT_USAGE;
570 }
571 12 my $session = eval { $app->open_session($id) };
572 12 ▶ unless ($session) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session) 3 9 12
573 3 my $error = $self->output->error_text($@);
574 3 ▶ $self->_warn($error.($error =~ / is in use\z/ ? ' by another raider' : '')."\n");
Branch: 1 branch
BranchTrueFalseTotal
$error =~ / is in use\z/ ? : 3 0 3
575 3 ▶ return $error =~ / is in use\z/ ? EXIT_SESSION_IN_USE : EXIT_RUN_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
$error =~ / is in use\z/ ? : 3 0 3
576 }
577 9 my @notes = eval {
578 9 $self->sessions_class->new(app => $app, output => $self->output)->restore($session);
579 };
580 9 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 9 9
581 0 my $error = $self->output->error_text($@);
582 0 $self->_warn('cannot resume session '.$id.': '.$error."\n");
583 0 return EXIT_RUN_ERROR;
584 }
585 9 return ( undef, $session, @notes );
586 }
587  
588  
589 21 ▶sub session_command {
Subroutine session_command: called CC=11 SCAR=24.1
Pod documented
590 21 my ( $self, $cmd, $id, $opt ) = @_;
591 21 my $machine;
592 21 ▶ if (my $m = $opt->{machine}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $$opt{"machine"}) 7 14 21
593 7 ▶ if ($m->{stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$m{"stream"}) 2 5 7
594 2 $self->_warn('raider session '.$cmd.": no --stream-* output, only a document\n");
595 2 return EXIT_USAGE;
596 }
597 5 $machine = $self->machine_class->new(%$m, out => $self->output->out);
598 }
599 # The app of the project; building it reads no .raider.yml and builds no
600 # engine.
601 19 ▶ my $app = $self->app_class->new(root => $opt->{root} // Path::Tiny->cwd->stringify);
Condition33%1/3
$$opt{"root"} // "Path::Tiny"->cwd->stringify
l!l&&r!l&&!r
1900
MC/DC0%0/2
$$opt{"root"} // "Path::Tiny"->cwd->stringify
$$opt{"root"} "Path::Tiny"->cwd->stringify
Truth table33%1/3
A // B
A= $$opt{"root"}B= "Path::Tiny"->cwd->stringify
ABresult
1X1
011
000
602 19 my $store = $app->session_store;
603 19 my $sessions = $self->sessions_class->new(app => $app, output => $self->output);
604 19 ▶ if ($cmd eq 'list') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "list") 3 16 19
605 3 $sessions->list($machine);
606 3 return EXIT_OK;
607 }
608 16 ▶ $id = $self->resolve_session($store, $id) // return EXIT_USAGE;
Condition100%2/2
$self->resolve_session($store, $id) // (return 2)
l!l
115
MC/DC100%1/1
$self->resolve_session($store, $id) // (return 2)
$self->resolve_session($store, $id)
Truth table100%2/2
A
A= $self->resolve_session($store, $id)
Aresult
11
00
609 11 ▶ if ($cmd eq 'show') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "show") 6 5 11
610 6 $sessions->show($id, $machine);
611 6 return EXIT_OK;
612 }
613 5 ▶ my $method = $cmd eq 'fork' ? 'fork_session' : 'remove';
Branch: 1 branch
BranchTrueFalseTotal
$cmd eq 'fork' ? : 2 3 5
614 5 ▶ return EXIT_OK if eval { $sessions->$method($id, $machine); 1 };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $sessions->$method($id, $machine); 1 } } 4 1 5
615 1 my $error = $self->output->error_text($@);
616 1 my $in_use = $error =~ / is in use\z/;
617 1 ▶ $self->_warn($error.($in_use ? ' by another raider' : '')."\n");
Branch: 1 branch
BranchTrueFalseTotal
$in_use ? : 1 0 1
618 1 ▶ return $in_use ? EXIT_SESSION_IN_USE : EXIT_RUN_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
$in_use ? : 1 0 1
619 }
620  
621  
622 1 ▶sub migrate_usage { <<'USAGE' }
Subroutine migrate_usage: called CC=1 SCAR=0.0
Pod documented
623 Usage: raider config migrate [--dry-run] [options]
624  
625 Moves the legacy project files of the working directory (-r DIR) to the
626 .raider/ layout: .raider.yml to .raider/config.yml and .raider.md to
627 .raider/instructions.md, each only when it exists. Shows what it does
628 first. Each new file is written atomically; the legacy file is renamed to
629 .raider.yml.bak / .raider.md.bak, so afterwards the same settings are read
630 from the new files. .raider/ is created with its .gitignore (sessions/,
631 lib/).
632  
633 api_key (top level, default: or an engine section) is not copied into
634 .raider/config.yml, which is meant to be shared: it is reported; move it
635 to ~/.raider/config.yml or the engine's *_API_KEY environment variable.
636  
637 Nothing is merged: when .raider/config.yml or .raider/instructions.md (or
638 a backup) already exists, nothing is written.
639  
640 Options:
641 --dry-run Show what would happen, write nothing
642 -r, --root DIR The project (default: cwd)
643 --no-color Disable ANSI colors
644 -h, --help Show this help
645  
646 The report is for humans only; there is no --json form.
647  
648 Exit status: 0 migrated, nothing to migrate or a dry run, 1 refused or
649 failed, 2 usage error, 3 .raider.yml cannot be read.
650 USAGE
651  
652  
653 22 ▶sub migrate_command {
Subroutine migrate_command: called CC=19 SCAR=29.6
Pod documented
654 22 my ( $self, @argv ) = @_;
655 # --dry-run belongs to this subcommand only, so it is taken out before
656 # the common options are parsed.
657 22 my $dry_run = 0;
658 22 my @rest;
659 22 ▶ while (@argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (@argv) 47 22 69
660 47 my $arg = shift @argv;
661 47 ▶ if ($arg eq '--') { push @rest, $arg, @argv; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "--") 0 47 47
662 47 ▶ if ($arg eq '--dry-run') { $dry_run = 1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "--dry-run") 3 44 47
663 44 push @rest, $arg;
664 }
665 22 ▶ my ( $opt, @words ) = $self->parse_options(@rest) or return EXIT_USAGE;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->parse_options(@rest) or return 2 21 1 22
666 21 ▶ if ($opt->{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"help"}) 1 20 21
667 1 $self->output->emit($self->migrate_usage);
668 1 return EXIT_OK;
669 }
670 20 ▶ if (@words) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words) 1 19 20
671 1 $self->_warn("Usage: raider config migrate [--dry-run] [options]\n");
672 1 return EXIT_USAGE;
673 }
674 19 ▶ if ($opt->{machine}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"machine"}) 1 18 19
675 1 $self->_warn("raider config migrate: no machine output, the report is for humans only\n");
676 1 return EXIT_USAGE;
677 }
678 18 ▶ $ENV{ANSI_COLORS_DISABLED} = 1 if $opt->{no_color};
Branch: 1 branch
BranchTrueFalseTotal
if $$opt{"no_color"} 0 18 18
679  
680 18 ▶ my $migrate = $self->migrate_class->new(root => $opt->{root} // Path::Tiny->cwd->stringify);
Condition33%1/3
$$opt{"root"} // "Path::Tiny"->cwd->stringify
l!l&&r!l&&!r
1800
MC/DC0%0/2
$$opt{"root"} // "Path::Tiny"->cwd->stringify
$$opt{"root"} "Path::Tiny"->cwd->stringify
Truth table33%1/3
A // B
A= $$opt{"root"}B= "Path::Tiny"->cwd->stringify
ABresult
1X1
011
000
681 18 my $plan = eval { $migrate->plan };
682 18 ▶ unless ($plan) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plan) 1 17 18
683 1 $self->_warn($self->output->error_text($@)."\n");
684 1 return EXIT_CONFIG;
685 }
686 17 ▶ if (my @refused = @{ $plan->{refused} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@refused) = @{$$plan{"refused"};}) 6 11 17
687 6 $self->_warn('raider config migrate: '.$_."\n") for @refused;
688 6 $self->_warn("raider config migrate: nothing written\n");
689 6 return EXIT_RUN_ERROR;
690 }
691 11 $self->output->migrate_report($plan, dry_run => $dry_run);
692 11 ▶ return EXIT_OK if $dry_run || !@{ $plan->{steps} };
Branch: 1 branch
BranchTrueFalseTotal
if $dry_run or not @{$$plan{"steps"};} 4 7 11
Condition100%3/3
$dry_run or not @{$$plan{"steps"};}
l!l&&r!l&&!r
227
MC/DC100%2/2
$dry_run or not @{$$plan{"steps"};}
$dry_run not @{$$plan{"steps"};}
Truth table100%3/3
A or not(B)
A= $dry_runB= not @{$$plan{"steps"};}
ABresult
1X1
011
000
693  
694 7 my @results = $migrate->apply($plan);
695 7 $self->output->migrate_done(@results);
696 7 my $failed = 0;
697 7 for my $r (@results) {
698 9 my $s = $r->{step};
699 9 ▶ if ($r->{error}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$r{'error'}) { } 1 8 9
elsif ($$r{'skipped'}) { } 0 8 8
700 1 $failed = 1;
701 $self->_warn('raider config migrate: '.$s->{from_label}.' not migrated, it stays in use: '
702 1 .$self->output->error_text($r->{error})."\n");
703 }
704 elsif ($r->{skipped}) {
705 0 $self->_warn('raider config migrate: '.$s->{from_label}." not migrated, stopped after the error above\n");
706 }
707 }
708 7 ▶ return $failed ? EXIT_RUN_ERROR : EXIT_OK;
Branch: 1 branch
BranchTrueFalseTotal
$failed ? : 1 6 7
709 }
710  
711  
712 1 ▶sub provider_usage { <<'USAGE' }
Subroutine provider_usage: called CC=1 SCAR=0.0
Pod documented
713 Usage: raider provider inspect HOST[:PORT] | https://HOST[:PORT] [options]
714  
715 Fetches https://HOST[:PORT]/.well-known/langertha.json, validates it as a
716 provider manifest and shows provider id, issuer, endpoints, auth and
717 models. Nothing is stored and no credential is sent or bound.
718  
719 Options:
720 --allow-internal Allow a loopback, private, link-local or reserved
721 target address, for a deliberately released
722 internal knarr or skeid (cloud metadata,
723 multicast and unspecified addresses stay refused)
724 --json[=N] Print one JSON document (also --msgpack, --yaml)
725 --no-color Disable ANSI colors
726 -h, --help Show this help
727  
728 Limits: https only, 1 MiB, 10 seconds, 3 redirects within the origin; a
729 redirect to another origin is not followed.
730  
731 Exit status: 0 a valid manifest, 1 refused, not fetched or not valid,
732 2 usage error.
733 USAGE
734  
735  
736 25 ▶sub provider_command {
Subroutine provider_command: called CC=11 SCAR=24.0
Pod documented
737 25 my ( $self, $cmd, @argv ) = @_;
738 # --allow-internal belongs to this subcommand only, so it is taken out
739 # before the common options are parsed.
740 25 my $allow_internal = 0;
741 25 my @rest;
742 25 ▶ while (@argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (@argv) 55 25 80
743 55 my $arg = shift @argv;
744 55 ▶ if ($arg eq '--') { push @rest, $arg, @argv; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "--") 0 55 55
745 55 ▶ if ($arg eq '--allow-internal') { $allow_internal = 1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "--allow-internal") 16 39 55
746 39 push @rest, $arg;
747 }
748 25 ▶ my ( $opt, @words ) = $self->parse_options(@rest) or return EXIT_USAGE;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->parse_options(@rest) or return 2 24 1 25
749 24 ▶ if ($opt->{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$opt{"help"}) 1 23 24
750 1 $self->output->emit($self->provider_usage);
751 1 return EXIT_OK;
752 }
753 23 ▶ if (@words != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words != 1) 2 21 23
754 2 $self->_warn("Usage: raider provider inspect HOST[:PORT] | https://HOST[:PORT] [--json] [--allow-internal]\n");
755 2 return EXIT_USAGE;
756 }
757 21 ▶ $ENV{ANSI_COLORS_DISABLED} = 1 if $opt->{no_color} || $opt->{machine};
Branch: 1 branch
BranchTrueFalseTotal
if $$opt{"no_color"} or $$opt{"machine"} 11 10 21
Condition66%2/3
$$opt{"no_color"} or $$opt{"machine"}
l!l&&r!l&&!r
01110
MC/DC50%1/2
$$opt{"no_color"} or $$opt{"machine"}
$$opt{"no_color"} $$opt{"machine"}
Truth table66%2/3
A or B
A= $$opt{"no_color"}B= $$opt{"machine"}
ABresult
1X1
011
000
758 21 my $machine;
759 21 ▶ if (my $m = $opt->{machine}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $$opt{"machine"}) 11 10 21
760 11 ▶ if ($m->{stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$m{"stream"}) 1 10 11
761 1 $self->_warn('raider provider '.$cmd.": no --stream-* output, only a document\n");
762 1 return EXIT_USAGE;
763 }
764 10 $machine = $self->machine_class->new(%$m, out => $self->output->out);
765 }
766 20 return $self->provider_class->new(output => $self->output, err => $self->err)
767 ->inspect($words[0], allow_internal => $allow_internal, machine => $machine);
768 }
769  
770  
771 150 ▶sub provider_usage_error {
Subroutine provider_usage_error: called CC=9 SCAR=22.0
Pod documented
772 150 my ( $self, $opt, $config_cmd ) = @_;
773 150 ▶ unless (defined $opt->{provider}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$opt{"provider"}) 135 15 150
774 135 ▶ return $opt->{allow_internal} ? '--allow-internal: only with --provider' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$opt{'allow_internal'} ? : 1 134 135
775 }
776 15 ▶ my $cli_opts = $opt->{engine_options} // {};
Condition50%1/2
$$opt{"engine_options"} // {}
l!l
150
MC/DC0%0/1
$$opt{"engine_options"} // {}
$$opt{"engine_options"}
Truth table50%1/2
A
A= $$opt{"engine_options"}
Aresult
11
00
777 my @conflicts = (
778 ( defined $opt->{engine} ? '-e/--engine' : () ),
779 ( exists $cli_opts->{engine} ? '-o engine=' : () ),
780 15 ▶ ( exists $cli_opts->{url} ? '-o url=' : () ),
Branch: 3 branches
BranchTrueFalseTotal
defined $$opt{'engine'} ? : 1 14 15
exists $$cli_opts{'engine'} ? : 1 14 15
exists $$cli_opts{'url'} ? : 1 14 15
781 );
782 15 ▶ return '--provider: not with '.join(', ', @conflicts).'; the provider manifest decides the engine and its URL'
Branch: 1 branch
BranchTrueFalseTotal
if @conflicts 3 12 15
783 if @conflicts;
784 12 ▶ return '--provider: not with config explain' if $config_cmd;
Branch: 1 branch
BranchTrueFalseTotal
if $config_cmd 1 11 12
785 11 return;
786 }
787  
788  
789 28 ▶sub resolve_session {
Subroutine resolve_session: called CC=2 SCAR=6.9
Pod documented
790 28 my ( $self, $store, $ref ) = @_;
791 28 my $id = eval { $store->resolve($ref) };
792 28 ▶ $self->_warn($self->output->error_text($@)."\n") unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 7 21 28
793 28 return $id;
794 }
795  
796  
797 51 ▶sub new_session {
Subroutine new_session: called CC=3 SCAR=11.0
Pod documented
798 51 my ( $self, $app, $machine ) = @_;
799 51 my $session = eval { $app->create_session };
800 51 ▶ unless ($session) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session) 1 50 51
801 1 my $error = $self->output->error_text($@);
802 1 $self->_warn('session not saved: '.$error."\n");
803 1 return;
804 }
805 50 ▶ $self->_warn('session '.$session->id.' ('.$session->path.")\n") unless $machine;
Branch: 1 branch
BranchTrueFalseTotal
unless $machine 24 26 50
806 50 return $session;
807 }
808  
809  
810 0 ▶sub interrupt_startup {
Subroutine interrupt_startup: not called CC=1 SCAR=6.9
Pod documented
811 0 my ( $self, $signal, $machine, $t0 ) = @_;
812 0 my $runner = $self->runner_class;
813 0 return $runner->interrupt($signal => $machine, $runner->elapsed_since($t0));
814 }
815  
816 55 __PACKAGE__->meta->make_immutable;
817  
818 55 1;
819  
820 __END__
821  
822 =pod
823  
824 =encoding UTF-8
825  
826 =head1 NAME
827  
828 Langertha::Raider::CLI::Main - Internal command-line entry point behind bin/raider
829  
830 =head1 VERSION
831  
832 version 0.503
833  
834 =head1 SYNOPSIS
835  
836 # Internal to Langertha-Raider -- no API promise.
837 exit Langertha::Raider::CLI::Main->new->run(@ARGV);
838  
839 =head1 DESCRIPTION
840  
841 B<Internal module.> Its interface may change without notice.
842  
843 Everything F<raider> does with its command line: the C<hall>, C<acp>,
844 C<config explain>, C<config migrate>, C<session> and C<provider inspect> subcommands, option parsing, the skill exports, and
845 then either the REPL (L<Langertha::Raider::CLI::REPL>) or one prompt
846 (L<Langertha::Raider::CLI::Runner>). L</run> returns the exit status.
847  
848 =head2 Exit status
849  
850 =over
851  
852 =item C<0> -- success, including C<--help>, C<--version>, the exports, C<config explain>,
853 C<config migrate> (also with nothing to migrate, and C<--dry-run>), C<session list>, C<session show>, C<session fork>, C<session rm>,
854 C<provider inspect> of a valid manifest and leaving the REPL.
855  
856 =item C<1> -- the run failed: the engine, a tool or the network raised an
857 error (with a machine format, the output is the C<failed> document); for
858 C<config migrate>: the migration was refused (a new file or a backup
859 already exists, F<.raider> is no directory, the home directory) or a step
860 failed; for C<provider inspect>: the manifest was refused (address, redirect), could
861 not be fetched or is not valid; for C<--provider> also: its endpoint is
862 not usable (another origin, not https, a refused address, a dialect or
863 auth type this raider has no adapter for, no models, a model on several
864 endpoints).
865  
866 =item C<2> -- usage error: unknown option, a C<-o> that is not
867 C<KEY=VALUE>, an unknown C<config> subcommand, no prompt, more than one
868 machine format, a machine format with C<-i>, or an unknown machine format
869 version; for C<config migrate>: a word after it or a machine format;
870 for sessions: a C<--session> value that is no session id,
871 more than one of C<--session>, C<--continue> and C<--no-session>, an unknown
872 or ambiguous session, or C<--continue> without any session; for
873 C<provider inspect>: no target or more than one, a target that is no
874 host or https origin, or a C<--stream-*> flag; for C<--provider>: a
875 target that is none, C<-e>, C<-o engine=>, C<-o url=> or C<config explain>
876 with it, a model the manifest does not list, no C<-m> where it lists
877 several models, or no C<-k> where the endpoint needs a key;
878 C<--allow-internal> without C<--provider>.
879  
880 =item C<3> -- configuration error: the config file (F<.raider/config.yml>,
881 else F<.raider.yml>; for C<config migrate> the F<.raider.yml> to migrate)
882 cannot be read, the
883 engine is unknown, or a pack detection rule is invalid.
884  
885 =item C<4> -- the session to continue (C<--session>, C<--continue>,
886 C<session resume>) or to remove (C<session rm>) is in use: another raider
887 has it open for writing and holds its lock. Unlike a usage error the same
888 command can work later, which is why it has a status of its own.
889  
890 =item C<130>, C<143> -- a one-shot run was cancelled by C<SIGINT> or
891 interrupted by C<SIGTERM> (see L<Langertha::Raider::CLI::Runner/run_prompt>).
892 It writes the C<cancelled> or C<interrupted> document (or a note), then
893 dies of that same signal, which a shell reports as 128 plus the signal
894 number; see L<Langertha::Raider::CLI::Runner/die_of_signal>.
895  
896 =back
897  
898 The C<hall> and C<acp> subcommands keep their own exit statuses. The REPL's
899 two-strike Ctrl-C leaves with C<0>.
900  
901 =head2 output
902  
903 The L<Langertha::Raider::CLI::Output> for everything but diagnostics.
904 Defaults to one on C<STDOUT>.
905  
906 =head2 err
907  
908 Filehandle for diagnostics. Defaults to C<STDERR>.
909  
910 =head2 in
911  
912 Filehandle a prompt or the REPL input is read from. Defaults to C<STDIN>.
913  
914 =head2 usage
915  
916 The C<--help> text.
917  
918 =head2 version_line
919  
920 The C<--version> line: F<raider>'s version (that of L<Langertha::Raider>),
921 then that of L<Langertha> core.
922  
923 raider 0.503 (Langertha 0.503) # for example
924  
925 =head2 parse_options
926  
927 my ( $opt, @prompt ) = $main->parse_options(@argv);
928  
929 Parses the options; returns the option hash (with C<-o> pairs in
930 C<engine_options>, and a machine format in C<machine> as C<format>,
931 C<stream> and C<version>) and the remaining words, or nothing after reporting a
932 usage error.
933  
934 =head2 app_args
935  
936 my %args = $main->app_args($opt);
937  
938 Constructor arguments for L<Langertha::Raider::CLI> from the parsed
939 options, without C<config> and the skill sources. With a machine format
940 the live trace is off unless C<--trace> asks for it, and then goes to
941 L</err>, so stdout carries only the machine output.
942  
943 =head2 run
944  
945 my $exit = $main->run(@argv);
946  
947 Does what the command line says and returns the exit status.
948  
949 =head2 resume_session
950  
951 my ( $exit, $session, @notes ) = $main->resume_session($app, $ref);
952  
953 Opens the session C<$ref> names (L</resolve_session>; the newest one of
954 the project when C<undef>, for C<--continue>) for writing through
955 L<Langertha::Raider::Application/open_session> and replays it into the
956 app's raider through L<Langertha::Raider::CLI::Sessions/restore>. Returns C<undef>, the
957 L<Langertha::Raider::Session> and the notes of the resume -- or, after
958 reporting why, just the exit status: C<2> when there is no such session
959 or C<$ref> is ambiguous, C<4> when another raider has it open, C<1> when
960 it cannot be opened or replayed otherwise.
961  
962 =head2 session_command
963  
964 my $exit = $main->session_command(list => undef, $opt);
965 my $exit = $main->session_command(show => $id, $opt);
966  
967 C<raider session list>, C<show ID>, C<fork ID> and C<rm ID> for the
968 project in C<-r> (or the working directory), through the
969 L<Langertha::Raider::Application> of that project and
970 L<Langertha::Raider::CLI::Sessions>; a document format (C<--json>,
971 C<--msgpack>, C<--yaml>) writes them as one document. C<rm> of a session
972 another raider has open ends with C<4>, as a resume of it would; a fork or
973 removal that fails otherwise with C<1>.
974  
975 =head2 migrate_usage
976  
977 The C<raider config migrate --help> text.
978  
979 =head2 migrate_command
980  
981 my $exit = $main->migrate_command(@argv);
982  
983 C<raider config migrate [--dry-run] [options]> through
984 L<Langertha::Raider::Config::Migrate>: the report
985 (L<Langertha::Raider::CLI::Output/migrate_report>) on L</output>, then,
986 without C<--dry-run>, the migration. A refusal or a failed step is
987 reported on L</err>. Takes C<--dry-run>, C<-r>, C<--no-color> and
988 C<--help>; the other options of F<raider> are accepted and have no effect,
989 as for the session commands. A word after it or a machine format is a
990 usage error: the report is for humans only.
991  
992 =head2 provider_usage
993  
994 The C<raider provider inspect --help> text.
995  
996 =head2 provider_command
997  
998 my $exit = $main->provider_command(inspect => @argv);
999  
1000 C<raider provider inspect TARGET [options]> through
1001 L<Langertha::Raider::CLI::Provider>. Takes C<--allow-internal>, a document
1002 format (C<--json>, C<--msgpack>, C<--yaml>; no stream), C<--no-color> and
1003 C<--help>; the other options of F<raider> are accepted and have no effect,
1004 as for the session commands. Exactly one target is a must.
1005  
1006 =head2 provider_usage_error
1007  
1008 my $problem = $main->provider_usage_error($opt, $config_cmd);
1009  
1010 Why C<--provider> or C<--allow-internal> cannot go with the rest of the
1011 command line, or C<undef>. C<--provider> decides the engine and its URL,
1012 so it excludes C<-e>, C<-o engine=> and C<-o url=>, and it does not go with
1013 C<config explain>; C<--allow-internal> only goes with C<--provider>.
1014  
1015 =head2 resolve_session
1016  
1017 my $id = $main->resolve_session($store, '3f2a');
1018  
1019 The whole id of the session a command-line reference names -- the id, a
1020 unique start of it or its four hex digits
1021 (L<Langertha::Raider::SessionStore/resolve>). An unknown or ambiguous
1022 reference is reported on L</err> and gives C<undef>.
1023  
1024 =head2 new_session
1025  
1026 my $session = $main->new_session($app, $machine);
1027  
1028 Starts the session a one-shot run is recorded in
1029 (L<Langertha::Raider::Application/create_session>) and names it on L</err>
1030 (with a machine format the document names it instead). A session that
1031 cannot be written is reported and the run goes on without one.
1032  
1033 =head2 interrupt_startup
1034  
1035 $main->interrupt_startup(TERM => $machine, $t0);
1036  
1037 Ends raider on a C<SIGINT> or C<SIGTERM> that arrives with a machine
1038 format before the run starts: the C<interrupted> document (or its
1039 C<run.finished>), then death by the signal, as for an interrupted run
1040 (L<Langertha::Raider::CLI::Runner/interrupt>).
1041  
1042 =head1 SEE ALSO
1043  
1044 =over
1045  
1046 =item * L<raider>
1047  
1048 =item * L<Langertha::Raider::CLI>
1049  
1050 =back
1051  
1052 =head1 SUPPORT
1053  
1054 =head2 Issues
1055  
1056 Please report bugs and feature requests on GitHub at
1057 L<https://github.com/Getty/langertha-raider/issues>.
1058  
1059 =head2 IRC
1060  
1061 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
1062  
1063 =head1 CONTRIBUTING
1064  
1065 Contributions are welcome! Please fork the repository and submit a pull request.
1066  
1067 =head1 AUTHOR
1068  
1069 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
1070  
1071 =head1 COPYRIGHT AND LICENSE
1072  
1073 This software is copyright (c) 2026 by Torsten Raudssus.
1074  
1075 This is free software; you can redistribute it and/or modify it under
1076 the same terms as the Perl 5 programming language system itself.
1077  
1078 =cut
↑ Summary blib/lib/Langertha/Raider/Hall/MCP.pm »