| 1 | package Claude::Agent::DryRun; | ||||||||||||||||||||||||||||
| 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(create_dry_run_hooks is_write_tool format_preview); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Claude::Agent::Hook::Matcher; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Claude::Agent::Hook::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub create_dry_run_hooks { | ||||||||||||||||||||||||||
|
Subroutine
create_dry_run_hooks: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 0 | my ($on_dry_run) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | unless ($ENV{CLAUDE_AGENT_DRY_RUN_NO_WARN}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | warn "=" x 72 . "\n"; | |||||||||||||||||||||||||||
| 18 | 0 | warn "[DRY-RUN MODE WARNING]\n"; | |||||||||||||||||||||||||||
| 19 | 0 | warn "Dry-run mode provides PREVIEW FUNCTIONALITY ONLY, not security.\n"; | |||||||||||||||||||||||||||
| 20 | 0 | warn "Bash command detection uses regex heuristics that can be BYPASSED via:\n"; | |||||||||||||||||||||||||||
| 21 | 0 | warn " - Command substitution: \$(echo rm) -rf\n"; | |||||||||||||||||||||||||||
| 22 | 0 | warn " - Variable expansion: \$cmd where cmd=rm\n"; | |||||||||||||||||||||||||||
| 23 | 0 | warn " - Aliases, scripts, or encoded commands\n"; | |||||||||||||||||||||||||||
| 24 | 0 | warn "For security-critical use, use tool whitelisting or sandboxing.\n"; | |||||||||||||||||||||||||||
| 25 | 0 | warn "Set CLAUDE_AGENT_DRY_RUN_NO_WARN=1 to suppress this warning.\n"; | |||||||||||||||||||||||||||
| 26 | 0 | warn "=" x 72 . "\n"; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | return { | ||||||||||||||||||||||||||||
| 30 | PreToolUse => [ | ||||||||||||||||||||||||||||
| 31 | Claude::Agent::Hook::Matcher->new( | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | hooks => [sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 33 | 0 | my ($input, $tool_use_id, $context) = @_; | |||||||||||||||||||||||||||
| 34 | 0 | my $tool_name = $input->{tool_name}; | |||||||||||||||||||||||||||
| 35 | 0 | my $tool_input = $input->{tool_input}; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if (is_write_tool($tool_name, $tool_input)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | my $preview = format_preview($tool_name, $tool_input); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($on_dry_run && ref($on_dry_run) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$on_dry_run and ref $on_dry_run eq "CODE"
MC/DC0%0/2
$on_dry_run and ref $on_dry_run eq "CODE"
$on_dry_run
ref $on_dry_run eq "CODE"
Truth table0%0/3
A and B
A= $on_dry_runB= ref $on_dry_run eq "CODE"
| |||||||||||||||||||||||||||||
| 41 | 0 | $on_dry_run->($tool_name, $tool_input, $preview); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | 0 | print "[DRY-RUN] $preview\n"; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | return Claude::Agent::Hook::Result->deny( | |||||||||||||||||||||||||||
| 48 | reason => "[DRY-RUN] $preview", | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return Claude::Agent::Hook::Result->proceed(); | |||||||||||||||||||||||||||
| 53 | 0 | }], | |||||||||||||||||||||||||||
| 54 | ), | ||||||||||||||||||||||||||||
| 55 | ], | ||||||||||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub is_write_tool { | ||||||||||||||||||||||||||
|
Subroutine
is_write_tool: not called CC=48 SCAR=77.6
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($tool_name, $tool_input) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return 1 if $tool_name eq 'Write'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return 1 if $tool_name eq 'Edit'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return 1 if $tool_name eq 'NotebookEdit'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($tool_name eq 'Bash') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $command = $tool_input->{command} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"command"} // ""
MC/DC0%0/1
$tool_input->{"command"} // ""
$tool_input->{"command"}
Truth table0%0/2
A
A= $tool_input->{"command"}
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (!defined $ENV{CLAUDE_AGENT_DRY_RUN_STRICT} || $ENV{CLAUDE_AGENT_DRY_RUN_STRICT}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"} or $ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"}
MC/DC0%0/2
not defined $ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"} or $ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"}
not defined $ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"}
$ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"}
Truth table0%0/3
not(A) or B
A= not defined $ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"}B= $ENV{"CLAUDE_AGENT_DRY_RUN_STRICT"}
| |||||||||||||||||||||||||||||
| 70 | my $safe_commands_env = $ENV{CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS} | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | // 'ls,cat,head,tail,grep,find,which,pwd,whoami,date,echo,wc,file,stat,type,uname,env,printenv'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"} // "ls,cat,head,tail,grep,find,which,pwd,whoami,date,echo,wc,file,stat,type,uname,env,printenv"
MC/DC0%0/1
$ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"} // "ls,cat,head,tail,grep,find,which,pwd,whoami,date,echo,wc,file,stat,type,uname,env,printenv"
$ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"}
Truth table0%0/2
A
A= $ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"}
| |||||||||||||||||||||||||||||
| 72 | 0 | my @raw_commands = split /,/, $safe_commands_env; | |||||||||||||||||||||||||||
| 73 | 0 | my @valid_commands = grep { /^[a-zA-Z0-9_-]+$/ } @raw_commands; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (@valid_commands < @raw_commands) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | my %valid_set = map { $_ => 1 } @valid_commands; | |||||||||||||||||||||||||||
| 76 | 0 | my @filtered = grep { !$valid_set{$_} } @raw_commands; | |||||||||||||||||||||||||||
| 77 | warn sprintf("[DRY-RUN CONFIG] Filtered %d invalid entries from CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS: %s\n", | ||||||||||||||||||||||||||||
| 78 | 0 | scalar(@filtered), join(', ', map { "'$_'" } @filtered)); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 0 | my %safe_commands = map { $_ => 1 } @valid_commands; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my ($first_cmd) = $command =~ /^\s*(\S+)/; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $first_cmd //= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$first_cmd //= ""
MC/DC0%0/1
$first_cmd //= ""
$first_cmd
Truth table0%0/2
A
A= $first_cmd
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($first_cmd =~ m{^/}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return 1 unless $first_cmd =~ m{^/(usr/)?s?bin/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | $first_cmd =~ s{^.*/}{}; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return 1 unless $safe_commands{$first_cmd}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return 1 if $command =~ /[>|]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | return 0; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | state $heuristic_warned = 0; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | if (!$heuristic_warned++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | warn "[DEPRECATION WARNING] Dry-run heuristic mode (CLAUDE_AGENT_DRY_RUN_STRICT=0) is " | |||||||||||||||||||||||||||
| 97 | . "deprecated and provides NO security guarantees. This fallback may be removed in " | ||||||||||||||||||||||||||||
| 98 | . "future versions. Use strict mode (default) for any security-sensitive applications.\n"; | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (!$ENV{CLAUDE_AGENT_DRY_RUN_QUIET}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | state $dry_run_warned = 0; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | warn "[DRY-RUN WARNING] Bash command detection is bypassable. " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | . "Set CLAUDE_AGENT_DRY_RUN_STRICT=1 for stricter protection.\n" | ||||||||||||||||||||||||||||
| 105 | unless $dry_run_warned++; | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | my @dangerous_cmds = qw(rm rmdir mv cp mkdir touch chmod chown dd truncate install ln patch rsync shred); | |||||||||||||||||||||||||||
| 108 | 0 | for my $cmd (@dangerous_cmds) { | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | return 1 if $command =~ /^\s*$cmd\b/ || $command =~ /[;|&]\s*$cmd\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$command =~ /^\s*$cmd\b/u or $command =~ /[;|&]\s*$cmd\b/u
MC/DC0%0/2
$command =~ /^\s*$cmd\b/u or $command =~ /[;|&]\s*$cmd\b/u
$command =~ /^\s*$cmd\b/u
$command =~ /[;|&]\s*$cmd\b/u
Truth table0%0/3
A or B
A= $command =~ /^\s*$cmd\b/uB= $command =~ /[;|&]\s*$cmd\b/u
| |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return 1 if $command =~ /^\s*wget\b/ || $command =~ /[;|&]\s*wget\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$command =~ /^\s*wget\b/u or $command =~ /[;|&]\s*wget\b/u
MC/DC0%0/2
$command =~ /^\s*wget\b/u or $command =~ /[;|&]\s*wget\b/u
$command =~ /^\s*wget\b/u
$command =~ /[;|&]\s*wget\b/u
Truth table0%0/3
A or B
A= $command =~ /^\s*wget\b/uB= $command =~ /[;|&]\s*wget\b/u
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return 1 if $command =~ /^\s*curl\s+.*-[oO]/ || $command =~ /[;|&]\s*curl\s+.*-[oO]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$command =~ /^\s*curl\s+.*-[oO]/u or $command =~ /[;|&]\s*curl\s+.*-[oO]/u
MC/DC0%0/2
$command =~ /^\s*curl\s+.*-[oO]/u or $command =~ /[;|&]\s*curl\s+.*-[oO]/u
$command =~ /^\s*curl\s+.*-[oO]/u
$command =~ /[;|&]\s*curl\s+.*-[oO]/u
Truth table0%0/3
A or B
A= $command =~ /^\s*curl\s+.*-[oO]/uB= $command =~ /[;|&]\s*curl\s+.*-[oO]/u
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return 1 if $command =~ /<<[<]?/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return 1 if $command =~ /\b(perl|python|ruby|sh|bash)\s+(-[ec]|-.*[ec])/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return 1 if $command =~ /\beval\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return 1 if $command =~ /\b(source|\.)\s+/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return 1 if $command =~ /\bxargs\b.*\b(rm|mv|cp)\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | return 1 if $command =~ /\b(git\s+(add|commit|push|reset|checkout|merge|rebase))\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return 1 if $command =~ /\b(npm\s+(install|uninstall|update|publish))\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | return 1 if $command =~ /\b(pip\s+(install|uninstall))\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return 1 if $command =~ /\b(cargo\s+(build|install|publish))\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return 1 if $command =~ /\b(make|cmake)\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return 1 if $command =~ /[>|]\s*\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return 1 if $command =~ /`[^`]*[>|]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return 1 if $command =~ /\$\([^)]*[>|]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | return 1 if $command =~ /\btee\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return 1 if $command =~ /\bsed\s+-i/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return 1 if $tool_input->{dangerouslyDisableSandbox}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (!$ENV{CLAUDE_AGENT_DRY_RUN_QUIET}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | my $safe_commands_env = $ENV{CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS} | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | // 'ls,cat,head,tail,grep,find,which,pwd,whoami,date,echo,wc,file,stat,type,uname,env,printenv'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"} // "ls,cat,head,tail,grep,find,which,pwd,whoami,date,echo,wc,file,stat,type,uname,env,printenv"
MC/DC0%0/1
$ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"} // "ls,cat,head,tail,grep,find,which,pwd,whoami,date,echo,wc,file,stat,type,uname,env,printenv"
$ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"}
Truth table0%0/2
A
A= $ENV{"CLAUDE_AGENT_DRY_RUN_SAFE_COMMANDS"}
| |||||||||||||||||||||||||||||
| 134 | 0 | my %safe_commands = map { $_ => 1 } split /,/, $safe_commands_env; | |||||||||||||||||||||||||||
| 135 | 0 | my ($first_cmd) = $command =~ /^\s*(\S+)/; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | $first_cmd //= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$first_cmd //= ""
MC/DC0%0/1
$first_cmd //= ""
$first_cmd
Truth table0%0/2
A
A= $first_cmd
| |||||||||||||||||||||||||||||
| 137 | 0 | $first_cmd =~ s{^.*/}{}; | |||||||||||||||||||||||||||
| 138 | 0 | ▶ | if (!$safe_commands{$first_cmd}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | warn "[DRY-RUN NOTICE] Command '$first_cmd' is not in safe list but allowed by heuristics. " | |||||||||||||||||||||||||||
| 140 | . "In strict mode (default), this would be blocked.\n"; | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($tool_name =~ /^mcp__/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $write_tools_env = $ENV{CLAUDE_AGENT_MCP_WRITE_TOOLS} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"CLAUDE_AGENT_MCP_WRITE_TOOLS"} // ""
MC/DC0%0/1
$ENV{"CLAUDE_AGENT_MCP_WRITE_TOOLS"} // ""
$ENV{"CLAUDE_AGENT_MCP_WRITE_TOOLS"}
Truth table0%0/2
A
A= $ENV{"CLAUDE_AGENT_MCP_WRITE_TOOLS"}
| |||||||||||||||||||||||||||||
| 147 | 0 | my %write_mcp_tools = map { $_ => 1 } split /,/, $write_tools_env; | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | return 1 if $write_mcp_tools{$tool_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | return 0; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | return 0; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub format_preview { | ||||||||||||||||||||||||||
|
Subroutine
format_preview: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 0 | my ($tool_name, $tool_input) = @_; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($tool_name eq 'Write') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $path = $tool_input->{file_path} // 'unknown'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"file_path"} // "unknown"
MC/DC0%0/1
$tool_input->{"file_path"} // "unknown"
$tool_input->{"file_path"}
Truth table0%0/2
A
A= $tool_input->{"file_path"}
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $content = $tool_input->{content} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"content"} // ""
MC/DC0%0/1
$tool_input->{"content"} // ""
$tool_input->{"content"}
Truth table0%0/2
A
A= $tool_input->{"content"}
| |||||||||||||||||||||||||||||
| 161 | 0 | my $lines = () = $content =~ /\n/g; | |||||||||||||||||||||||||||
| 162 | 0 | $lines++; | |||||||||||||||||||||||||||
| 163 | 0 | my $bytes = length($content); | |||||||||||||||||||||||||||
| 164 | 0 | return "Would write $bytes bytes ($lines lines) to: $path"; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ($tool_name eq 'Edit') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my $path = $tool_input->{file_path} // 'unknown'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"file_path"} // "unknown"
MC/DC0%0/1
$tool_input->{"file_path"} // "unknown"
$tool_input->{"file_path"}
Truth table0%0/2
A
A= $tool_input->{"file_path"}
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $old = $tool_input->{old_string} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"old_string"} // ""
MC/DC0%0/1
$tool_input->{"old_string"} // ""
$tool_input->{"old_string"}
Truth table0%0/2
A
A= $tool_input->{"old_string"}
| |||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $new = $tool_input->{new_string} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"new_string"} // ""
MC/DC0%0/1
$tool_input->{"new_string"} // ""
$tool_input->{"new_string"}
Truth table0%0/2
A
A= $tool_input->{"new_string"}
| |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $old_preview = length($old) > 50 ? substr($old, 0, 47) . '...' : $old; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | my $new_preview = length($new) > 50 ? substr($new, 0, 47) . '...' : $new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | $old_preview =~ s/\n/\\n/g; | |||||||||||||||||||||||||||
| 174 | 0 | $new_preview =~ s/\n/\\n/g; | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $replace_all = $tool_input->{replace_all} ? ' (all occurrences)' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | return "Would edit $path$replace_all: '$old_preview' -> '$new_preview'"; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if ($tool_name eq 'Bash') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $cmd = $tool_input->{command} // 'unknown'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"command"} // "unknown"
MC/DC0%0/1
$tool_input->{"command"} // "unknown"
$tool_input->{"command"}
Truth table0%0/2
A
A= $tool_input->{"command"}
| |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my $desc = $tool_input->{description} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"description"} // ""
MC/DC0%0/1
$tool_input->{"description"} // ""
$tool_input->{"description"}
Truth table0%0/2
A
A= $tool_input->{"description"}
| |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | my $cmd_preview = length($cmd) > 80 ? substr($cmd, 0, 77) . '...' : $cmd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | return $desc ? "Would run: $cmd_preview ($desc)" : "Would run: $cmd_preview"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($tool_name eq 'NotebookEdit') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $path = $tool_input->{notebook_path} // 'unknown'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"notebook_path"} // "unknown"
MC/DC0%0/1
$tool_input->{"notebook_path"} // "unknown"
$tool_input->{"notebook_path"}
Truth table0%0/2
A
A= $tool_input->{"notebook_path"}
| |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $mode = $tool_input->{edit_mode} // 'replace'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tool_input->{"edit_mode"} // "replace"
MC/DC0%0/1
$tool_input->{"edit_mode"} // "replace"
$tool_input->{"edit_mode"}
Truth table0%0/2
A
A= $tool_input->{"edit_mode"}
| |||||||||||||||||||||||||||||
| 189 | 0 | return "Would $mode cell in notebook: $path"; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | my $input_preview = join(', ', map { "$_=$tool_input->{$_}" } | |||||||||||||||||||||||||||
| 193 | 0 | grep { defined $tool_input->{$_} } sort keys %$tool_input); | |||||||||||||||||||||||||||
| 194 | 0 | ▶ | $input_preview = substr($input_preview, 0, 100) . '...' if length($input_preview) > 100; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 0 | return "Would execute $tool_name with: $input_preview"; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 8 | 1; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | __END__ | ||||||||||||||||||||||||||||