(tool: string, error: string)
| 38 | * and hex; lowercase; collapse whitespace; cap length. Keyed by the tool name. |
| 39 | */ |
| 40 | export function normalizeFailureSignature(tool: string, error: string): string { |
| 41 | let s = (error || '').toLowerCase(); |
| 42 | s = s.replace(/[\w./-]*\/[\w./-]+/g, '<path>'); // unix-ish paths (with a slash) |
| 43 | s = s.replace(/[a-z]:\\[\w\\./-]+/g, '<path>'); // windows paths |
| 44 | s = s.replace(/\b[\w-]+\.[a-z][a-z0-9]{0,5}\b/g, '<path>'); // bare filenames (x.ts, y.py) |
| 45 | s = s.replace(/:\d+(:\d+)?/g, ''); // :line:col |
| 46 | s = s.replace(/'[^']*'|"[^"]*"|`[^`]*`/g, "'<id>'"); // quoted identifiers |
| 47 | s = s.replace(/\b0x[0-9a-f]+\b/g, '<hex>'); |
| 48 | s = s.replace(/\b\d+\b/g, '<n>'); |
| 49 | s = s.replace(/\s+/g, ' ').trim(); |
| 50 | s = s.slice(0, 100); |
| 51 | return `${tool}|${s}`; |
| 52 | } |
| 53 | |
| 54 | /** A short, stable key for a task (so we count distinct tasks). */ |
| 55 | export function taskKey(prompt: string): string { |
no outgoing calls