| 1583 | const SLOW_OPERATION_TTL_MS = 10000 |
| 1584 | |
| 1585 | export function addSlowOperation(operation: string, durationMs: number): void { |
| 1586 | if ((process.env.NCODE_BUILD_MODE !== 'noumena' && process.env.USER_TYPE !== 'ant')) return |
| 1587 | // Skip tracking for editor sessions (user editing a prompt file in $EDITOR) |
| 1588 | // These are intentionally slow since the user is drafting text |
| 1589 | if (operation.includes('exec') && operation.includes('claude-prompt-')) { |
| 1590 | return |
| 1591 | } |
| 1592 | const now = Date.now() |
| 1593 | // Remove stale operations |
| 1594 | STATE.slowOperations = STATE.slowOperations.filter( |
| 1595 | op => now - op.timestamp < SLOW_OPERATION_TTL_MS, |
| 1596 | ) |
| 1597 | // Add new operation |
| 1598 | STATE.slowOperations.push({ operation, durationMs, timestamp: now }) |
| 1599 | // Keep only the most recent operations |
| 1600 | if (STATE.slowOperations.length > MAX_SLOW_OPERATIONS) { |
| 1601 | STATE.slowOperations = STATE.slowOperations.slice(-MAX_SLOW_OPERATIONS) |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | const EMPTY_SLOW_OPERATIONS: ReadonlyArray<{ |
| 1606 | operation: string |