bin/acme_claude_shell

filter: Statementstmt 75.4% 89 / 118 Branchbran 35.7% 10 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 86.6% 13 / 15 Podpod n/a totaltotal 65.5% 112 / 171 CC 6 SCAR 5.7
CC
6
Cov
65%
show_help
3.2
show_version
2.1
print_section
2.1
CRAP 1.8
« blib/lib/Acme/Claude/Shell/Hooks.pm ↑ Summary
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.01';
16  
17 2 ▶my %opts = (
Branch: 1 branch
BranchTrueFalseTotal
-t STDOUT ? : 0 2 2
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 'help|h' => \$opts{'help'},
33 2 ▶ 'version|v' => \$opts{'version'},
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("dry-run|n", \$opts{"dry-run"}, "unsafe|u", sub { $opts{"safe-mode"} = 0; } , "no-color", sub { $opts{"color"} = 0; } , "color!", \$opts{"color"}, "directory|d=s", \$opts{"dir"}, "command|c=s", \$opts{"command"}, "model|m=s", \$opts{"model"}, "help|h", \$opts{"help"}, "version|v", \$opts{"version"}) or pod2usage(2) 2 0 2
34 ) or pod2usage(2);
35  
36 2 ▶if ($opts{'help'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"help"}) 1 1 2
37 1 show_help();
38 1 exit 0;
39 }
40  
41 1 ▶if ($opts{'version'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"version"}) 1 0 1
42 1 show_version();
43 1 exit 0;
44 }
45  
46 # Check for piped input: acme_claude_shell -c - reads from stdin
47 0 my $command = $opts{'command'};
48 0 ▶if (defined $command && $command eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $command and $command eq "-") 0 0 0
Condition0%0/3
defined $command and $command eq "-"
!ll&&!rl&&r
000
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 "-"
ABresult
0X0
100
111
49 # Read command from stdin (for piping: echo "list files" | acme_claude_shell -c -)
50 0 local $/;
51 0 $command = <STDIN>;
52 0 ▶ chomp $command if defined $command;
Branch: 1 branch
BranchTrueFalseTotal
if defined $command 0 0 0
53 }
54  
55 # Single command mode or interactive
56 0 ▶if (defined $command && length $command) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $command and length $command) { } 0 0 0
Condition0%0/3
defined $command and length $command
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
57 run($command,
58 dry_run => $opts{'dry-run'},
59 safe_mode => $opts{'safe-mode'},
60 working_dir => $opts{'dir'},
61 colorful => $opts{'color'},
62 0 ▶ ($opts{'model'} ? (model => $opts{'model'}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$opts{'model'} ? : 0 0 0
63 );
64 } else {
65 shell(
66 dry_run => $opts{'dry-run'},
67 safe_mode => $opts{'safe-mode'},
68 working_dir => $opts{'dir'},
69 colorful => $opts{'color'},
70 0 ▶ ($opts{'model'} ? (model => $opts{'model'}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$opts{'model'} ? : 0 0 0
71 );
72 }
73  
74 1 ▶sub show_help {
Subroutine show_help: called CC=3 SCAR=11.6
75 1 my $c = $opts{'color'};
76  
77 1 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) { } 0 1 1
78 0 print colored(['bold', 'cyan'], "\n Acme::Claude::Shell"), " - AI-powered interactive shell\n\n";
79 } else {
80 1 print "\n Acme::Claude::Shell - AI-powered interactive shell\n\n";
81 }
82  
83 1 print_section("Usage", $c);
84 1 print " acme_claude_shell [options]\n";
85 1 print " acme_claude_shell -c \"find all large log files\"\n\n";
86  
87 1 print_section("Options", $c);
88 1 print_opt("-n, --dry-run", "Preview mode - show commands without executing", $c);
89 1 print_opt("-u, --unsafe", "Disable safety confirmations for dangerous commands", $c);
90 1 print_opt("--no-color", "Disable colored output", $c);
91 1 print_opt("-d, --directory DIR", "Set working directory (default: current)", $c);
92 1 print_opt("-c, --command CMD", "Run single command and exit (use '-' for stdin)", $c);
93 1 print_opt("-m, --model MODEL", "Claude model to use (e.g., claude-opus-4-5)", $c);
94 1 print_opt("-h, --help", "Show this help", $c);
95 1 print_opt("-v, --version", "Show version", $c);
96 1 print "\n";
97  
98 1 print_section("Examples", $c);
99 1 print " acme_claude_shell # Start interactive shell\n";
100 1 print " acme_claude_shell --dry-run # Preview mode\n";
101 1 print " acme_claude_shell -d /var/log # Start in specific directory\n";
102 1 print " acme_claude_shell -c \"list perl files\" # Single command\n";
103 1 print " acme_claude_shell -m claude-opus-4-5 # Use a specific model\n";
104 1 print " echo \"list files\" | acme_claude_shell -c - # Piped input\n\n";
105  
106 1 print_section("Interactive Commands", $c);
107 1 print " help Show help inside the shell\n";
108 1 print " history Show executed command history\n";
109 1 print " clear Clear the screen\n";
110 1 print " exit Exit the shell (or 'quit')\n\n";
111  
112 1 print_section("Example Session", $c);
113 1 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) { } 0 1 1
114 0 print colored(['green'], " acme_claude_shell> "), "find all perl files larger than 10k\n";
115 0 print colored(['cyan'], " Thinking...\n");
116 0 print " I'll find .pl and .pm files over 10KB:\n\n";
117 0 print colored(['cyan'], " i "), "Command: find . -name '*.p[lm]' -size +10k\n\n";
118 0 print " Action:\n";
119 0 print " [", colored(['cyan'], "a"), "] Approve and run\n";
120 0 print " [", colored(['cyan'], "d"), "] Dry-run (show only)\n";
121 0 print " [", colored(['cyan'], "e"), "] Edit command\n";
122 0 print " [", colored(['cyan'], "x"), "] Cancel\n";
123 0 print " > a\n\n";
124 0 print " ./lib/Acme/Claude/Shell.pm\n";
125 0 print " ./lib/Acme/Claude/Shell/Session.pm\n\n";
126 0 print colored(['green'], " Done\n\n");
127 0 print colored(['green'], " acme_claude_shell> "), "now show their sizes\n";
128 0 print " (Claude remembers the previous files...)\n\n";
129 } else {
130 1 print " acme_claude_shell> find all perl files larger than 10k\n";
131 1 print " Thinking...\n";
132 1 print " I'll find .pl and .pm files over 10KB:\n";
133 1 print " Command: find . -name '*.p[lm]' -size +10k\n";
134 1 print " > a\n";
135 1 print " ./lib/Acme/Claude/Shell.pm\n\n";
136 }
137  
138 1 print_section("SDK Features Demonstrated", $c);
139 1 print " This module showcases all Claude::Agent SDK features:\n";
140 1 print " - query() Single-shot commands (-c option)\n";
141 1 print " - session() Multi-turn context (interactive mode)\n";
142 1 print " - MCP tools Custom shell execution tools\n";
143 1 print " - Hooks Safety confirmation before running\n";
144 1 print " - Dry-run Preview without executing\n";
145 1 print " - IO::Async Non-blocking spinners\n";
146 1 print " - CLI utils Colored output, menus, spinners\n\n";
147 }
148  
149 1 ▶sub show_version {
Subroutine show_version: called CC=2 SCAR=7.6
150 1 my $c = $opts{'color'};
151 1 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) { } 0 1 1
152 0 print colored(['bold', 'cyan'], "Acme::Claude::Shell"), " version $VERSION\n";
153 } else {
154 1 print "Acme::Claude::Shell version $VERSION\n";
155 }
156 }
157  
158 6 ▶sub print_section {
Subroutine print_section: called CC=2 SCAR=7.6
159 6 my ($title, $color) = @_;
160 6 ▶ if ($color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color) { } 0 6 6
161 0 print colored(['bold', 'yellow'], "$title:\n");
162 } else {
163 6 print "$title:\n";
164 }
165 }
166  
167 8 ▶sub print_opt {
Subroutine print_opt: called CC=2 SCAR=7.6
168 8 my ($opt, $desc, $color) = @_;
169 8 ▶ if ($color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color) { } 0 8 8
170 0 printf " %-25s %s\n", colored(['green'], $opt), $desc;
171 } else {
172 8 printf " %-25s %s\n", $opt, $desc;
173 }
174 }
175  
176 __END__
177  
178 =head1 NAME
179  
180 acme_claude_shell - AI-powered interactive shell
181  
182 =head1 SYNOPSIS
183  
184 acme_claude_shell [options]
185 acme_claude_shell -c "find all large log files"
186  
187 =head1 OPTIONS
188  
189 =over 4
190  
191 =item B<-n, --dry-run>
192  
193 Preview mode - show commands without executing them.
194  
195 =item B<-u, --unsafe>
196  
197 Disable safety confirmations for dangerous commands.
198  
199 =item B<--no-color>
200  
201 Disable colored output.
202  
203 =item B<-d, --directory> DIR
204  
205 Set working directory (default: current directory).
206  
207 =item B<-c, --command> CMD
208  
209 Run a single command and exit instead of starting interactive mode.
210 Use '-' to read the command from stdin for piping.
211  
212 =item B<-m, --model> MODEL
213  
214 Specify the Claude model to use (e.g., claude-opus-4-5, claude-sonnet-4-5).
215  
216 =item B<-h, --help>
217  
218 Show help message.
219  
220 =item B<-v, --version>
221  
222 Show version.
223  
224 =back
225  
226 =head1 DESCRIPTION
227  
228 An AI-enhanced interactive shell where you describe what you want in
229 natural language, and Claude figures out the shell commands, explains
230 them, and executes them with your approval.
231  
232 =head1 AUTHOR
233  
234 LNATION, C<< <email at lnation.org> >>
235  
236 =head1 LICENSE
237  
238 This software is licensed under the Artistic License 2.0.
239  
240 =cut
« blib/lib/Acme/Claude/Shell/Hooks.pm ↑ Summary