* Formats a bash command by normalizing whitespace and escaping * @param {string} command - The raw bash command string * @returns {string} Formatted and escaped command string
(command)
| 162 | * @returns {string} Formatted and escaped command string |
| 163 | */ |
| 164 | function formatBashCommand(command) { |
| 165 | if (!command) return ""; |
| 166 | |
| 167 | // Convert multi-line commands to single line by replacing newlines with spaces |
| 168 | // and collapsing multiple spaces |
| 169 | let formatted = command |
| 170 | .replace(/\n/g, " ") // Replace newlines with spaces |
| 171 | .replace(/\r/g, " ") // Replace carriage returns with spaces |
| 172 | .replace(/\t/g, " ") // Replace tabs with spaces |
| 173 | .replace(/\s+/g, " ") // Collapse multiple spaces into one |
| 174 | .trim(); // Remove leading/trailing whitespace |
| 175 | |
| 176 | // Escape backticks to prevent markdown issues |
| 177 | formatted = formatted.replace(/`/g, "\\`"); |
| 178 | |
| 179 | // Truncate if too long (keep reasonable length for summary) |
| 180 | const maxLength = 300; |
| 181 | if (formatted.length > maxLength) { |
| 182 | formatted = formatted.substring(0, maxLength) + "..."; |
| 183 | } |
| 184 | |
| 185 | return formatted; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Truncates a string to a maximum length with ellipsis |
no outgoing calls
no test coverage detected