| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.020; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use FindBin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use lib "$FindBin::Bin/../lib"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Acme::Claude::Shell qw(shell run); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Term::ANSIColor qw(colored); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | my %opts = ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 'dry-run' => 0, | ||||||||||||||||||||||||||||
| 19 | 'safe-mode' => 1, | ||||||||||||||||||||||||||||
| 20 | 'color' => -t STDOUT ? 1 : 0, | ||||||||||||||||||||||||||||
| 21 | 'dir' => '.', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | GetOptions( | ||||||||||||||||||||||||||||
| 25 | 'dry-run|n' => \$opts{'dry-run'}, | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | 'unsafe|u' => sub { $opts{'safe-mode'} = 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | 'no-color' => sub { $opts{'color'} = 0 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 'color!' => \$opts{'color'}, | ||||||||||||||||||||||||||||
| 29 | 'directory|d=s' => \$opts{'dir'}, | ||||||||||||||||||||||||||||
| 30 | 'command|c=s' => \$opts{'command'}, | ||||||||||||||||||||||||||||
| 31 | 'model|m=s' => \$opts{'model'}, | ||||||||||||||||||||||||||||
| 32 | 'effort|e=s' => \$opts{'effort'}, | ||||||||||||||||||||||||||||
| 33 | 'verbose' => \$opts{'verbose'}, | ||||||||||||||||||||||||||||
| 34 | 'help|h' => \$opts{'help'}, | ||||||||||||||||||||||||||||
| 35 | 2 | ▶ | 'version|v' => \$opts{'version'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | ) or pod2usage(2); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | if ($opts{'help'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 1 | show_help(); | |||||||||||||||||||||||||||
| 40 | 1 | exit 0; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if ($opts{'version'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 1 | show_version(); | |||||||||||||||||||||||||||
| 45 | 1 | exit 0; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $command = $opts{'command'}; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | if (defined $command && $command eq '-') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $command and $command eq "-"
MC/DC0%0/2
defined $command and $command eq "-"
defined $command
$command eq "-"
Truth table0%0/3
A and B
A= defined $commandB= $command eq "-"
| |||||||||||||||||||||||||||||
| 50 | 0 | local $/; | |||||||||||||||||||||||||||
| 51 | 0 | $command = <STDIN>; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | chomp $command if defined $command; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (defined $command && length $command) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $command and length $command
MC/DC0%0/2
defined $command and length $command
defined $command
length $command
Truth table0%0/3
A and B
A= defined $commandB= length $command
| |||||||||||||||||||||||||||||
| 56 | run($command, | ||||||||||||||||||||||||||||
| 57 | dry_run => $opts{'dry-run'}, | ||||||||||||||||||||||||||||
| 58 | safe_mode => $opts{'safe-mode'}, | ||||||||||||||||||||||||||||
| 59 | working_dir => $opts{'dir'}, | ||||||||||||||||||||||||||||
| 60 | colorful => $opts{'color'}, | ||||||||||||||||||||||||||||
| 61 | ($opts{'model'} ? (model => $opts{'model'}) : ()), | ||||||||||||||||||||||||||||
| 62 | ($opts{'effort'} ? (effort => $opts{'effort'}) : ()), | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | verbose => $opts{'verbose'} ? 1 : 0, | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||
| 66 | shell( | ||||||||||||||||||||||||||||
| 67 | dry_run => $opts{'dry-run'}, | ||||||||||||||||||||||||||||
| 68 | safe_mode => $opts{'safe-mode'}, | ||||||||||||||||||||||||||||
| 69 | working_dir => $opts{'dir'}, | ||||||||||||||||||||||||||||
| 70 | colorful => $opts{'color'}, | ||||||||||||||||||||||||||||
| 71 | ($opts{'model'} ? (model => $opts{'model'}) : ()), | ||||||||||||||||||||||||||||
| 72 | ($opts{'effort'} ? (effort => $opts{'effort'}) : ()), | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | verbose => $opts{'verbose'} ? 1 : 0, | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | sub show_help { | ||||||||||||||||||||||||||
|
Subroutine
show_help: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||
| 78 | 1 | my $c = $opts{'color'}; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | if ($c) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | print colored(['bold', 'cyan'], "\n Acme::Claude::Shell"), " - AI-powered interactive shell\n\n"; | |||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||
| 83 | 1 | print "\n Acme::Claude::Shell - AI-powered interactive shell\n\n"; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | print_section("Usage", $c); | |||||||||||||||||||||||||||
| 87 | 1 | print " acme_claude_shell [options]\n"; | |||||||||||||||||||||||||||
| 88 | 1 | print " acme_claude_shell -c \"find all large log files\"\n\n"; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | print_section("Options", $c); | |||||||||||||||||||||||||||
| 91 | 1 | print_opt("-n, --dry-run", "Preview mode - show commands without executing", $c); | |||||||||||||||||||||||||||
| 92 | 1 | print_opt("-u, --unsafe", "Disable safety confirmations for dangerous commands", $c); | |||||||||||||||||||||||||||
| 93 | 1 | print_opt("--no-color", "Disable colored output", $c); | |||||||||||||||||||||||||||
| 94 | 1 | print_opt("-d, --directory DIR", "Set working directory (default: current)", $c); | |||||||||||||||||||||||||||
| 95 | 1 | print_opt("-c, --command CMD", "Run single command and exit (use '-' for stdin)", $c); | |||||||||||||||||||||||||||
| 96 | 1 | print_opt("-m, --model MODEL", "Claude model to use (e.g., opus, sonnet)", $c); | |||||||||||||||||||||||||||
| 97 | 1 | print_opt("-e, --effort LEVEL", "Effort level: low, medium, high, xhigh or max", $c); | |||||||||||||||||||||||||||
| 98 | 1 | print_opt("--verbose", "Log every tool call and notification", $c); | |||||||||||||||||||||||||||
| 99 | 1 | print_opt("-h, --help", "Show this help", $c); | |||||||||||||||||||||||||||
| 100 | 1 | print_opt("-v, --version", "Show version", $c); | |||||||||||||||||||||||||||
| 101 | 1 | print "\n"; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | print_section("Examples", $c); | |||||||||||||||||||||||||||
| 104 | 1 | print " acme_claude_shell # Start interactive shell\n"; | |||||||||||||||||||||||||||
| 105 | 1 | print " acme_claude_shell --dry-run # Preview mode\n"; | |||||||||||||||||||||||||||
| 106 | 1 | print " acme_claude_shell -d /var/log # Start in specific directory\n"; | |||||||||||||||||||||||||||
| 107 | 1 | print " acme_claude_shell -c \"list perl files\" # Single command\n"; | |||||||||||||||||||||||||||
| 108 | 1 | print " acme_claude_shell -m claude-opus-4-5 # Use a specific model\n"; | |||||||||||||||||||||||||||
| 109 | 1 | print " echo \"list files\" | acme_claude_shell -c - # Piped input\n\n"; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | print_section("Interactive Commands", $c); | |||||||||||||||||||||||||||
| 112 | 1 | print " help Show help inside the shell\n"; | |||||||||||||||||||||||||||
| 113 | 1 | print " history Show executed command history\n"; | |||||||||||||||||||||||||||
| 114 | 1 | print " clear Clear the screen\n"; | |||||||||||||||||||||||||||
| 115 | 1 | print " exit Exit the shell (or 'quit')\n\n"; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | print_section("Example Session", $c); | |||||||||||||||||||||||||||
| 118 | 1 | ▶ | if ($c) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | print colored(['green'], " acme_claude_shell> "), "find all perl files larger than 10k\n"; | |||||||||||||||||||||||||||
| 120 | 0 | print colored(['cyan'], " Thinking...\n"); | |||||||||||||||||||||||||||
| 121 | 0 | print " I'll find .pl and .pm files over 10KB:\n\n"; | |||||||||||||||||||||||||||
| 122 | 0 | print colored(['cyan'], " i "), "Command: find . -name '*.p[lm]' -size +10k\n\n"; | |||||||||||||||||||||||||||
| 123 | 0 | print " Action:\n"; | |||||||||||||||||||||||||||
| 124 | 0 | print " [", colored(['cyan'], "a"), "] Approve and run\n"; | |||||||||||||||||||||||||||
| 125 | 0 | print " [", colored(['cyan'], "d"), "] Dry-run (show only)\n"; | |||||||||||||||||||||||||||
| 126 | 0 | print " [", colored(['cyan'], "e"), "] Edit command\n"; | |||||||||||||||||||||||||||
| 127 | 0 | print " [", colored(['cyan'], "x"), "] Cancel\n"; | |||||||||||||||||||||||||||
| 128 | 0 | print " > a\n\n"; | |||||||||||||||||||||||||||
| 129 | 0 | print " ./lib/Acme/Claude/Shell.pm\n"; | |||||||||||||||||||||||||||
| 130 | 0 | print " ./lib/Acme/Claude/Shell/Session.pm\n\n"; | |||||||||||||||||||||||||||
| 131 | 0 | print colored(['green'], " Done\n\n"); | |||||||||||||||||||||||||||
| 132 | 0 | print colored(['green'], " acme_claude_shell> "), "now show their sizes\n"; | |||||||||||||||||||||||||||
| 133 | 0 | print " (Claude remembers the previous files...)\n\n"; | |||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||
| 135 | 1 | print " acme_claude_shell> find all perl files larger than 10k\n"; | |||||||||||||||||||||||||||
| 136 | 1 | print " Thinking...\n"; | |||||||||||||||||||||||||||
| 137 | 1 | print " I'll find .pl and .pm files over 10KB:\n"; | |||||||||||||||||||||||||||
| 138 | 1 | print " Command: find . -name '*.p[lm]' -size +10k\n"; | |||||||||||||||||||||||||||
| 139 | 1 | print " > a\n"; | |||||||||||||||||||||||||||
| 140 | 1 | print " ./lib/Acme/Claude/Shell.pm\n\n"; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | print_section("SDK Features Demonstrated", $c); | |||||||||||||||||||||||||||
| 144 | 1 | print " This module showcases all Claude::Agent SDK features:\n"; | |||||||||||||||||||||||||||
| 145 | 1 | print " - query() Single-shot commands (-c option)\n"; | |||||||||||||||||||||||||||
| 146 | 1 | print " - session() Multi-turn context (interactive mode)\n"; | |||||||||||||||||||||||||||
| 147 | 1 | print " - MCP tools Custom shell execution tools\n"; | |||||||||||||||||||||||||||
| 148 | 1 | print " - Hooks Safety confirmation before running\n"; | |||||||||||||||||||||||||||
| 149 | 1 | print " - Dry-run Preview without executing\n"; | |||||||||||||||||||||||||||
| 150 | 1 | print " - IO::Async Non-blocking spinners\n"; | |||||||||||||||||||||||||||
| 151 | 1 | print " - CLI utils Colored output, menus, spinners\n\n"; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1 | ▶ | sub show_version { | ||||||||||||||||||||||||||
|
Subroutine
show_version: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 155 | 1 | my $c = $opts{'color'}; | |||||||||||||||||||||||||||
| 156 | 1 | ▶ | if ($c) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | print colored(['bold', 'cyan'], "Acme::Claude::Shell"), " version $VERSION\n"; | |||||||||||||||||||||||||||
| 158 | } else { | ||||||||||||||||||||||||||||
| 159 | 1 | print "Acme::Claude::Shell version $VERSION\n"; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 6 | ▶ | sub print_section { | ||||||||||||||||||||||||||
|
Subroutine
print_section: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 164 | 6 | my ($title, $color) = @_; | |||||||||||||||||||||||||||
| 165 | 6 | ▶ | if ($color) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | print colored(['bold', 'yellow'], "$title:\n"); | |||||||||||||||||||||||||||
| 167 | } else { | ||||||||||||||||||||||||||||
| 168 | 6 | print "$title:\n"; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 10 | ▶ | sub print_opt { | ||||||||||||||||||||||||||
|
Subroutine
print_opt: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 173 | 10 | my ($opt, $desc, $color) = @_; | |||||||||||||||||||||||||||
| 174 | 10 | ▶ | if ($color) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | printf " %-25s %s\n", colored(['green'], $opt), $desc; | |||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||
| 177 | 10 | printf " %-25s %s\n", $opt, $desc; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||