blib/lib/Acme/Claude/Shell/Tools.pm

filter: Statementstmt 50.6% 184 / 363 Branchbran 36.1% 68 / 188 Conditioncond 25.2% 23 / 91 MC/DCmcdc 12.7% 7 / 55 Subroutinesub 66.6% 24 / 36 Podpod 0.0% 0 / 1 totaltotal 41.6% 306 / 734 CC 133 SCAR 51.8
CC
133
Cov
43%
_confirm_command
870.0
_format_perms
110.0
_execute_command
90.0
CRAP 177.3
↑ Summary blib/lib/Acme/Claude/Shell/Session.pm »
1 package Acme::Claude::Shell::Tools;
2  
3 8 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 our @EXPORT_OK = qw(shell_tools);
9  
10 8 ▶use Claude::Agent qw(tool);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Claude::Agent::CLI qw(menu status ask_yn prompt start_spinner stop_spinner);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use IO::Async::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use Cwd qw(abs_path getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Term::ANSIColor qw(colored);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 Acme::Claude::Shell::Tools - SDK MCP tool definitions for Acme::Claude::Shell
21  
22 =head1 SYNOPSIS
23  
24 use Acme::Claude::Shell::Tools qw(shell_tools);
25  
26 my $tools = shell_tools($session);
27  
28 =head1 DESCRIPTION
29  
30 Defines the SDK MCP tools that Claude can use to interact with the shell.
31 Each tool returns a Future for async execution.
32  
33 =head2 Tools
34  
35 =over 4
36  
37 =item * B<execute_command> - Run shell commands (with user confirmation)
38  
39 Executes arbitrary shell commands. The user is prompted to approve, edit,
40 dry-run, or cancel each command before execution. Dangerous commands
41 (rm -rf, sudo, mkfs, etc.) trigger additional warnings.
42  
43 =item * B<read_file> - Read file contents (safe, no confirmation)
44  
45 Read file contents directly without shell commands. Supports C<lines>
46 parameter to read first N lines, and C<tail> parameter to read last N lines.
47  
48 =item * B<list_directory> - List directory contents (safe, no confirmation)
49  
50 List directory contents with optional glob C<pattern> filtering,
51 C<long_format> for detailed output, and C<show_hidden> for dotfiles.
52  
53 =item * B<search_files> - Search for files by pattern (safe, no confirmation)
54  
55 Search recursively by filename C<pattern> (glob) or file C<content> (grep).
56 Supports C<max_depth> limit. Results capped at 100 matches.
57  
58 =item * B<get_system_info> - Get system information (safe, no confirmation)
59  
60 Returns OS, disk, memory, and process information. Use C<info_type> to
61 filter: 'all', 'os', 'disk', 'memory', or 'processes'.
62  
63 =item * B<get_working_directory> - Get current working directory (safe)
64  
65 Returns the current working directory path.
66  
67 =back
68  
69 =head2 Command Approval
70  
71 The C<execute_command> tool handles user approval directly (not via hooks)
72 to ensure synchronous confirmation before execution. Users can:
73  
74 =over 4
75  
76 =item * B<[a]> Approve and run the command
77  
78 =item * B<[d]> Dry-run (preview only, don't execute)
79  
80 =item * B<[e]> Edit the command before running
81  
82 =item * B<[x]> Cancel
83  
84 =back
85  
86 =head2 Dangerous Command Detection
87  
88 The following patterns trigger additional safety warnings:
89  
90 =over 4
91  
92 =item * C<rm -rf>, C<rm --recursive>, C<rm --force>
93  
94 =item * C<sudo> commands
95  
96 =item * C<mkfs>, C<dd of=>, device writes
97  
98 =item * C<chmod 777>, C<chown -R>
99  
100 =item * C<kill -9>, C<reboot>, C<shutdown>, C<halt>, C<poweroff>
101  
102 =item * Fork bombs, remote script piping (curl/wget | sh)
103  
104 =back
105  
106 =cut
107  
108 1 ▶sub shell_tools {
Subroutine shell_tools: called CC=1 SCAR=0.0
Pod undocumented
109 1 my ($session) = @_;
110  
111 return [
112 # execute_command tool - ALL shell operations go through this
113 # so the PreToolUse hook can confirm each command
114 tool(
115 'execute_command',
116 'Execute a shell command and return its output. Use this for ALL shell operations including listing files, reading files, etc. The user will be prompted to approve each command.',
117 {
118 type => 'object',
119 properties => {
120 command => {
121 type => 'string',
122 description => 'The shell command to execute (e.g., "ls -la", "cat file.txt", "find . -name *.pl")',
123 },
124 working_dir => {
125 type => 'string',
126 description => 'Directory to run command in (optional, defaults to current directory)',
127 },
128 },
129 required => ['command'],
130 },
131 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
132 0 my ($params, $loop) = @_;
133 0 return _execute_command($session, $params, $loop);
134 },
135 ),
136  
137 # get_working_directory tool - safe, no confirmation needed
138 tool(
139 'get_working_directory',
140 'Get the current working directory. This is safe and does not require user confirmation.',
141 {
142 type => 'object',
143 properties => {},
144 },
145 1 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
146 1 my ($params, $loop) = @_;
147 1 my $future = $loop->new_future;
148 1 $future->done(_mcp_result(getcwd()));
149 1 return $future;
150 },
151 ),
152  
153 # read_file tool - safe read operation, no confirmation needed
154 tool(
155 'read_file',
156 'Read the contents of a file. Safe operation - does not require user confirmation. Use this instead of execute_command for reading files.',
157 {
158 type => 'object',
159 properties => {
160 path => {
161 type => 'string',
162 description => 'Path to the file to read',
163 },
164 lines => {
165 type => 'integer',
166 description => 'Number of lines to read from the beginning (optional)',
167 },
168 tail => {
169 type => 'integer',
170 description => 'Number of lines to read from the end (optional)',
171 },
172 },
173 required => ['path'],
174 },
175 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
176 3 my ($params, $loop) = @_;
177 3 return _read_file_safe($session, $params, $loop);
178 },
179 ),
180  
181 # list_directory tool - safe read operation, no confirmation needed
182 tool(
183 'list_directory',
184 'List the contents of a directory. Safe operation - does not require user confirmation. Use this instead of execute_command for listing files.',
185 {
186 type => 'object',
187 properties => {
188 path => {
189 type => 'string',
190 description => 'Path to the directory to list (defaults to current directory)',
191 },
192 pattern => {
193 type => 'string',
194 description => 'Glob pattern to filter files (e.g., "*.pl", "*.txt")',
195 },
196 long_format => {
197 type => 'boolean',
198 description => 'Show detailed file information (size, date, permissions)',
199 },
200 show_hidden => {
201 type => 'boolean',
202 description => 'Include hidden files (starting with .)',
203 },
204 },
205 },
206 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
207 2 my ($params, $loop) = @_;
208 2 return _list_directory_safe($session, $params, $loop);
209 },
210 ),
211  
212 # search_files tool - safe search operation, no confirmation needed
213 tool(
214 'search_files',
215 'Search for files by name pattern or content. Safe operation - does not require user confirmation.',
216 {
217 type => 'object',
218 properties => {
219 pattern => {
220 type => 'string',
221 description => 'File name pattern to search for (e.g., "*.pm", "config*")',
222 },
223 content => {
224 type => 'string',
225 description => 'Text pattern to search for within files (grep)',
226 },
227 path => {
228 type => 'string',
229 description => 'Directory to search in (defaults to current directory)',
230 },
231 max_depth => {
232 type => 'integer',
233 description => 'Maximum directory depth to search',
234 },
235 },
236 },
237 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
238 2 my ($params, $loop) = @_;
239 2 return _search_files_safe($session, $params, $loop);
240 },
241 ),
242  
243 # get_system_info tool - safe system information, no confirmation needed
244 tool(
245 'get_system_info',
246 'Get system information including OS, disk space, and memory. Safe operation - does not require user confirmation.',
247 {
248 type => 'object',
249 properties => {
250 info_type => {
251 type => 'string',
252 description => 'Type of info: "all", "os", "disk", "memory", "processes" (defaults to "all")',
253 enum => ['all', 'os', 'disk', 'memory', 'processes'],
254 },
255 },
256 },
257 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
258 2 my ($params, $loop) = @_;
259 2 return _get_system_info($session, $params, $loop);
260 },
261 1 ),
262 ];
263 }
264  
265 0 ▶sub _execute_command {
Subroutine _execute_command: not called CC=9 SCAR=45.0
266 0 my ($session, $params, $loop) = @_;
267  
268 0 my $command = $params->{command};
269 0 ▶ my $dir = $params->{working_dir} // $session->working_dir;
Condition0%0/3
$params->{"working_dir"} // $session->working_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"working_dir"} // $session->working_dir
$params->{"working_dir"} $session->working_dir
Truth table0%0/3
A // B
A= $params->{"working_dir"}B= $session->working_dir
ABresult
1X1
011
000
270 0 my $colorful = $session->colorful;
271  
272 # Stop spinner before prompting for approval
273 0 ▶ if ($session->can('_spinner') && $session->_spinner) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session->can("_spinner") and $session->_spinner) 0 0 0
Condition0%0/3
$session->can("_spinner") and $session->_spinner
!ll&&!rl&&r
000
MC/DC0%0/2
$session->can("_spinner") and $session->_spinner
$session->can("_spinner") $session->_spinner
Truth table0%0/3
A and B
A= $session->can("_spinner")B= $session->_spinner
ABresult
0X0
100
111
274 0 stop_spinner($session->_spinner);
275 0 $session->_spinner(undef);
276 }
277  
278 # Prompt for approval before executing
279 0 my ($approved, $new_command) = _confirm_command($session, $command);
280  
281 0 ▶ unless ($approved) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($approved) 0 0 0
282 0 my $future = $loop->new_future;
283 0 $future->done(_mcp_result("User cancelled command", 1));
284 0 return $future;
285 }
286  
287 # Use potentially edited command
288 0 ▶ $command = $new_command if defined $new_command;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_command 0 0 0
289  
290 # Start execution spinner
291 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) 0 0 0
292 0 $session->_spinner(start_spinner("Executing...", $loop));
293 }
294  
295 # Record in history
296 0 push @{$session->_history}, {
297 time => _timestamp(),
298 command => $command,
299 status => 'running',
300 };
301  
302 0 my $future = $loop->new_future;
303 0 my $stdout = '';
304 0 my $stderr = '';
305  
306 my $process = IO::Async::Process->new(
307 command => [ '/bin/sh', '-c', $command ],
308 ($dir && -d $dir ? (setup => [ chdir => $dir ]) : ()),
309 stdout => {
310 into => \$stdout,
311 },
312 stderr => {
313 into => \$stderr,
314 },
315 0 ▶ on_finish => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
316 0 my ($self, $exitcode) = @_;
317 0 my $exit_status = $exitcode >> 8;
318  
319 0 ▶ if ($exit_status != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_status != 0) { } 0 0 0
320 0 $session->_history->[-1]{status} = "exit $exit_status";
321 0 ▶ my $output = $stderr || $stdout || "Command failed with exit code $exit_status";
Condition0%0/5
$stderr || $stdout || "Command failed with exit code $exit_status"
l!l
00
$stderr or $stdout
l!l&&r!l&&!r
000
MC/DC0%0/2
$stderr || $stdout || "Command failed with exit code $exit_status"
$stderr $stdout
Truth table0%0/3
A or B
A= $stderrB= $stdout
ABresult
1X1
011
000
322 0 $future->done(_mcp_result($output));
323 } else {
324 0 $session->_history->[-1]{status} = 'success';
325 0 ▶ $future->done(_mcp_result($stdout // ''));
Condition0%0/2
$stdout // ""
l!l
00
MC/DC0%0/1
$stdout // ""
$stdout
Truth table0%0/2
A
A= $stdout
Aresult
11
00
326 }
327 },
328 0 ▶ on_exception => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
329 0 my ($self, $exception, $errno, $exitcode) = @_;
330 0 $session->_history->[-1]{status} = 'error';
331 0 $future->done(_mcp_result("Error: $exception", 1));
332 },
333 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$dir && -d $dir ? : 0 0 0
Condition0%0/3
$dir and -d $dir
!ll&&!rl&&r
000
MC/DC0%0/2
$dir and -d $dir
$dir -d $dir
Truth table0%0/3
A and B
A= $dirB= -d $dir
ABresult
0X0
100
111
334  
335 0 $loop->add($process);
336  
337 0 return $future;
338 }
339  
340 # Helper to format tool results in MCP format
341 10 ▶sub _mcp_result {
Subroutine _mcp_result: called CC=2 SCAR=6.9
342 10 my ($text, $is_error) = @_;
343 return {
344 10 ▶ content => [{ type => 'text', text => $text }],
Branch: 1 branch
BranchTrueFalseTotal
$is_error ? : 1 9 10
345 is_error => $is_error ? 1 : 0,
346 };
347 }
348  
349 # Dangerous command patterns
350 8 my @DANGEROUS_PATTERNS = (
351 { pattern => qr/\brm\s+(-[rf]+|--recursive|--force)/i,
352 reason => 'Recursive or forced file deletion' },
353 { pattern => qr/\bsudo\b/,
354 reason => 'Superuser command' },
355 { pattern => qr/\bmkfs\b/,
356 reason => 'Filesystem formatting' },
357 { pattern => qr/\bdd\b.*\bof=/,
358 reason => 'Direct disk write' },
359 { pattern => qr/>\s*\/dev\//,
360 reason => 'Writing to device file' },
361 { pattern => qr/\bchmod\s+(-R\s+)?777\b/,
362 reason => 'World-writable permissions' },
363 { pattern => qr/\bchown\s+-R\b.*\//,
364 reason => 'Recursive ownership change' },
365 { pattern => qr/\bkill\s+-9\b/,
366 reason => 'Forceful process termination' },
367 { pattern => qr/\b(reboot|shutdown|halt|poweroff)\b/,
368 reason => 'System shutdown/reboot' },
369 { pattern => qr/\bformat\b/,
370 reason => 'Disk formatting' },
371 { pattern => qr/:\s*\(\s*\)\s*\{\s*:\s*\|\s*:\s*&\s*\}\s*;/,
372 reason => 'Fork bomb detected' },
373 { pattern => qr/\bwget\b.*\|\s*(ba)?sh/i,
374 reason => 'Piping remote script to shell' },
375 { pattern => qr/\bcurl\b.*\|\s*(ba)?sh/i,
376 reason => 'Piping remote script to shell' },
377 );
378  
379 0 ▶sub _check_dangerous {
Subroutine _check_dangerous: not called CC=3 SCAR=24.8
380 0 my ($command) = @_;
381 0 for my $check (@DANGEROUS_PATTERNS) {
382 0 ▶ if ($command =~ $check->{pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /$check->{"pattern"}/u) 0 0 0
383 0 return $check;
384 }
385 }
386 0 return undef;
387 }
388  
389 # Confirm command with user before executing
390 # Returns ($approved, $new_command) - $new_command is set if user edited it
391 0 ▶sub _confirm_command {
Subroutine _confirm_command: not called CC=29 SCAR=67.7
392 0 my ($session, $command) = @_;
393  
394 0 my $colorful = $session->colorful;
395  
396 # Check for dangerous patterns
397 0 my $danger = _check_dangerous($command);
398  
399 0 print "\n";
400  
401 0 ▶ if ($danger && $session->safe_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($danger and $session->safe_mode) 0 0 0
Condition0%0/3
$danger and $session->safe_mode
!ll&&!rl&&r
000
MC/DC0%0/2
$danger and $session->safe_mode
$danger $session->safe_mode
Truth table0%0/3
A and B
A= $dangerB= $session->safe_mode
ABresult
0X0
100
111
402 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
403 0 status('warning', "Potentially dangerous command detected!");
404 0 print colored(['yellow'], " Reason: $danger->{reason}\n");
405 } else {
406 0 print "WARNING: Potentially dangerous command!\n";
407 0 print " Reason: $danger->{reason}\n";
408 }
409 0 print "\n";
410 }
411  
412 # Show the command
413 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
414 0 status('info', "Command: $command");
415 } else {
416 0 print "Command: $command\n";
417 }
418  
419 # Show action menu
420 0 ▶ my $choice = menu("Action", [
Condition0%0/2
menu("Action", [{"key", "a", "label", "Approve and run"}, {"key", "d", "label", "Dry-run (preview only)"}, {"key", "e", "label", "Edit command"}, {"key", "x", "label", "Cancel"}]) // "x"
l!l
00
MC/DC0%0/1
menu("Action", [{"key", "a", "label", "Approve and run"}, {"key", "d", "label", "Dry-run (preview only)"}, {"key", "e", "label", "Edit command"}, {"key", "x", "label", "Cancel"}]) // "x"
menu("Action", [{"key", "a", "label", "Approve and run"}, {"key", "d", "label", "Dry-run (preview only)"}, {"key", "e", "label", "Edit command"}, {"key", "x", "label", "Cancel"}])
Truth table0%0/2
A
A= menu("Action", [{"key", "a", "label", "Approve and run"}, {"key", "d", "label", "Dry-run (preview only)"}, {"key", "e", "label", "Edit command"}, {"key", "x", "label", "Cancel"}])
Aresult
11
00
421 { key => 'a', label => 'Approve and run' },
422 { key => 'd', label => 'Dry-run (preview only)' },
423 { key => 'e', label => 'Edit command' },
424 { key => 'x', label => 'Cancel' },
425 ]) // 'x';
426  
427 0 ▶ if ($choice eq 'x') {
Branch: 3 branches
BranchTrueFalseTotal
if ($choice eq 'x') { } 0 0 0
elsif ($choice eq 'd') { } 0 0 0
elsif ($choice eq 'e') { } 0 0 0
428 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
429 0 status('warning', "Command cancelled");
430 } else {
431 0 print "Cancelled.\n";
432 }
433 0 return (0, undef);
434 }
435 elsif ($choice eq 'd') {
436 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
437 0 status('info', "[DRY-RUN] Would execute:");
438 0 print colored(['cyan'], " $command\n\n");
439 } else {
440 0 print "[DRY-RUN] Would execute: $command\n";
441 }
442 0 return (0, undef);
443 }
444 elsif ($choice eq 'e') {
445 0 my $new_cmd;
446 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
447 0 $new_cmd = prompt("Edit command:", $command);
448 } else {
449 0 print "Edit command [$command]: ";
450 0 $new_cmd = <STDIN>;
451 0 ▶ chomp $new_cmd if defined $new_cmd;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_cmd 0 0 0
452 0 ▶ $new_cmd = $command unless length($new_cmd // '');
Branch: 1 branch
BranchTrueFalseTotal
unless length($new_cmd // "") 0 0 0
Condition0%0/2
$new_cmd // ""
l!l
00
MC/DC0%0/1
$new_cmd // ""
$new_cmd
Truth table0%0/2
A
A= $new_cmd
Aresult
11
00
453 }
454  
455 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
456 0 status('info', "Modified command:");
457 0 print colored(['bold', 'white'], " $new_cmd\n\n");
458 } else {
459 0 print "Modified: $new_cmd\n";
460 }
461  
462 # For dangerous commands after editing, still require confirmation
463 0 ▶ if (_check_dangerous($new_cmd) && $session->safe_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (_check_dangerous($new_cmd) and $session->safe_mode) 0 0 0
Condition0%0/3
_check_dangerous($new_cmd) and $session->safe_mode
!ll&&!rl&&r
000
MC/DC0%0/2
_check_dangerous($new_cmd) and $session->safe_mode
_check_dangerous($new_cmd) $session->safe_mode
Truth table0%0/3
A and B
A= _check_dangerous($new_cmd)B= $session->safe_mode
ABresult
0X0
100
111
464 0 my $confirmed;
465 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
466 0 $confirmed = ask_yn("Are you SURE you want to run this command?", 'n');
467 } else {
468 0 print "Are you SURE? (y/N): ";
469 0 my $ans = <STDIN>;
470 0 ▶ chomp $ans if defined $ans;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ans 0 0 0
471 0 ▶ $confirmed = ($ans // '') =~ /^y/i;
Condition0%0/2
$ans // ""
l!l
00
MC/DC0%0/1
$ans // ""
$ans
Truth table0%0/2
A
A= $ans
Aresult
11
00
472 }
473 0 ▶ return (0, undef) unless $confirmed;
Branch: 1 branch
BranchTrueFalseTotal
unless $confirmed 0 0 0
474 }
475  
476 0 return (1, $new_cmd);
477 }
478  
479 # 'a' - Approve
480 # For dangerous commands, require extra confirmation
481 0 ▶ if ($danger && $session->safe_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($danger and $session->safe_mode) 0 0 0
Condition0%0/3
$danger and $session->safe_mode
!ll&&!rl&&r
000
MC/DC0%0/2
$danger and $session->safe_mode
$danger $session->safe_mode
Truth table0%0/3
A and B
A= $dangerB= $session->safe_mode
ABresult
0X0
100
111
482 0 my $confirmed;
483 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
484 0 $confirmed = ask_yn("Are you SURE you want to run this dangerous command?", 'n');
485 } else {
486 0 print "Are you SURE? (y/N): ";
487 0 my $ans = <STDIN>;
488 0 ▶ chomp $ans if defined $ans;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ans 0 0 0
489 0 ▶ $confirmed = ($ans // '') =~ /^y/i;
Condition0%0/2
$ans // ""
l!l
00
MC/DC0%0/1
$ans // ""
$ans
Truth table0%0/2
A
A= $ans
Aresult
11
00
490 }
491  
492 0 ▶ unless ($confirmed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($confirmed) 0 0 0
493 0 ▶ if ($colorful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colorful) { } 0 0 0
494 0 status('warning', "Command cancelled");
495 } else {
496 0 print "Cancelled.\n";
497 }
498 0 return (0, undef);
499 }
500 }
501  
502 0 return (1, undef);
503 }
504  
505 0 ▶sub _list_files {
Subroutine _list_files: not called CC=8 SCAR=42.8
506 0 my ($session, $params, $loop) = @_;
507  
508 0 ▶ my $path = $params->{path} // '.';
Condition0%0/2
$params->{"path"} // "."
l!l
00
MC/DC0%0/1
$params->{"path"} // "."
$params->{"path"}
Truth table0%0/2
A
A= $params->{"path"}
Aresult
11
00
509 0 ▶ my $pattern = $params->{pattern} // '';
Condition0%0/2
$params->{"pattern"} // ""
l!l
00
MC/DC0%0/1
$params->{"pattern"} // ""
$params->{"pattern"}
Truth table0%0/2
A
A= $params->{"pattern"}
Aresult
11
00
510 0 ▶ my $long = $params->{long_format} // 1;
Condition0%0/2
$params->{"long_format"} // 1
l!l
00
MC/DC0%0/1
$params->{"long_format"} // 1
$params->{"long_format"}
Truth table0%0/2
A
A= $params->{"long_format"}
Aresult
11
00
511 0 ▶ my $hidden = $params->{hidden} // 0;
Condition0%0/2
$params->{"hidden"} // 0
l!l
00
MC/DC0%0/1
$params->{"hidden"} // 0
$params->{"hidden"}
Truth table0%0/2
A
A= $params->{"hidden"}
Aresult
11
00
512  
513 # Build ls command
514 0 my @opts;
515 0 ▶ push @opts, '-l' if $long;
Branch: 1 branch
BranchTrueFalseTotal
if $long 0 0 0
516 0 ▶ push @opts, '-a' if $hidden;
Branch: 1 branch
BranchTrueFalseTotal
if $hidden 0 0 0
517  
518 0 ▶ my $target = $pattern ? "$path/$pattern" : $path;
Branch: 1 branch
BranchTrueFalseTotal
$pattern ? : 0 0 0
519 0 my $cmd = "ls @opts $target 2>/dev/null || ls @opts $path";
520  
521 0 return _execute_command($session, { command => $cmd }, $loop);
522 }
523  
524 0 ▶sub _read_file {
Subroutine _read_file: not called CC=3 SCAR=24.8
525 0 my ($session, $params, $loop) = @_;
526  
527 0 my $path = $params->{path};
528 0 my $lines = $params->{lines};
529 0 my $tail = $params->{tail};
530  
531 # Build read command
532 0 my $cmd;
533 0 ▶ if ($tail) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tail) { } 0 0 0
elsif ($lines) { } 0 0 0
534 0 $cmd = "tail -n $tail " . _shell_quote($path);
535 } elsif ($lines) {
536 0 $cmd = "head -n $lines " . _shell_quote($path);
537 } else {
538 0 $cmd = "cat " . _shell_quote($path);
539 }
540  
541 0 return _execute_command($session, { command => $cmd }, $loop);
542 }
543  
544 0 ▶sub _shell_quote {
Subroutine _shell_quote: not called CC=1 SCAR=6.9
545 0 my ($str) = @_;
546 0 $str =~ s/'/'\\''/g;
547 0 return "'$str'";
548 }
549  
550 0 ▶sub _timestamp {
Subroutine _timestamp: not called CC=1 SCAR=6.9
551 0 my @t = localtime;
552 0 return sprintf("%04d-%02d-%02d %02d:%02d:%02d",
553 $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]);
554 }
555  
556 # Safe read_file - no command approval needed
557 3 ▶sub _read_file_safe {
Subroutine _read_file_safe: called CC=14 SCAR=32.7
558 3 my ($session, $params, $loop) = @_;
559  
560 3 my $path = $params->{path};
561 3 my $lines = $params->{lines};
562 3 my $tail_lines = $params->{tail};
563  
564 3 my $future = $loop->new_future;
565  
566 # Resolve path
567 3 my $full_path = $path;
568 3 ▶ if ($path !~ m{^/}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[^/]u) 0 3 3
569 0 ▶ $full_path = File::Spec->catfile($session->working_dir // getcwd(), $path);
Condition0%0/3
$session->working_dir // getcwd()
l!l&&r!l&&!r
000
MC/DC0%0/2
$session->working_dir // getcwd()
$session->working_dir getcwd()
Truth table0%0/3
A // B
A= $session->working_dirB= getcwd()
ABresult
1X1
011
000
570 }
571  
572 3 ▶ unless (-e $full_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $full_path) 1 2 3
573 1 $future->done(_mcp_result("Error: File not found: $path", 1));
574 1 return $future;
575 }
576  
577 2 ▶ unless (-r $full_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $full_path) 0 2 2
578 0 $future->done(_mcp_result("Error: Permission denied: $path", 1));
579 0 return $future;
580 }
581  
582 2 ▶ if (-d $full_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $full_path) 0 2 2
583 0 $future->done(_mcp_result("Error: Path is a directory: $path", 1));
584 0 return $future;
585 }
586  
587 # Read file contents
588 2 my $content;
589 2 ▶ if (open my $fh, '<', $full_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<', $full_path) { } 2 0 2
590 2 ▶ if ($lines) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lines) { } 1 1 2
elsif ($tail_lines) { } 0 1 1
591 1 my @lines;
592 1 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 2 0 2
593 2 push @lines, $line;
594 2 ▶ last if @lines >= $lines;
Branch: 1 branch
BranchTrueFalseTotal
if @lines >= $lines 1 1 2
595 }
596 1 $content = join('', @lines);
597 }
598 elsif ($tail_lines) {
599 0 my @buffer;
600 0 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
601 0 push @buffer, $line;
602 0 ▶ shift @buffer if @buffer > $tail_lines;
Branch: 1 branch
BranchTrueFalseTotal
if @buffer > $tail_lines 0 0 0
603 }
604 0 $content = join('', @buffer);
605 }
606 else {
607 1 local $/;
608 1 $content = <$fh>;
609 }
610 2 close $fh;
611 2 ▶ $future->done(_mcp_result($content // ''));
Condition50%1/2
$content // ""
l!l
20
MC/DC0%0/1
$content // ""
$content
Truth table50%1/2
A
A= $content
Aresult
11
00
612 }
613 else {
614 0 $future->done(_mcp_result("Error reading file: $!", 1));
615 }
616  
617 2 return $future;
618 }
619  
620 # Safe list_directory - no command approval needed
621 2 ▶sub _list_directory_safe {
Subroutine _list_directory_safe: called CC=13 SCAR=35.8
622 2 my ($session, $params, $loop) = @_;
623  
624 2 ▶ my $path = $params->{path} // '.';
Condition50%1/2
$params->{"path"} // "."
l!l
20
MC/DC0%0/1
$params->{"path"} // "."
$params->{"path"}
Truth table50%1/2
A
A= $params->{"path"}
Aresult
11
00
625 2 my $pattern = $params->{pattern};
626 2 my $long_format = $params->{long_format};
627 2 my $show_hidden = $params->{show_hidden};
628  
629 2 my $future = $loop->new_future;
630  
631 # Resolve path
632 2 my $full_path = $path;
633 2 ▶ if ($path !~ m{^/}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[^/]u) 0 2 2
634 0 ▶ $full_path = File::Spec->catfile($session->working_dir // getcwd(), $path);
Condition0%0/3
$session->working_dir // getcwd()
l!l&&r!l&&!r
000
MC/DC0%0/2
$session->working_dir // getcwd()
$session->working_dir getcwd()
Truth table0%0/3
A // B
A= $session->working_dirB= getcwd()
ABresult
1X1
011
000
635 }
636  
637 2 ▶ unless (-d $full_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $full_path) 0 2 2
638 0 $future->done(_mcp_result("Error: Not a directory: $path", 1));
639 0 return $future;
640 }
641  
642 2 ▶ unless (opendir my $dh, $full_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $full_path) { } 2 0 2
643 0 $future->done(_mcp_result("Error: Cannot open directory: $!", 1));
644 0 return $future;
645 }
646 else {
647 2 my @entries = readdir($dh);
648 2 closedir $dh;
649  
650 # Filter hidden files
651 2 ▶ unless ($show_hidden) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_hidden) { } 0 2 2
652 2 @entries = grep { !/^\./ } @entries;
653 }
654 else {
655 # Remove . and .. but keep other hidden files
656 0 ▶ @entries = grep { $_ ne '.' && $_ ne '..' } @entries;
Condition0%0/3
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table0%0/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
657 }
658  
659 # Apply pattern filter
660 2 ▶ if ($pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern) 1 1 2
661 1 my $regex = _glob_to_regex($pattern);
662 1 @entries = grep { /$regex/ } @entries;
663 }
664  
665 # Sort entries
666 2 @entries = sort @entries;
667  
668 2 my @output;
669 2 ▶ if ($long_format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($long_format) { } 0 2 2
670 0 for my $entry (@entries) {
671 0 my $entry_path = File::Spec->catfile($full_path, $entry);
672 0 my @stat = stat($entry_path);
673 0 ▶ if (@stat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stat) { } 0 0 0
674 0 my $size = $stat[7];
675 0 my $mtime = $stat[9];
676 0 my $mode = $stat[2];
677 0 ▶ my $type = -d $entry_path ? 'd' : '-';
Branch: 1 branch
BranchTrueFalseTotal
-d $entry_path ? : 0 0 0
678 0 my $perms = _format_perms($mode);
679 0 my $date = _format_date($mtime);
680 0 push @output, sprintf("%s%s %8d %s %s",
681 $type, $perms, $size, $date, $entry);
682 }
683 else {
684 0 push @output, $entry;
685 }
686 }
687 }
688 else {
689 2 @output = @entries;
690 }
691  
692 2 $future->done(_mcp_result(join("\n", @output)));
693 }
694  
695 2 return $future;
696 }
697  
698 # Safe search_files - no command approval needed
699 2 ▶sub _search_files_safe {
Subroutine _search_files_safe: called CC=10 SCAR=26.6
700 2 my ($session, $params, $loop) = @_;
701  
702 2 my $pattern = $params->{pattern};
703 2 my $content = $params->{content};
704 2 ▶ my $path = $params->{path} // '.';
Condition50%1/2
$params->{"path"} // "."
l!l
20
MC/DC0%0/1
$params->{"path"} // "."
$params->{"path"}
Truth table50%1/2
A
A= $params->{"path"}
Aresult
11
00
705 2 my $max_depth = $params->{max_depth};
706  
707 2 my $future = $loop->new_future;
708  
709 2 ▶ unless ($pattern || $content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pattern or $content) 0 2 2
Condition66%2/3
$pattern or $content
l!l&&r!l&&!r
110
MC/DC0%0/2
$pattern or $content
$pattern $content
Truth table66%2/3
A or B
A= $patternB= $content
ABresult
1X1
011
000
710 0 $future->done(_mcp_result("Error: Must specify 'pattern' (filename) or 'content' (text search)", 1));
711 0 return $future;
712 }
713  
714 # Resolve path
715 2 my $full_path = $path;
716 2 ▶ if ($path !~ m{^/}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[^/]u) 0 2 2
717 0 ▶ $full_path = File::Spec->catfile($session->working_dir // getcwd(), $path);
Condition0%0/3
$session->working_dir // getcwd()
l!l&&r!l&&!r
000
MC/DC0%0/2
$session->working_dir // getcwd()
$session->working_dir getcwd()
Truth table0%0/3
A // B
A= $session->working_dirB= getcwd()
ABresult
1X1
011
000
718 }
719  
720 2 ▶ unless (-d $full_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $full_path) 0 2 2
721 0 $future->done(_mcp_result("Error: Not a directory: $path", 1));
722 0 return $future;
723 }
724  
725 2 my @results;
726 2 ▶ my $regex = $pattern ? _glob_to_regex($pattern) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$pattern ? : 1 1 2
727 2 ▶ my $content_re = $content ? qr/\Q$content\E/i : undef;
Branch: 1 branch
BranchTrueFalseTotal
$content ? : 1 1 2
728  
729 2 _search_recursive($full_path, $full_path, $regex, $content_re, $max_depth, 0, \@results);
730  
731 2 ▶ if (@results) {
Branch: 1 branch
BranchTrueFalseTotal
if (@results) { } 2 0 2
732 2 $future->done(_mcp_result(join("\n", @results)));
733 }
734 else {
735 0 $future->done(_mcp_result("No matches found"));
736 }
737  
738 2 return $future;
739 }
740  
741 4 ▶sub _search_recursive {
Subroutine _search_recursive: called CC=19 SCAR=30.1
742 4 my ($base, $dir, $name_re, $content_re, $max_depth, $depth, $results) = @_;
743  
744 4 ▶ return if defined $max_depth && $depth > $max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max_depth and $depth > $max_depth 0 4 4
Condition33%1/3
defined $max_depth and $depth > $max_depth
!ll&&!rl&&r
400
MC/DC0%0/2
defined $max_depth and $depth > $max_depth
defined $max_depth $depth > $max_depth
Truth table33%1/3
A and B
A= defined $max_depthB= $depth > $max_depth
ABresult
0X0
100
111
745 4 ▶ return if @$results >= 100; # Limit results
Branch: 1 branch
BranchTrueFalseTotal
if @$results >= 100 0 4 4
746  
747 4 ▶ opendir my $dh, $dir or return;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or return 4 0 4
748 4 my @entries = readdir($dh);
749 4 closedir $dh;
750  
751 4 for my $entry (sort @entries) {
752 16 ▶ next if $entry eq '.' || $entry eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "." or $entry eq ".." 8 8 16
Condition100%3/3
$entry eq "." or $entry eq ".."
l!l&&r!l&&!r
448
MC/DC100%2/2
$entry eq "." or $entry eq ".."
$entry eq "." $entry eq ".."
Truth table100%3/3
A or B
A= $entry eq "."B= $entry eq ".."
ABresult
1X1
011
000
753  
754 8 my $path = File::Spec->catfile($dir, $entry);
755 8 my $rel_path = File::Spec->abs2rel($path, $base);
756  
757 8 ▶ if (-d $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $path) { } 2 6 8
elsif (-f $path) { } 6 0 6
758 2 _search_recursive($base, $path, $name_re, $content_re, $max_depth, $depth + 1, $results);
759 }
760 elsif (-f $path) {
761 # Check filename pattern
762 6 ▶ my $name_match = !$name_re || $entry =~ $name_re;
Condition100%3/3
!$name_re || $entry =~ /$name_re/u
l!l&&r!l&&!r
321
MC/DC100%2/2
!$name_re || $entry =~ /$name_re/u
!$name_re $entry =~ /$name_re/u
Truth table100%3/3
not(A) || B
A= !$name_reB= $entry =~ /$name_re/u
ABresult
1X1
011
000
763  
764 6 ▶ if ($name_match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name_match) 5 1 6
765 5 ▶ if ($content_re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_re) { } 3 2 5
766 # Search file content
767 3 ▶ if (open my $fh, '<', $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $path) 3 0 3
768 3 my $line_num = 0;
769 3 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 9 3 12
770 9 $line_num++;
771 9 ▶ if ($line =~ $content_re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$content_re/u) 1 8 9
772 1 chomp $line;
773 1 ▶ $line = substr($line, 0, 100) . '...' if length($line) > 100;
Branch: 1 branch
BranchTrueFalseTotal
if length $line > 100 0 1 1
774 1 push @$results, "$rel_path:$line_num: $line";
775 1 ▶ last if @$results >= 100;
Branch: 1 branch
BranchTrueFalseTotal
if @$results >= 100 0 1 1
776 }
777 }
778 3 close $fh;
779 }
780 }
781 else {
782 2 push @$results, $rel_path;
783 }
784 }
785 }
786  
787 8 ▶ last if @$results >= 100;
Branch: 1 branch
BranchTrueFalseTotal
if @$results >= 100 0 8 8
788 }
789 }
790  
791 # Get system info - no command approval needed
792 2 ▶sub _get_system_info {
Subroutine _get_system_info: called CC=20 SCAR=31.2
793 2 my ($session, $params, $loop) = @_;
794  
795 2 ▶ my $info_type = $params->{info_type} // 'all';
Condition50%1/2
$params->{"info_type"} // "all"
l!l
20
MC/DC0%0/1
$params->{"info_type"} // "all"
$params->{"info_type"}
Truth table50%1/2
A
A= $params->{"info_type"}
Aresult
11
00
796 2 my $future = $loop->new_future;
797  
798 2 my @info;
799  
800 2 ▶ if ($info_type eq 'all' || $info_type eq 'os') {
Branch: 1 branch
BranchTrueFalseTotal
if ($info_type eq "all" or $info_type eq "os") 2 0 2
Condition66%2/3
$info_type eq "all" or $info_type eq "os"
l!l&&r!l&&!r
110
MC/DC0%0/2
$info_type eq "all" or $info_type eq "os"
$info_type eq "all" $info_type eq "os"
Truth table66%2/3
A or B
A= $info_type eq "all"B= $info_type eq "os"
ABresult
1X1
011
000
801 2 push @info, "=== OS Information ===";
802 2 push @info, "System: $^O";
803 2 push @info, "Perl: $^V";
804 2 ▶ if (open my $fh, '<', '/etc/os-release') {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", "/etc/os-release") 2 0 2
805 2 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 26 2 28
806 26 chomp;
807 26 ▶ push @info, $_ if /^(NAME|VERSION|PRETTY_NAME)=/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(NAME|VERSION|PRETTY_NAME)=/u 6 20 26
808 }
809 2 close $fh;
810 }
811 2 push @info, "";
812 }
813  
814 2 ▶ if ($info_type eq 'all' || $info_type eq 'disk') {
Branch: 1 branch
BranchTrueFalseTotal
if ($info_type eq "all" or $info_type eq "disk") 1 1 2
Condition66%2/3
$info_type eq "all" or $info_type eq "disk"
l!l&&r!l&&!r
101
MC/DC50%1/2
$info_type eq "all" or $info_type eq "disk"
$info_type eq "all" $info_type eq "disk"
Truth table66%2/3
A or B
A= $info_type eq "all"B= $info_type eq "disk"
ABresult
1X1
011
000
815 1 push @info, "=== Disk Usage ===";
816 1 ▶ my $cwd = $session->working_dir // getcwd();
Condition33%1/3
$session->working_dir // getcwd()
l!l&&r!l&&!r
100
MC/DC0%0/2
$session->working_dir // getcwd()
$session->working_dir getcwd()
Truth table33%1/3
A // B
A= $session->working_dirB= getcwd()
ABresult
1X1
011
000
817 # Use POSIX statvfs if available, otherwise report working directory
818 1 push @info, "Working directory: $cwd";
819 1 push @info, "";
820 }
821  
822 2 ▶ if ($info_type eq 'all' || $info_type eq 'memory') {
Branch: 1 branch
BranchTrueFalseTotal
if ($info_type eq "all" or $info_type eq "memory") 1 1 2
Condition66%2/3
$info_type eq "all" or $info_type eq "memory"
l!l&&r!l&&!r
101
MC/DC50%1/2
$info_type eq "all" or $info_type eq "memory"
$info_type eq "all" $info_type eq "memory"
Truth table66%2/3
A or B
A= $info_type eq "all"B= $info_type eq "memory"
ABresult
1X1
011
000
823 1 push @info, "=== Memory ===";
824 1 ▶ if ($^O eq 'darwin') {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'darwin') { } 0 1 1
elsif (-r '/proc/meminfo') { } 1 0 1
825 0 push @info, "(Memory info requires system command on macOS)";
826 }
827 elsif (-r '/proc/meminfo') {
828 1 ▶ if (open my $fh, '<', '/proc/meminfo') {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", "/proc/meminfo") 1 0 1
829 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 54 1 55
830 54 ▶ push @info, $_ if /^(MemTotal|MemFree|MemAvailable|Buffers|Cached):/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(MemTotal|MemFree|MemAvailable|Buffers|Cached):/u 5 49 54
831 }
832 1 close $fh;
833 }
834 }
835 1 push @info, "";
836 }
837  
838 2 ▶ if ($info_type eq 'all' || $info_type eq 'processes') {
Branch: 1 branch
BranchTrueFalseTotal
if ($info_type eq "all" or $info_type eq "processes") 1 1 2
Condition66%2/3
$info_type eq "all" or $info_type eq "processes"
l!l&&r!l&&!r
101
MC/DC50%1/2
$info_type eq "all" or $info_type eq "processes"
$info_type eq "all" $info_type eq "processes"
Truth table66%2/3
A or B
A= $info_type eq "all"B= $info_type eq "processes"
ABresult
1X1
011
000
839 1 push @info, "=== Current Process ===";
840 1 push @info, "PID: $$";
841 1 ▶ push @info, "User: " . (getpwuid($<) // $<);
Condition33%1/3
getpwuid $< // $<
l!l&&r!l&&!r
100
MC/DC0%0/2
getpwuid $< // $<
getpwuid $< $<
Truth table33%1/3
A // B
A= getpwuid $<B= $<
ABresult
1X1
011
000
842 1 push @info, "";
843 }
844  
845 2 $future->done(_mcp_result(join("\n", @info)));
846 2 return $future;
847 }
848  
849 # Helper: convert glob pattern to regex
850 2 ▶sub _glob_to_regex {
Subroutine _glob_to_regex: called CC=1 SCAR=0.0
851 2 my ($glob) = @_;
852 2 $glob =~ s/\./\\./g;
853 2 $glob =~ s/\*/.*/g;
854 2 $glob =~ s/\?/./g;
855 2 return qr/^$glob$/i;
856 }
857  
858 # Helper: format file permissions
859 0 ▶sub _format_perms {
Subroutine _format_perms: not called CC=10 SCAR=47.0
860 0 my ($mode) = @_;
861 0 my $perms = '';
862 0 ▶ $perms .= ($mode & 0400) ? 'r' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 256 ? : 0 0 0
863 0 ▶ $perms .= ($mode & 0200) ? 'w' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 128 ? : 0 0 0
864 0 ▶ $perms .= ($mode & 0100) ? 'x' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 64 ? : 0 0 0
865 0 ▶ $perms .= ($mode & 0040) ? 'r' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 32 ? : 0 0 0
866 0 ▶ $perms .= ($mode & 0020) ? 'w' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 16 ? : 0 0 0
867 0 ▶ $perms .= ($mode & 0010) ? 'x' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 8 ? : 0 0 0
868 0 ▶ $perms .= ($mode & 0004) ? 'r' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 4 ? : 0 0 0
869 0 ▶ $perms .= ($mode & 0002) ? 'w' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 2 ? : 0 0 0
870 0 ▶ $perms .= ($mode & 0001) ? 'x' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$mode & 1 ? : 0 0 0
871 0 return $perms;
872 }
873  
874 # Helper: format date for ls output
875 0 ▶sub _format_date {
Subroutine _format_date: not called CC=1 SCAR=6.9
876 0 my ($time) = @_;
877 0 my @t = localtime($time);
878 0 return sprintf("%s %2d %02d:%02d",
879 (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$t[4]],
880 $t[3], $t[2], $t[1]);
881 }
882  
883 =head1 AUTHOR
884  
885 LNATION, C<< <email at lnation.org> >>
886  
887 =head1 LICENSE AND COPYRIGHT
888  
889 This software is Copyright (c) 2026 by LNATION.
890  
891 This is free software, licensed under:
892  
893 The Artistic License 2.0 (GPL Compatible)
894  
895 =cut
896  
897 8 1;
↑ Summary blib/lib/Acme/Claude/Shell/Session.pm »