* Strips full-line comments from a command. * This handles cases where Claude adds comments in bash commands, e.g.: * "# Check the logs directory\nls /home/user/logs" * Should be stripped to: "ls /home/user/logs" * * Only strips full-line comments (lines where the entire line is a comment),
(command: string)
| 506 | * not inline comments that appear after a command on the same line. |
| 507 | */ |
| 508 | function stripCommentLines(command: string): string { |
| 509 | const lines = command.split('\n') |
| 510 | const nonCommentLines = lines.filter(line => { |
| 511 | const trimmed = line.trim() |
| 512 | // Keep lines that are not empty and don't start with # |
| 513 | return trimmed !== '' && !trimmed.startsWith('#') |
| 514 | }) |
| 515 | |
| 516 | // If all lines were comments/empty, return original |
| 517 | if (nonCommentLines.length === 0) { |
| 518 | return command |
| 519 | } |
| 520 | |
| 521 | return nonCommentLines.join('\n') |
| 522 | } |
| 523 | |
| 524 | export function stripSafeWrappers(command: string): string { |
| 525 | // SECURITY: Use [ \t]+ not \s+ — \s matches \n/\r which are command |
no outgoing calls
no test coverage detected