| 1567 | const SLOW_OPERATION_TTL_MS = 10000 |
| 1568 | |
| 1569 | export function addSlowOperation(operation: string, durationMs: number): void { |
| 1570 | if (process.env.USER_TYPE !== 'ant') return |
| 1571 | // Skip tracking for editor sessions (user editing a prompt file in $EDITOR) |
| 1572 | // These are intentionally slow since the user is drafting text |
| 1573 | if (operation.includes('exec') && operation.includes('claude-prompt-')) { |
| 1574 | return |
| 1575 | } |
| 1576 | const now = Date.now() |
| 1577 | // Remove stale operations |
| 1578 | STATE.slowOperations = STATE.slowOperations.filter( |
| 1579 | op => now - op.timestamp < SLOW_OPERATION_TTL_MS, |
| 1580 | ) |
| 1581 | // Add new operation |
| 1582 | STATE.slowOperations.push({ operation, durationMs, timestamp: now }) |
| 1583 | // Keep only the most recent operations |
| 1584 | if (STATE.slowOperations.length > MAX_SLOW_OPERATIONS) { |
| 1585 | STATE.slowOperations = STATE.slowOperations.slice(-MAX_SLOW_OPERATIONS) |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | const EMPTY_SLOW_OPERATIONS: ReadonlyArray<{ |
| 1590 | operation: string |