| 1 | package Langertha::Raider::CLI; | ||||||||||||||||||||
| 2 | # ABSTRACT: Autonomous CLI agent that can browse directories, edit files, and run bash commands | ||||||||||||||||||||
| 3 | 73 | our $VERSION = '0.503'; | |||||||||||||||||||
| 4 | 73 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 73 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 73 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 73 | ▶ | use Langertha::Raider::Application; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 73 | extends 'Langertha::Raider::Application'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # Plain functions, kept for callers of the former tables here; the tables | ||||||||||||||||||||
| 14 | # are the resolver's. | ||||||||||||||||||||
| 15 | 0 | ▶ | sub env_var_for_engine { | ||||||||||||||||||
|
Subroutine
env_var_for_engine: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 16 | 0 | my ($engine) = @_; | |||||||||||||||||||
| 17 | 0 | return __PACKAGE__->engine_resolver_class->env_var_for_engine($engine); | |||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub default_model_for_engine { | ||||||||||||||||||
|
Subroutine
default_model_for_engine: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 21 | 0 | my ($engine) = @_; | |||||||||||||||||||
| 22 | 0 | return __PACKAGE__->engine_resolver_class->default_model_for_engine($engine); | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | has trace => ( | ||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||
| 28 | isa => 'Bool', | ||||||||||||||||||||
| 29 | 87 | ▶ | default => sub { -t STDOUT ? 1 : 0 }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 73 | ); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | has trace_out => ( | ||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||
| 35 | 359 | ▶ | default => sub { \*STDOUT }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 73 | ); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | # Well-known per-tool files + source dirs. Used both for loading (when the | ||||||||||||||||||||
| 39 | # matching profile flag is set) and for the "ignored but present" notice. | ||||||||||||||||||||
| 40 | 73 | our %AGENT_PROFILES = ( | |||||||||||||||||||
| 41 | claude => [ | ||||||||||||||||||||
| 42 | { type => 'file', path => 'CLAUDE.md' }, | ||||||||||||||||||||
| 43 | { type => 'claude', path => '.claude/skills' }, | ||||||||||||||||||||
| 44 | ], | ||||||||||||||||||||
| 45 | openai => [ | ||||||||||||||||||||
| 46 | { type => 'file', path => 'AGENTS.md' }, | ||||||||||||||||||||
| 47 | ], | ||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 132 | ▶ | around _raider_plugins => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 51 | 132 | my ( $orig, $self ) = @_; | |||||||||||||||||||
| 52 | 132 | my @plugins = $self->$orig; | |||||||||||||||||||
| 53 | # Pass as name + {args}; PluginHost still injects `host`. The `loop` arg | ||||||||||||||||||||
| 54 | # lets the plugin drive a spinner during LLM HTTP calls. | ||||||||||||||||||||
| 55 | 132 | ▶ | unshift @plugins, '+Langertha::Raider::Plugin::Trace', { loop => $self->loop, out => $self->trace_out } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | if $self->trace; | ||||||||||||||||||||
| 57 | 132 | return @plugins; | |||||||||||||||||||
| 58 | 73 | }; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 455 | ▶ | sub source_labels { | ||||||||||||||||||
|
Subroutine
source_labels: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 62 | return { | ||||||||||||||||||||
| 63 | 455 | engine => '-e', | |||||||||||||||||||
| 64 | model => '-m', | ||||||||||||||||||||
| 65 | api_key => '-k', | ||||||||||||||||||||
| 66 | engine_options => '-o', | ||||||||||||||||||||
| 67 | 'engine_options packs' => '-o packs', | ||||||||||||||||||||
| 68 | pack_names => '--pack', | ||||||||||||||||||||
| 69 | no_pack_names => '--no-pack', | ||||||||||||||||||||
| 70 | perl => '--perl', | ||||||||||||||||||||
| 71 | detect => '--detect', | ||||||||||||||||||||
| 72 | no_detect => '--no-detect', | ||||||||||||||||||||
| 73 | bare => '--bare', | ||||||||||||||||||||
| 74 | mission => '-M', | ||||||||||||||||||||
| 75 | cli_skill_sources => '--claude/--openai/--skills', | ||||||||||||||||||||
| 76 | }; | ||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 139 | ▶ | sub persona_intro { <<'EOM' } | ||||||||||||||||||
|
Subroutine
persona_intro: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 81 | You are Langertha, viking shield-maiden. Autonomous CLI agent on user's | ||||||||||||||||||||
| 82 | local machine. CLI name: "raider". Just CLI. No pause, no abort, no ask | ||||||||||||||||||||
| 83 | to stop. You do things. | ||||||||||||||||||||
| 84 | EOM | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 139 | ▶ | sub persona_turn_end { <<'EOM' } | ||||||||||||||||||
|
Subroutine
persona_turn_end: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 87 | You have no yield / ask / abort tool. Task done: plain text reply. CLI | ||||||||||||||||||||
| 88 | loops back to user. | ||||||||||||||||||||
| 89 | EOM | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 83 | ▶ | sub ignored_agent_files { | ||||||||||||||||||
|
Subroutine
ignored_agent_files: called CC=11 SCAR=24.6
Pod
documented
| |||||||||||||||||||||
| 93 | 83 | my ($self) = @_; | |||||||||||||||||||
| 94 | 83 | ▶ | return if $self->bare; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 83 | my %loaded; | |||||||||||||||||||
| 97 | 83 | for my $s (@{$self->skill_sources}) { | |||||||||||||||||||
| 98 | 1 | ▶ | next unless ($s->{type} // '') eq 'file'; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$s{"type"} // ""
MC/DC0%0/1
$$s{"type"} // ""
$$s{"type"}
Truth table50%1/2
A
A= $$s{"type"}
| |||||||||||||||||||||
| 99 | 1 | my $p = Path::Tiny::path($s->{path}); | |||||||||||||||||||
| 100 | 1 | ▶ | $p = Path::Tiny::path($self->root)->child($s->{path}) unless $p->is_absolute; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 1 | $loaded{ $p->canonpath }++; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 83 | my @out; | |||||||||||||||||||
| 105 | 83 | for my $profile (sort keys %AGENT_PROFILES) { | |||||||||||||||||||
| 106 | 166 | for my $spec (@{$AGENT_PROFILES{$profile}}) { | |||||||||||||||||||
| 107 | 249 | ▶ | next unless $spec->{type} eq 'file'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | 166 | my $p = Path::Tiny::path($self->root)->child($spec->{path}); | |||||||||||||||||||
| 109 | 166 | ▶ | next unless -f $p; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 1 | ▶ | next if $loaded{ $p->canonpath }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | push @out, { path => $p->basename, profile => $profile }; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | 83 | return @out; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 92 | ▶ | sub trace_plugin { | ||||||||||||||||||
|
Subroutine
trace_plugin: called CC=4 SCAR=22.5
Pod
documented
| |||||||||||||||||||||
| 119 | 92 | my ($self) = @_; | |||||||||||||||||||
| 120 | 92 | ▶ | return unless $self->trace; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | 0 | for my $p (@{$self->_raider->plugin_instances}) { | |||||||||||||||||||
| 122 | 0 | ▶ | return $p if $p->isa('Langertha::Raider::Plugin::Trace'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | 0 | return; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 88 | ▶ | sub token_stats { | ||||||||||||||||||
|
Subroutine
token_stats: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||
| 129 | 88 | my ($self) = @_; | |||||||||||||||||||
| 130 | 88 | ▶ | my $t = $self->trace_plugin or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 131 | 0 | return $t->token_stats; | |||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 73 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 73 | 1; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =pod | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =encoding UTF-8 | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head1 NAME | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Langertha::Raider::CLI - Autonomous CLI agent that can browse directories, edit files, and run bash commands | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =head1 VERSION | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | version 0.503 | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =head1 SYNOPSIS | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | use Langertha::Raider::CLI; | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | my $app = Langertha::Raider::CLI->new( | ||||||||||||||||||||
| 157 | # engine/model/api_key auto-detected from *_API_KEY env vars | ||||||||||||||||||||
| 158 | root => '/path/to/project', | ||||||||||||||||||||
| 159 | skill_sources => [ | ||||||||||||||||||||
| 160 | { type => 'file', path => 'CLAUDE.md' }, | ||||||||||||||||||||
| 161 | { type => 'claude', path => '.claude/skills' }, | ||||||||||||||||||||
| 162 | ], | ||||||||||||||||||||
| 163 | engine_options => { temperature => 0.2 }, | ||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | my $result = $app->run('Explore the repo and summarize it.'); | ||||||||||||||||||||
| 167 | print $result; | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =head1 DESCRIPTION | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | L<Langertha::Raider::CLI> wraps L<Langertha::Raider> with a standard toolbox for a | ||||||||||||||||||||
| 172 | working coding/system agent: | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =over | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =item * Local filesystem access, confined to L<Langertha::Raider::Application/root> | ||||||||||||||||||||
| 177 | (L<Langertha::Raider::FileTools>). | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =item * Full shell via L<MCP::Run::Bash> (the C<bash> tool), started in | ||||||||||||||||||||
| 180 | the root but not confined to it. | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =item * Web search + fetch via L<Net::Async::WebSearch> and | ||||||||||||||||||||
| 183 | L<Net::Async::HTTP> (L<Langertha::Raider::WebTools>). | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | =item * Optional Perl-native tools via L<Langertha::Raider::PerlTools>, | ||||||||||||||||||||
| 186 | and the Hall tools (L<Langertha::Raider::HallTools>) when a Hall started | ||||||||||||||||||||
| 187 | the raider. The tool list in the prompt is generated from the tools the | ||||||||||||||||||||
| 188 | engine is offered (L<Langertha::Raider::Application/mission>). | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =item * Persona and power packs via L<Langertha::Raider::Packs>. | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | =item * Per-engine cheap-model defaults and automatic engine selection from | ||||||||||||||||||||
| 193 | the first C<*_API_KEY> env var found (L<Langertha::Raider::EngineResolver>). | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | =item * Optional skill-loading from C<.claude/skills/*/SKILL.md>, | ||||||||||||||||||||
| 196 | C<AGENTS.md>, plain markdown directories, or any mix. | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | =item * Engine-attribute config via C<.raider.yml> in the root plus | ||||||||||||||||||||
| 199 | C<engine_options> merge. | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | =item * Live trace plugin (L<Langertha::Raider::Plugin::Trace>) and | ||||||||||||||||||||
| 202 | situation-injection plugin (L<Langertha::Raider::Plugin::Situation>). | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | =item * On-the-fly how-to-use-raider documentation generator | ||||||||||||||||||||
| 205 | (L<Langertha::Raider::Skill>). | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | =back | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | It is the command line's L<Langertha::Raider::Application>: all the | ||||||||||||||||||||
| 210 | attributes and methods documented there (C<root>, C<engine_name>, | ||||||||||||||||||||
| 211 | C<model>, C<mission>, C<packs>, C<raid_f>, C<run>, C<explain_config>, ...) | ||||||||||||||||||||
| 212 | apply here, and this class adds what belongs to the terminal -- the live | ||||||||||||||||||||
| 213 | L</trace>, the per-tool agent profiles of C<--claude> / C<--openai> and | ||||||||||||||||||||
| 214 | L</token_stats>. The command line itself is L<raider>. | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | =head2 default_model_for_engine | ||||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | my $model = Langertha::Raider::CLI::default_model_for_engine('openai'); # 'gpt-4o-mini' | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | A plain function, not a method: the model an engine uses when no model is | ||||||||||||||||||||
| 221 | set (L<Langertha::Raider::Application/model>) -- raider's cheap default | ||||||||||||||||||||
| 222 | for the engine, else the engine class's own default, C<undef> for an | ||||||||||||||||||||
| 223 | engine that needs an explicit model (C<openrouter>) or an unknown one. | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | =head2 trace | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | Emit live ANSI-colored progress output (iteration markers, tool calls, tool | ||||||||||||||||||||
| 228 | results) via L<Langertha::Raider::Plugin::Trace>. Defaults to on when STDOUT is a | ||||||||||||||||||||
| 229 | terminal. | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | =head2 trace_out | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | Filehandle the L</trace> is printed to. Defaults to C<STDOUT>. | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | =head2 source_labels | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | The command-line flags that set what | ||||||||||||||||||||
| 238 | L<Langertha::Raider::Application/explain_config> and the other reports | ||||||||||||||||||||
| 239 | name (L<Langertha::Raider::Application/source_label>): C<-e>, C<-m>, | ||||||||||||||||||||
| 240 | C<-k>, C<-o>, C<--pack>, C<--perl>, C<--bare>, C<-M>, ... | ||||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | =head2 persona_intro | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | The default persona's opening names the CLI. | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | =head2 persona_turn_end | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | The CLI loops back to the user. | ||||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | =head2 ignored_agent_files | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | Returns a list of per-tool agent files that exist in the working root but | ||||||||||||||||||||
| 253 | are NOT covered by the current L<Langertha::Raider::Application/skill_sources>. Intended to power the | ||||||||||||||||||||
| 254 | banner's "seeing AGENTS.md, ignoring" notice. | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | =head2 trace_plugin | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | Returns the loaded L<Langertha::Raider::Plugin::Trace> instance, or undef if trace | ||||||||||||||||||||
| 259 | is disabled. | ||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | =head2 token_stats | ||||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | Cumulative token counts for this session (hashref with C<prompt>, | ||||||||||||||||||||
| 264 | C<completion>, C<total>, C<calls>) — available when trace is enabled, | ||||||||||||||||||||
| 265 | nothing otherwise. | ||||||||||||||||||||
| 266 | |||||||||||||||||||||
| 267 | =head1 SEE ALSO | ||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | =over | ||||||||||||||||||||
| 270 | |||||||||||||||||||||
| 271 | =item * L<Langertha::Raider> | ||||||||||||||||||||
| 272 | |||||||||||||||||||||
| 273 | =item * L<Langertha::Raider::Application> | ||||||||||||||||||||
| 274 | |||||||||||||||||||||
| 275 | =item * L<Langertha::Raider::FileTools> | ||||||||||||||||||||
| 276 | |||||||||||||||||||||
| 277 | =item * L<MCP::Run::Bash> | ||||||||||||||||||||
| 278 | |||||||||||||||||||||
| 279 | =item * L<raider> — the CLI entry point | ||||||||||||||||||||
| 280 | |||||||||||||||||||||
| 281 | =back | ||||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | =head1 SUPPORT | ||||||||||||||||||||
| 284 | |||||||||||||||||||||
| 285 | =head2 Issues | ||||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||
| 288 | L<https://github.com/Getty/langertha-raider/issues>. | ||||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | =head2 IRC | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | =head1 CONTRIBUTING | ||||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||
| 297 | |||||||||||||||||||||
| 298 | =head1 AUTHOR | ||||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/> | ||||||||||||||||||||
| 301 | |||||||||||||||||||||
| 302 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 303 | |||||||||||||||||||||
| 304 | This software is copyright (c) 2026 by Torsten Raudssus. | ||||||||||||||||||||
| 305 | |||||||||||||||||||||
| 306 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 307 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 308 | |||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||