* Strip ALL ANSI escape sequences and C1 control bytes from a string. * Preserves printable text and ordinary whitespace (tab, newline).
(input)
| 217 | * Preserves printable text and ordinary whitespace (tab, newline). |
| 218 | */ |
| 219 | function stripAnsi(input) { |
| 220 | if (typeof input !== 'string' || input.length === 0) return input; |
| 221 | let out = input; |
| 222 | for (const re of ANSI_RE) out = out.replace(re, ''); |
| 223 | // Also strip raw NUL and other non-tab/newline C0 controls |
| 224 | out = out.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ''); |
| 225 | return out; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Sanitize a tool result string before adding it to model context: |
no outgoing calls
no test coverage detected