Acme-Claude-Shell
view release on metacpan or search on metacpan
lib/Acme/Claude/Shell/Query.pm view on Meta::CPAN
package Acme::Claude::Shell::Query;
use 5.020;
use strict;
use warnings;
use Types::Standard qw(InstanceOf Str);
use Marlin
'loop!' => InstanceOf['IO::Async::Loop'],
'dry_run?' => sub { 0 },
'safe_mode?' => sub { 1 },
'working_dir?' => sub { '.' },
'colorful?' => sub { 1 },
'model?' => Str,
'_spinner==.';
use Claude::Agent qw(query create_sdk_mcp_server);
use Claude::Agent::Options;
use Claude::Agent::CLI qw(
start_spinner stop_spinner
header divider status
);
use Acme::Claude::Shell::Tools qw(shell_tools);
use Acme::Claude::Shell::Hooks qw(safety_hooks);
use Future::AsyncAwait;
# Fun spinner styles with matching colors
my @SPINNERS = (
{ spinner => 'moon', spinner_color => 'yellow' },
{ spinner => 'earth', spinner_color => 'cyan' },
{ spinner => 'clock', spinner_color => 'blue' },
{ spinner => 'dots', spinner_color => 'magenta' },
{ spinner => 'material', spinner_color => 'green' },
{ spinner => 'circle_half', spinner_color => 'cyan' },
{ spinner => 'color_circles', spinner_color => 'white' },
);
sub _random_spinner {
return %{ $SPINNERS[rand @SPINNERS] };
}
=head1 NAME
Acme::Claude::Shell::Query - Single-shot query mode for Acme::Claude::Shell
=head1 SYNOPSIS
use Acme::Claude::Shell::Query;
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $query = Acme::Claude::Shell::Query->new(
loop => $loop,
dry_run => 0,
safe_mode => 1,
);
my $result = $query->run("find all large log files")->get;
=head1 DESCRIPTION
Executes a single natural language command using Claude's query() function.
Does not maintain session context between calls - each run() is independent.
This is useful for scripting or when you want a one-shot command without
starting an interactive session.
Uses Claude::Agent SDK features:
=over 4
=item * C<query()> - Single-shot prompt execution
=item * SDK MCP tools - execute_command, read_file, list_directory, search_files, get_system_info, get_working_directory
=item * Hooks - PreToolUse (audit), PostToolUse (stats), PostToolUseFailure (errors), Stop (statistics), Notification (logging)
=item * CLI utilities - Spinners and colored output
=back
=head2 Attributes
=over 4
=item * C<loop> (required) - IO::Async::Loop instance
( run in 1.449 second using v1.01-cache-2.11-cpan-e1769b4cff6 )