* Strip HTML tags and collapse whitespace. TestSavantAI was trained on * plain text, not markup — feeding it raw HTML massively reduces recall * because all the tag noise dilutes the injection signal. Callers that * already have plain text (page snapshot innerText, tool output strings) * get no-
(input: string)
| 266 | * get no-op behavior; callers with HTML get the markup stripped. |
| 267 | */ |
| 268 | function htmlToPlainText(input: string): string { |
| 269 | // Fast path: if no angle brackets, it's already plain text. |
| 270 | if (!input.includes('<')) return input; |
| 271 | return input |
| 272 | .replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi, ' ') // drop script/style bodies entirely |
| 273 | .replace(/<[^>]+>/g, ' ') // drop tags |
| 274 | .replace(/ /g, ' ') |
| 275 | .replace(/&/g, '&') |
| 276 | .replace(/</g, '<') |
| 277 | .replace(/>/g, '>') |
| 278 | .replace(/"/g, '"') |
| 279 | .replace(/\s+/g, ' ') |
| 280 | .trim(); |
| 281 | } |
| 282 | |
| 283 | export async function scanPageContent(text: string): Promise<LayerSignal> { |
| 284 | if (!text || text.length === 0) { |
no outgoing calls
no test coverage detected